动态规划,而已! 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/ ...
随机推荐
- Android开发Thread+Handler演示样本(打地鼠)
直接在代码 package com.mingrisoft; import java.util.Random; import android.app.Activity; import android.o ...
- hdu1430魔板
Problem Description 在魔方风靡全球之后不久,Rubik先生发明了它的简化版——魔板.魔板由8个同样大小的方块组成,每个方块颜色均不相同,可用数字1-8分别表示.任一时刻魔板的状态可 ...
- Hadoop-2.2.0中国文献——MapReduce 下一代 —配置单节点集群
Mapreduce 包 你需从公布页面获得MapReduce tar包.若不能.你要将源代码打成tar包. $ mvn clean install -DskipTests $ cd hadoop-ma ...
- ACE 主动对象模式的按部就班的实现方法
ACE的主动对象模式的实现 对分布式系统设计来说,ACE提供的主动对象模式是让我们在系统框架构建的时候,回归到传统的单线程编程思维.你可能要问,既然有主动对象,那必然有被动对象,没有错,确实有被动对象 ...
- 记一个Oracle存储过程错误
下面一个存储过程是创建一个job,在5秒后更新一个表: create or replace PROCEDURE P_TEST AS jobno number; BEGIN dbms_job.submi ...
- 【原创】shadowebdict开发日记:基于linux的简明英汉字典(三)
全系列目录: [原创]shadowebdict开发日记:基于linux的简明英汉字典(一) [原创]shadowebdict开发日记:基于linux的简明英汉字典(二) [原创]shadowebdic ...
- Node.js 博客实例(五)编辑与删除功能
原教程 https://github.com/nswbmw/N-blog/wiki/_pages的第五章,因为版本号等的原因,在原教程基础上稍加修改就可以实现. 如今给博客加入编辑文章与删除文章的功能 ...
- jvisualvm远程监控Tomcat
网上已经有很多这方面的资料,但有些很杂乱,这里做了整理总结. 一.Java VisualVM 概述 对于使用命令行远程监控jvm 太麻烦 . 在jdk1.6 中 Oracle 提供了一个新的可视化的. ...
- Visual Prolog 的 Web 专家系统 (7)
GENI核心 -- 推理引擎(1)知识表示 GOAL最后一句是谓语infer(),它的含义是"论证". 因此,,进GENI核心,执行视图推理引擎. infer() infer(): ...
- 【Nginx】开发一个简单的HTTP模块
首先来分析一下HTTP模块是怎样介入Nginx的. 当master进程fork出若干个workr子进程后,每一个worker子进程都会在自己的for死循环中不断调用事件模块: for ( ;; ) { ...