codeforces 371D
#include<stdio.h>
#define N 210000
struct node {
int x,next;
__int64 count,vec;
}pre[N];
int n,flag;
int find(int x) {
if(x==n+1)
return n+1;
if(pre[x].count>pre[x].vec) {
int h=pre[x].next;
pre[h].count=pre[h].count+pre[x].count-pre[x].vec;
pre[x].count=pre[x].vec;
pre[x].x=pre[x].next=find(pre[x].next);
}
return pre[x].x;
}
int main() {
__int64 m;
int i,j,k;
while(scanf("%d",&n)!=EOF) {
for(i=1;i<=n;i++) {
pre[i].next=i+1;
pre[i].count=0;
pre[i].x=i;
}
pre[n].x=n;
pre[n].count=0;
for(i=1;i<=n;i++) {
scanf("%I64d",&m);
pre[i].vec=m;
}
scanf("%d",&m);
flag=0;
while(m--) {
scanf("%d",&k);
if(k==1) {
scanf("%d%d",&i,&j);
if(find(i)!=n+1) {
pre[i].count+=j;
find(i);
}
}
else {
scanf("%d",&i);
printf("%I64d\n",pre[i].count);
}
}
}
return 0;
}
codeforces 371D的更多相关文章
- CodeForces 371D Vessels(树状数组)
树状数组,一个想法是当往p注水时,认为是其容量变小了,更新时二分枚举,注意一些优化. #include<cstdio> #include<iostream> #include& ...
- CodeForces 371D. Vessels
暴力+胡乱优化就过了..tags给的东西似乎什么都没用到.....CF的数据是不是有点水啊.....果然是没有营养的题目..... D. Vessels time limit per test 2 s ...
- Codeforces 371D Vessels (模拟)
题目链接 Vessels 这道题我做得有点稀里糊涂啊==TLE了几发之后改了一行就A了. 具体思路就是记fi为若第i个容器已经盛不下水了,那么接下来盛水的那个容器. hi为若现在要给i号容器加水,当前 ...
- Codeforces I. Vessels(跳转标记)
题目描述: Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Mango DS Traning #49 ---线段树3 解题手记
Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
随机推荐
- [SDOI2011]消防(单调队列,树的直径,双指针)
消防 2011年 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 某个国家有n个城市,这n个城市中任意两个都连通且有 ...
- [App Store Connect帮助]六、测试 Beta 版本(3.1)管理测试员:添加内部测试员
您可以添加至多 25 个内部测试员(您的 App Store Connect 用户)使用“TestFlight Beta 版测试”来测试您的 App.在您上传了至少一个构建版本之后,才可添加测试员. ...
- GoAhead4.1.0 开发总结一(移植)
环境 官方文档:https://www.embedthis.com/goahead/doc/ 源码下载: goahead-4.1.0-src.tgz 系统平台:Ubuntu 12.04.4 gcc v ...
- mysqlbinlog(日志管理工具)
mysqlbinlog用于处理二进制的日志文件,如果想要查看这些日志文件的文本内容,就需要使用mysqlbinlog工具. 1.mysqlbinlog命令的语法 shell > mysqlbin ...
- [译]Cookies Without Chocolate Chips
Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...
- Cesium加载影像
注意:使用自定义数据源时,Cesium.Viewer类参数必须设置为 baseLayerPicker:false A. 使用天地图数据源 //天地图var provider=new Cesium.We ...
- 上传txt文件编码格式判断(文本乱码解决方法)
说明 通过ajax或者浏览上传文本文件,上传时候c#处理时候因为文本格式的创建不同,在获取内容时候会出现中文乱码. 解决方法 通过上传的文件流,判断文件的编码格式,在使用对应的编码格式获取文本内容 # ...
- Objective-C设计模式——外观Faced(接口适配)
外观模式 外观设计模式和适配器差不多,不过它门对对象控制的粒度不同,适配器一般只是控制一个系统和客户端的对接.外观则是用来抽象多个系统一起工作. 外观一般具有多个子系统,所以外观应持有多个子系统的引用 ...
- can't set blob value on that column
MySQL_Prepared_Statement::setBlob: can't set blob value on that column, MySQL error code:0, SQLState ...
- WEB-CSS实现单行(多行)文本溢出显示省略号
//单行文本溢出部分隐藏显示省略号...overflow: hidden; text-overflow:ellipsis; white-space: nowrap; /** n 行文本溢出部分隐藏显示 ...