博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces --- Round #248 (Div. 2) B. Kuriyama Mirai's Stones
阅读量:6282 次
发布时间:2019-06-22

本文共 2114 字,大约阅读时间需要 7 分钟。

B. Kuriyama Mirai's Stones

 

Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

  1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .
  2. Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her .

For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Sample test(s)
Input
6 6 4 2 7 2 7 3 2 3 6 1 3 4 1 1 6
Output
24 9 28
Input
4 5 5 2 3 10 1 2 4 2 1 4 1 1 1 2 1 4 2 1 2 1 1 1 1 3 3 1 1 3 1 4 4 1 2 2
Output
10 15 5 15 5 5 2 12 3 5
Note

Please note that the answers to the questions may overflow 32-bit integer type.

 

【题目大意】

有一些石头排成一行,每个石头都有自己的权值,现在有两种询问:

一种是1开头的:询问原来的石头顺序下,第i到第j颗石头的的权值只和;

一种是2开头的,询问所有石头按照大小顺序排列以后,第i到第j颗石头的权值之和;

这题乍看很像树状数组,但是并不是树状数组,直接模拟即可.

 

#include
#include
#include
#define MAX 100100using namespace std;__int64 m,a,b,c;__int64 n,i,sum;__int64 num1[MAX];__int64 num2[MAX];__int64 sum1[MAX];__int64 sum2[MAX];int main(){ sum=0; scanf("%I64d",&n); for(i=0;i

 

 

转载于:https://www.cnblogs.com/crazyacking/p/3749778.html

你可能感兴趣的文章
基于RBAC权限管理
查看>>
基于Internet的软件工程策略
查看>>
数学公式的英语读法
查看>>
留德十年
查看>>
迷人的卡耐基说话术
查看>>
PHP导出table为xls出现乱码解决方法
查看>>
PHP问题 —— 丢失SESSION
查看>>
Java中Object类的equals()和hashCode()方法深入解析
查看>>
数据库
查看>>
Vue------第二天(计算属性、侦听器、绑定Class、绑定Style)
查看>>
dojo.mixin(混合进)、dojo.extend、dojo.declare
查看>>
Python 数据类型
查看>>
iOS--环信集成并修改头像和昵称(需要自己的服务器)
查看>>
PHP版微信权限验证配置,音频文件下载,FFmpeg转码,上传OSS和删除转存服务器本地文件...
查看>>
教程前言 - 回归宣言
查看>>
PHP 7.1是否支持操作符重载?
查看>>
Vue.js 中v-for和v-if一起使用,来判断select中的option为选中项
查看>>
Java中AES加密解密以及签名校验
查看>>
定义内部类 继承 AsyncTask 来实现异步网络请求
查看>>
VC中怎么读取.txt文件
查看>>