433B.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:
- She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her
. - 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.
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.
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.
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
24
9
28
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
10
15
5
15
5
5
2
12
3
5
Please note that the answers to the questions may overflow 32-bit integer type.
刚开始没有注意下面的Note,用int类型的数组WA了。后来改用long long型。我之前也没去算过OJ可以接受多大的数组,就这道AC的代码来看4W的long long是没有问题的。
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include<unordered_set>
#define ll long long
using namespace std;
int dir[][] = { {,},{-,},{,},{,-} }; int main()
{
int n;
cin >> n;
vector<ll> v(n),a(n);
for (int i = ; i < n; i++)
{
int t;
cin >> t;
v[i] = t;
a[i] = t;
}
sort(a.begin(), a.end());
for (int i = ; i < n; i++)
{
v[i] += v[i - ];
a[i] += a[i - ];
} int m;
cin >> m;
while (m--)
{
int q, l, r;
cin >> q >> l >> r;
if (q == )
{
if (l == )
cout << v[r - ] << endl;
else
cout << v[r - ] - v[l - ] << endl;
}
else
{
if (l == )
cout << a[r - ] << endl;
else
cout << a[r - ] - a[l - ] << endl;
}
}
//system("pause");
return ;
}
433B.Kuriyama Mirai's Stones的更多相关文章
- 动态规划,而已! CodeForces 433B - Kuriyama Mirai's Stones
Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from ...
- Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's Stones
题目简单描述就是求数组中[l,r]区间的和 #include <iostream> #include <vector> #include <string> #inc ...
- CF433B Kuriyama Mirai's Stones 题解
Content 有一个长度为 \(n\) 的数组 \(a_1,a_2,a_3,...,a_n\).有 \(m\) 次询问,询问有以下两种: \(1~l~r\),求 \(\sum\limits_{i=l ...
- codeforces433B
Kuriyama Mirai's Stones CodeForces - 433B 有n颗宝石,每个宝石都有自己的价值. 然后m次询问.问区间[i,j]的宝石的总值,或者问排序后的区间[i,j]的总值 ...
- Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)
比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...
- Anna-senpai帖子翻译与Mirai源代码使用
Anna-senpai这个人太好玩了,整件事就像没有黄段子的无聊世界那样. 无聊翻译了一下,顺便实验了效果. --------------------------------------------- ...
- HDU 5973 Game of Taking Stones 威佐夫博弈+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5973 Game of Taking Stones Time Limit: 2000/1000 MS ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- codechef Jewels and Stones 题解
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery acces ...
随机推荐
- [CQOI2015] 网络吞吐量 - 最大流,最短路
在第i个点只能选A[i]次的情况下,能选出多少条1-n的最短路 Solution 我们造出最短路DAG,然后对每个点拆点限流,跑最大流即可 双向边警告!(有悖直觉 #include <bits/ ...
- hive删除表时直接卡死
原因:因为以前安装的mysql,字符集都改为了utf-8. 解决方案:需要把字符集都改为latin1 首先进入mysql查看字符集 show variables like 'char%' 找到mysq ...
- DataGridView 调整列顺序为设计的顺序
设置: dataGridView1.AutoGenerateColumns = false;
- 题解 AT859 【元素の系統名】
题目传送门. 介绍一种使用string字符串的方法. \(string\)是\(C++\).\(java\).\(VB\)等编程语言中的字符串,字符串是一个特殊的对象,属于引用类型. \(C++\)标 ...
- Python警告:InsecureRequestWarning、InsecurePlatformWarning、SNIMissingWarning
SSL警告 urllib3将基于证书验证支持的级别发出几种不同的警告.这些警告表示特定情况,可以通过不同方式解决. InsecureRequestWarning 当在未启用证书验证的情况下对HTTPS ...
- Mac 上完美解决SVN问题及svn软件
注:本文是转自https://blog.csdn.net/qq_40144558/article/details/80630466 svn对Mac的支持不算美好,几乎所有软件都很繁琐,我们作为开发其实 ...
- mybatis(二):缘由
本是Apache的一个开源项目iBatis 2010年,iBatis由Apache Software Foundation(软件基金会)迁移到了Google Code(代码托管平台),并改名为MyBa ...
- 通过css修改input的边框
input{ border:1px solid #d2d2d2; background-color:transparent; } 可以看到主要是把背景色调成透明的颜色,从而来进行边框的设置
- [CF1220C] Substring Game in the Lesson - 博弈论
[CF1220C] Description 给定一个字符串 \(S\) , 同时维护一个区间 \([l,r]\) .轮流操作,每次可以扩展到一个新区间使得原区间是新区间的真子区间,并且字典序更小,不能 ...
- Hackintosh Issues 10.13.x
Issuses 1: 出现禁行: (-v:) allcating 0x800 pages at 0x2000000 alloc type 2 Load kernal from stream Load ...