#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. 擅长排列的小明II

    先搜索 出来一点结果之后  看结果之间的 联系 得出  递推公式  . #include<stdio.h> #include<string.h> #include<mat ...

  2. 洛谷P3366 【模板】最小生成树(Kruskal)

    题目描述 如题,给出一个无向图,求出最小生成树,如果该图不连通,则输出orz 输入输出格式 输入格式: 第一行包含两个整数N.M,表示该图共有N个结点和M条无向边.(N<=5000,M<= ...

  3. O - Combinations (组合数学)

    Description Computing the exact number of ways that N things can be taken M at a time can be a great ...

  4. ListView(4)取消GridView/ListView item被点击时的效果

    方法一,在代码中设置 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelector(new Colo ...

  5. Html 标签的事件绑定(转自 MSDN)

    参考 MSDN 网页给 HTML 标签绑定 click 事件: function makeFoldersCollapsible(folderIcon, openFolderIcon, pathToIc ...

  6. python之路 之一pyspark

    pip包下载安装pyspark pip install pyspark  这里可能会遇到安装超时的情况   加参数  --timeout=100 pip   -default   -timeout=1 ...

  7. 改变默认选择前1000行,编辑前200行【MSSQL】

  8. 6.12---select

  9. php简易计算器

    php循环结构 案例:php简易计算器 步骤: 1.先绘制这个表格 2.根据表单提交的sub属性判断一下,是否点击计算了 (GET方式提交的数据,通过地址栏传递的) 3.计算,并将结果输入到第二行 问 ...

  10. Spark学习之RDD编程(2)

    Spark学习之RDD编程(2) 1. Spark中的RDD是一个不可变的分布式对象集合. 2. 在Spark中数据的操作不外乎创建RDD.转化已有的RDD以及调用RDD操作进行求值. 3. 创建RD ...