CodeForces 371D. Vessels
暴力+胡乱优化就过了。。tags给的东西似乎什么都没用到。。。。。CF的数据是不是有点水啊。。。。。果然是没有营养的题目。。。。。
2 seconds
256 megabytes
standard input
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:
- Add xi liters of water to the pi-th vessel;
- 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.
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 ≤ pi ≤ n, 1 ≤ xi ≤ 109, 1 ≤ ki ≤ n).
For each query, print on a single line the number of liters of water in the corresponding vessel.
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2
4
5
8
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3
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的更多相关文章
- Codeforces 371D Vessels (模拟)
题目链接 Vessels 这道题我做得有点稀里糊涂啊==TLE了几发之后改了一行就A了. 具体思路就是记fi为若第i个容器已经盛不下水了,那么接下来盛水的那个容器. hi为若现在要给i号容器加水,当前 ...
- CodeForces 371D Vessels(树状数组)
树状数组,一个想法是当往p注水时,认为是其容量变小了,更新时二分枚举,注意一些优化. #include<cstdio> #include<iostream> #include& ...
- Codeforces I. Vessels(跳转标记)
题目描述: Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- codeforces 371D
#include<stdio.h> #define N 210000 struct node { int x,next; __int64 count,vec; }pre[N]; int n ...
- Mango DS Traning #49 ---线段树3 解题手记
Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- datediff(),dateadd(),datepart().datename()时间处理函数
原文链接:http://www.cnblogs.com/whz111/articles/2445777.html --convert(时间)对应数字表示的时间格式 select CONVERT(var ...
- [JS] 如何清空file input框 [整理]
测试环境:OS --> winXPBrowsers --> IE6+, FF 3.0.11, FF 3.5, Opera 9.64, Opera 10 beta 2, Safari 4, ...
- struts.xml中的intercepter
1. http://weizhilizhiwei.iteye.com/blog/1005210 Struts2 的核心——拦截器[Interceptor] 2. http://blog.csdn.ne ...
- Xcode 的正确打开方式——Debugging(转)
转自CocoaChina http://www.cocoachina.com/ios/20150225/11190.html 程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不 ...
- MySQL 删除数据表
MySQL 删除数据表 MySQL中删除数据表是非常容易操作的, 但是你再进行删除表操作时要非常小心,因为执行删除命令后所有数据都会消失. 语法 以下为删除MySQL数据表的通用语法: DROP TA ...
- linux网络编程常用头文件
sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arpa/inet.h:提供IP地址转换函 ...
- 4位bcd数转换为2进制数
DATA SEGMENTBUF DW 1234HBUF1 DW ? ;2进制数放到buf1内存单元DATA ENDSCODE SEGMENTASSUME CS:CODE ...
- System.InvalidOperationException: 无法加载协定为“ServiceReference1.XXXXXXXXXXXXXXXX”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分。
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="testWeb ...
- javascript 字符串滚动显示
<html> <head> <script type="text/javascript"> var chars = "JavaScri ...
- Ecshop 数据库操作方法getRow、getAll、getOne区别
ECShop没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现.这样做的好处是实现非常轻量,大大减小了分发包的文件大小.另外,当网站需要做memcached缓存时,也可以 ...