暴力+胡乱优化就过了。。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;
}

CodeForces 371D. Vessels的更多相关文章

  1. Codeforces 371D Vessels (模拟)

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

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

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

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

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

  4. codeforces 371D

    #include<stdio.h> #define N 210000 struct node { int x,next; __int64 count,vec; }pre[N]; int n ...

  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. Codeforces Round #218 (Div. 2) D. Vessels

    D. Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

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

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

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

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

  9. 【Codeforces 738C】Road to Cinema

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

随机推荐

  1. Java POI 两种导出方式

    这里面包含了模板导出方法和自定义模板进行导出 package jp.co.syspro.poo.action.hibikoyou; import java.io.ByteArrayOutputStre ...

  2. 织梦dede自定义内容分页,datalist运用实例

    在/plus文件夹中新建一个ceshi.php文件..<?php require(dirname(__FILE__)."/../include/common.inc.php" ...

  3. type和create type

    type和create type 异同点:      create type 可在库中生成一个长期有效的自定义类型对象,而type作用域仅限于语句块中:      两者都可以自定义数据类型: 各种ty ...

  4. 64位Window操作系统下,Orcal数据访问服务器端和客户端版本对应与通讯问题

    最近做一个小系统,需要在客户现场搭建数据库环境.之前我们一直访问的是公司的一个测试库,现在需要在现场开发,现场的Orcal服务器是12C ,我们本不打算重装服务器端orcal,故将我们自己电脑的orc ...

  5. javascript判断浏览器是否是隐私模式

    判断浏览器是否是隐私模式,隐私模式下有写api不可用 1. try { localStorage['test'] = 'test'; //localStorage和sessionStorage都存在, ...

  6. EBS与FMW集成工作流管理器的检查

    工作流管理器的检查点(DB层面): --1:数据库job aq参数设置,建议设置job_queue_processes>=10 select p.NAME,p.DESCRIPTION,p.VAL ...

  7. 安装SVN及实现nginx web同步更新需要在WDCP一键安装包的基础上

    一.安装 1.查看是否安装cvs rpm -qa | grep subversion 2.安装 yum install subversion 3.测试是否安装成功 /usr/bin/svnserve ...

  8. ASP.NET MVC 缓存使用示例

    应该说,缓存的设计是一门较为复杂的学问,主要考虑的问题包括:要不要缓存?要缓存哪些数据?要缓存多少数据?要缓存多久?如何更新缓存(手动还是自 动)?将缓存放在哪里?本文将以较为通俗易懂的方式,来看一看 ...

  9. 写了一个jquery的 弹出层插件。

    下载地址:http://pan.baidu.com/s/1eQ26CMm ps:ajax加载做的,要有环境才能正常运行哦! //这是一个以ajax加载显示弹出层插件  参数(option): widt ...

  10. Websocket 与代理服务器如何交互? How HTML5 Web Sockets Interact With Proxy Servers

    How HTML5 Web Sockets Interact With Proxy Servers Posted by Peter Lubberson Mar 16, 2010 With the re ...