#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的更多相关文章

  1. CodeForces 371D Vessels(树状数组)

    树状数组,一个想法是当往p注水时,认为是其容量变小了,更新时二分枚举,注意一些优化. #include<cstdio> #include<iostream> #include& ...

  2. CodeForces 371D. Vessels

    暴力+胡乱优化就过了..tags给的东西似乎什么都没用到.....CF的数据是不是有点水啊.....果然是没有营养的题目..... D. Vessels time limit per test 2 s ...

  3. Codeforces 371D Vessels (模拟)

    题目链接 Vessels 这道题我做得有点稀里糊涂啊==TLE了几发之后改了一行就A了. 具体思路就是记fi为若第i个容器已经盛不下水了,那么接下来盛水的那个容器. hi为若现在要给i号容器加水,当前 ...

  4. Codeforces I. Vessels(跳转标记)

    题目描述: Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Mango DS Traning #49 ---线段树3 解题手记

    Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. 在CentOS下安装VMware tool

    VMware tools是虚拟机VMware Workstation自带的一款工具.它的作用就是使用户可以从物理主机直接往虚拟机里面拖文件.如果不安装它,我们是无法进行虚拟机和物理机之间的文件传输的. ...

  2. 基于itchat实现微信群消息同步机器人

    原始网址:http://www.jianshu.com/p/7aeadca0c9bd# 最近 全栈数据工程师养成攻略 的微信群已经将近500人,开了二群之后为了打通不同微信群之间的消息,花了点时间做了 ...

  3. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation

    You are given a list of train stations, say from the station 11 to the station 100100. The passenger ...

  4. elasticsearch 查询优化

    首先对不必要的字段不做分词也就是不做索引,禁止内存交换 1.shard 一个Shard就是一个Lucene实例,是一个完整的搜索引擎. 分片数过多会导致检索时打开比较多的文件,多台服务器之间通讯成本加 ...

  5. gdb如何保存和读取断点

    刚开始在linux下学编程使用gdb的同学可能会发现,每次用gdb设置断点调试程序,但下次打开的时候所有断点都没有了,很不方便.下面介绍保存和读取断点的方法. 1. 保存断点 先用info b 查看一 ...

  6. 转载--Beautifuisoup的使用

    转载自--http://mp.weixin.qq.com/s?src=11&timestamp=1520511185&ver=742&signature=KDzYoOg8Xd9 ...

  7. Android基础TOP4_2:弹窗式选择列表

    Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  8. HTTP、HTTP1.0、HTTP1.1、HTTP2.0——笔记

    笔记来源地址:https://mp.weixin.qq.com/s/T2IErLDxbWP1a-VbRkZZHg HTTP: HTTP是WWW数据通信的基础,是应用层协议. HTTP是干什么的?用来给 ...

  9. 字符集编码---3 Windows BOM

    Windows平台下存储Unicode格式的文件时,会在文件头插入2到3字节的文件头.这个文件头就是BOM(Byte Order Marks). 这个文件头在Unicode中,无对应符号.所以不必担心 ...

  10. Functions of the call stack

    https://en.wikipedia.org/wiki/Call_stack#STACK-FRAME As noted above, the primary purpose of a call s ...