动态规划,而已! CodeForces 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.
!
!!
!!!
!
!
!
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 100006
__int64 sum;
__int64 pp[maxn]={0},p[maxn]={0},liu[maxn],xp[maxn];
int main()
{
int i,j,k;
int t,n,m;
int l,r;
while(scanf("%d",&n)!=EOF)
{
p[0]=0;
for(i=1;i<=n;i++)
{
scanf("%I64d",&liu[i]);
xp[i]=liu[i];
p[i]=p[i-1]+liu[i];
}
xp[0]=0;
sort(xp,xp+n+1);
for(i=1;i<=n;i++)
pp[i]=pp[i-1]+xp[i];
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
if(m==1)
{
scanf("%d%d",&l,&r);
sum=p[r]-p[l-1];
printf("%I64d\n",sum);
}
else if(m==2)
{
scanf("%d%d",&l,&r);
sum=pp[r]-pp[l-1];
printf("%I64d\n",sum);
}
}
}
return 0;
}
看出bug就讲吧,谢谢;
版权声明:本文博客原创文章,博客,未经同意,不得转载。
动态规划,而已! CodeForces 433B - Kuriyama Mirai's Stones的更多相关文章
- 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 ...
- 【动态规划】Codeforces 711C Coloring Trees
题目链接: http://codeforces.com/problemset/problem/711/C 题目大意: 给N棵树,M种颜色,已经有颜色的不能涂色,没颜色为0,可以涂色,每棵树I涂成颜色J ...
- 【动态规划】Codeforces 698A & 699C Vacations
题目链接: http://codeforces.com/problemset/problem/698/A http://codeforces.com/problemset/problem/699/C ...
- 【动态规划】Codeforces 706C Hard problem
题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci( ...
- 动态规划:Codeforces Round #427 (Div. 2) C Star sky
C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...
- Codeforces 433 C. Ryouko's Memory Note
C. Ryouko's Memory Note time limit per test 1 second memory limit per test 256 megabytes input stand ...
- codeforces 560 C Gerald's Hexagon
神精度--------这都能过.随便算就好了,根本不用操心 就是把六边形补全成三角形.然后去掉补的三个三角形,然后面积除以边长1的三角形的面积就可以.... #include<map> # ...
- 【动态规划】Codeforces Round #406 (Div. 2) C.Berzerk
有向图博弈问题. 能转移到一个必败态的就是必胜态. 能转移到的全是必胜态的就是必败态. 转移的时候可以用队列维护. 可以看这个 http://www.cnblogs.com/quintessence/ ...
随机推荐
- 设计模式之迭代器模式(Iterator)摘录
23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程,它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...
- python学习笔记之三:字典,当索引不好用时
字典是python中唯一内建的映射类型.字典中的值并没有特殊的顺序,但是都存储在一个特定的键(key)里.键可以是数字,字符串甚至是元组. 1. 创建和使用字典 字典可以通过下面的方式创建: phon ...
- C#属性总结
1.私有字段和公有字段的比较 类中的私有字段只能在类的内部访问,而对类的公有字段的访问却不受限制. 在以前,为了封装,程序中会尽量少使用公有字段,因为使用公有字段的话,会让程序失去控制权.所以程序中会 ...
- poj 2369 Permutations 更换水称号
寻找循环节求lcm够了,如果答案是12345应该输出1.这是下一个洞. #include<iostream> #include<cstdio> #include<cstr ...
- 每天一点儿JAVA-向量的操作
package java_prac2; import java.util.*; /** * <p>Title: 矢量操作</p> * <p>Description: ...
- DateTime.Compare(t1,t2)比較两个日期大小
DateTime.Compare(t1,t2)比較两个日期大小,排前面的小,排在后面的大,比方:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
- javascript于boolean类型转换,运营商&&和|| 返回值
javascript它是弱类型语言,不管是什么类型的数据可以被转换成boolean种类.转换规则如下面的: 数据类型 转换为boolean后的值 NAN ...
- Linux下关于解决JavaSwing中文乱码的情况(转)
前两天在linux中运行java 老是出乱码,很苦恼,后来网上找了好多解决办法.有些可行,有些不可行,今天总结一下. redhed 貌似没出现乱码 本身就jdk就支持中文 红旗linux suse等 ...
- swift排序算法和数据结构
var arrayNumber: [Int] = [2, 4, 6, 7, 3, 8, 1] //冒泡排序 func maopao(var array: [Int]) -> [Int] { fo ...
- Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树动态规划)
原标题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意 ...