codeforces 371D
#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的更多相关文章
- CodeForces 371D Vessels(树状数组)
树状数组,一个想法是当往p注水时,认为是其容量变小了,更新时二分枚举,注意一些优化. #include<cstdio> #include<iostream> #include& ...
- CodeForces 371D. Vessels
暴力+胡乱优化就过了..tags给的东西似乎什么都没用到.....CF的数据是不是有点水啊.....果然是没有营养的题目..... D. Vessels time limit per test 2 s ...
- Codeforces 371D Vessels (模拟)
题目链接 Vessels 这道题我做得有点稀里糊涂啊==TLE了几发之后改了一行就A了. 具体思路就是记fi为若第i个容器已经盛不下水了,那么接下来盛水的那个容器. hi为若现在要给i号容器加水,当前 ...
- Codeforces I. Vessels(跳转标记)
题目描述: Vessels time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Mango DS Traning #49 ---线段树3 解题手记
Training address: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=38994#overview B.Xenia and B ...
- 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 ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
随机推荐
- bzoj题目大体分类
http://m.blog.csdn.net/article/details?id=51387623
- Java 添加、回复、修改(替换)、删除Word批注
批注是一种常用于对特定文档内容进行注解的工具或方法,起到解释说明.标记指正的作用.在本篇文章中,将介绍如何操作Word批注的方法,包括: 1. 添加批注:添加文本到批注.插入图片到批注: 2. 回复批 ...
- Linux上安装禅道
linux一键安装包内置了apache, php, mysql这些应用程序,只需要下载解压缩即可运行禅道. 从7.3版本开始,linux一键安装包分为32位和64位两个包,请大家根据操作系统的情况下载 ...
- 题解报告:poj 1426 Find The Multiple(bfs、dfs)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- Integer / BigInteger / BigDecimal 方法
import java.math.BigDecimal; import java.math.*; public class Main{ public static void main(String[] ...
- Hive扩展功能(九)--Hive的行级更新操作(Update)
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这三部机, 每部主机的用户名都为centos ...
- 在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法
在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法 [MXDRAW CAD控件文档] 下面帮助的完整例子,在控件安装目录的Sample\Ie\iedemo.htm中. 1. 主要用到 ...
- SpringBoot开源项目学习总结
一.实现日期格式数据类型的转换 首先,定义DateConverter实现Converter<String, Date>接口: package com.stevlu.common; impo ...
- Spring框架系列(七)--Spring常用注解
Spring部分: 1.声明bean的注解: @Component:组件,没有明确的角色 @Service:在业务逻辑层使用(service层) @Repository:在数据访问层使用(dao层) ...
- RabbitMQ系列(五)--高级特性
在上一篇文章讲解MQ消息可靠性投递和幂等性中有提到confirm机制的重要性,现在更相信的说明一下 一.Confirm机制 Confirm就是消息确认,当Producer发送消息,如果Broker收到 ...