暴力+胡乱优化就过了。。tags给的东西似乎什么都没用到。。。。。CF的数据是不是有点水啊。。。。。果然是没有营养的题目。。。。。

D. Vessels
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th vessel is ai liters.

Initially, all the vessels are empty. In some vessels water is poured. All the water that overflows from the i-th vessel goes to the (i + 1)-th one. The liquid that overflows from the n-th vessel spills on the floor.

Your task is to simulate pouring water into the vessels. To do this, you will need to handle two types of queries:

  1. Add xi liters of water to the pi-th vessel;
  2. Print the number of liters of water in the ki-th vessel.

When you reply to the second request you can assume that all the water poured up to this point, has already overflown between the vessels.

Input

The first line contains integer n — the number of vessels (1 ≤ n ≤ 2·105). The second line contains n integers a1, a2, ..., an — the vessels' capacities (1 ≤ ai ≤ 109). The vessels' capacities do not necessarily increase from the top vessels to the bottom ones (see the second sample). The third line contains integer m — the number of queries (1 ≤ m ≤ 2·105). Each of the next m lines contains the description of one query. The query of the first type is represented as "1 pi xi", the query of the second type is represented as "2 ki" (1 ≤ pin, 1 ≤ xi ≤ 109, 1 ≤ kin).

Output

For each query, print on a single line the number of liters of water in the corresponding vessel.

Sample test(s)
input
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2

output
4
5
8

input
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3

output
7
10
5

#include <iostream>
#include <cstdio>
#include <cstring>using namespace std;int a[320000],v[320000],n,m,s,p,x,next[320000];int main()
{scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",a+i);next[i]=i+1;}next[n+1]=n+1;scanf("%d",&m);while(m--){scanf("%d",&s);if(s==1){scanf("%d%d",&p,&x);int i,j;for(i=p;i<=n;i=next[i]){if(v[i]==a[i]) continue;int temp=min(a[i]-v[i],x);v[i]+=temp;x-=temp;if(!x) break;}if(v[i]==a[i]) i++;int t;for(j=p;j<i;j=t){t=next[j];next[j]=i;}}else if(s==2){scanf("%d",&p);printf("%d\n",v[p]);}}return 0;
}

转载于:https://www.cnblogs.com/fuhaots2009/p/3469214.html

CodeForces 371D. Vessels相关推荐

  1. CodeForces - 371D. Vessels(并查集)

    题目链接:http://codeforces.com/problemset/problem/371/D点击打开链接 D. Vessels time limit per test 2 seconds m ...

  2. CodeForces - 371D Vessels 【并查集】

    Vessels 题意: 自上而下的n个碗,向某个碗中倒水,如果溢出,则会流向它之下的下一个未满的碗.有两种操作:1 p x表示往第p个碗中导入x的水,2 p表示询问此时第p个碗中的水量. 题解: 未经 ...

  3. Codeforces 371D. Vessels【并查集】

    题目大意: 给出一堆从上到下叠起来的容器,有两种操作:第一种是在编号为i的容器中加入x的水(保证水溢出之后会流到下一个最近的容器(如果存在)中):第二种是查询编号为i的容器中有多少水. 做法: 首先, ...

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

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

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

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

  6. Vessels CodeForces - 371D

    A - Vessels CodeForces - 371D 题意: 进行两种操作:1代表向x容器中倒入y升水 2代表  查询x容器中 的水为多少 将所有容器从下往上开始标号 1到  n,当要倒水的时候 ...

  7. 【CodeForces - 371D】Vessels(思维,元素合并,并查集)

    题干: There is a system of n vessels arranged one above the other as shown in the figure below. Assume ...

  8. CF 371D Vessels 【并查集】

    给出一个竖着的n个容器每个容器的容积,从上到下分别是1,2,3,4,,n,从某点开始浇水,保证该层满了后水能流向下一层,一层一层,直到不再溢出或者最底下都装满了留到地上去了为之. 给出n个操作/询问 ...

  9. Codeforces 题目合集+分类+代码 【Updating...】【361 in total】

    961A - Tetris                                                模拟                                      ...

最新文章

  1. 录取5秒钟的KNN取景效果gif(Opencv) Python实现
  2. babel 转换箭头函数
  3. 火力发电厂与变电站设计防火规范_2019年《建筑设计防火规范》新版征求意见稿...
  4. 使用 jquery 创建数组
  5. 1.封装WinMain至动态链接库
  6. HDU 1875 畅通工程再续
  7. 循环自相关函数和谱相关密度(五)——实信号、复信号模型下的QPSK信号循环谱MATLAB仿真结果及代码
  8. HTML+CSS+JS实现 ❤️酷炫情人节爱心动画特效❤️
  9. wps启用编辑按钮在哪里_WPS 新功能上线,官宣首发!人人都会用的图片设计
  10. html生成小窗口,用JS制作9种弹出小窗口(HTML)
  11. springboot redis token_Spring Boot + Redis 实现接口幂等性,看这篇就太好了!
  12. 网易云音乐歌曲歌词下载
  13. 分享个大厂PRD模板
  14. java计算机毕业设计基于安卓Android的团务智慧管理APP(源码+系统+mysql数据库+Lw文档)
  15. Xshell使用教程
  16. 图文详解PCB生产工艺流程
  17. 2018DeeCamp笔试题目第二套B卷
  18. C语言入门知识集合。
  19. 微博【黄金分析师吕超】--1.19黄金分析
  20. 人工智能在石油勘探开发中的应用及发展趋势(总结部分)

热门文章

  1. 【 Linux 】进程间通信之信号量
  2. seconds_behind_master计算方式
  3. 聊天宝团队解散,老罗的社交梦破碎
  4. CSS3 浏览器内核识别码
  5. 【PP-18】定义成本核算变式——数量结构控制参数
  6. Facebook打开,跳转个人首页、动态方式
  7. 学计算机的机械硕士好找工作吗,学机械的为啥转行特别多?网友:一言难尽,就业率高,质量不高...
  8. python 字符串转字典 编码_python基础--2(字符串、元组、列表、字典、集合、文件、编码转码)...
  9. 电视剧《爱情公寓》分集剧情介绍
  10. 风格化的 Toggle Buttons