暴力+胡乱优化就过了。。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. JAVA线程池ThreadPoolExecutor与阻塞队列BlockingQueue .
  2. 如何搭建html运行环境,搭建基于express框架运行环境的方法步骤
  3. AlertDialog.Builder选择对话框
  4. python django django-debug-toolbar 加载缓慢,不能使用。
  5. Ubuntu虚拟机磁盘扩容+VM虚拟机开机多出1分30秒的解决方案(终极教程)
  6. dptcpp 题目 2352: [信息学奥赛一本通-T1440]数的划分-dp
  7. 【干货分享】流程DEMO-补打卡
  8. 跨模块中的分配内存问题
  9. mysql 占用swap_查看swap占用情况
  10. 程序员的灯下黑:重知识轻技术(转)
  11. 用scanf输入long long 型的数
  12. mes系统服务器连接失败,mes系统如何连接其他系统设备?
  13. android developer tools下载地址
  14. 队列同步器(AbstractQueuedSynchronizer)源码简析
  15. 兜兜转转解决office和visio不能同时安装的问题
  16. 史上最全的CSP-J/S 第一轮知识点
  17. python xlwings excel 根据列排序
  18. 如何在cmd中运行PHP
  19. 第五项修炼--学习型组织的艺术与实践
  20. Android实现AppCompatActivity全屏半透明

热门文章

  1. python编程(kivy入门)
  2. WIN10一直提示自动修复,无法进入系统
  3. dancer cookbook 小议3
  4. 实现收藏本网站的功能
  5. Java实现的经典坦克大战小游戏
  6. 【跨层注意力:多层次融合】
  7. 好听的英文歌-阿黛尔两首
  8. 理论小知识:日期和时间类型
  9. 各版本Linux安装软件
  10. 对皮肤美白算法的一些研究