题目链接 Vessels

这道题我做得有点稀里糊涂啊==TLE了几发之后改了一行就A了。

具体思路就是记fi为若第i个容器已经盛不下水了,那么接下来盛水的那个容器。

hi为若现在要给i号容器加水,当前真正被加水的那个容器。

这样就大大降低了时间复杂度。

 #include <bits/stdc++.h>

 using namespace std;
#define rep(i,a,b) for(int i(a); i <= (b); ++i) const int N = ;
long long a[N], b[N], f[N], h[N], c[N], d[N], op, x, cap, p;
int n, q, k; int main(){ scanf("%d", &n);
rep(i, , n) scanf("%lld", a + i);
a[n + ] = 1e18; f[n + ] = n + ; h[n + ] = n + ;
rep(i, , n) b[i] = , f[i] = i + , h[i] = i, c[i] = ;
scanf("%d", &q);
while (q--){
scanf("%lld", &op);
if (op == ){
scanf("%d%lld", &k, &p);
while (p > ){
x = h[k]; int l = x, cnt = ;
while (c[x]){
d[++cnt] = x;
x = f[x];
} rep(i, , cnt){
h[d[i]] = x;
f[d[i]] = x;
} cap = a[x] - b[x];
if (cap < p){
b[x] = a[x];
c[x] = ;
p -= cap;
}
else b[x] += p, p = ;
k = x;
}
}
else{
scanf("%lld", &op);
printf("%lld\n", b[op]);
}
} return ; }

Codeforces 371D Vessels (模拟)的更多相关文章

  1. CodeForces 371D. Vessels

    暴力+胡乱优化就过了..tags给的东西似乎什么都没用到.....CF的数据是不是有点水啊.....果然是没有营养的题目..... D. Vessels time limit per test 2 s ...

  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 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  6. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  7. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  9. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

随机推荐

  1. 【转】Python操作MongoDB

    Python 操作 MongoDB   请给作者点赞--> 原文链接 这篇文章主要介绍了使用Python脚本操作MongoDB的教程,MongoDB作为非关系型数据库得到了很大的宣传力度,而市面 ...

  2. P3805 【模版】manacher算法(manacher)

    P3805 [模版]manacher算法 题目描述 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 字符串长度为n 输入输出格式 输入格式: 一行小写英文字符a ...

  3. 求 1 到 n 的所有数的约数和

    求 1 到 n 的所有数的约数和 暴力方法就是枚举每个数,算出他的约数和即可,这样有点慢. 另一种思路,枚举约数,判断他是谁的约数,并记录(即他的倍数有多少个),在乘以他自己. n/i求的是n以内,i ...

  4. fetch 使用记录

    fetch api出来很多年了 ,由于兼容性问题之前一直没在项目中用到,最近做的项目只需兼容IE9+,把fetch引入了进来.目前用起来感觉挺好的,简洁. fetch 返回值是promise对象,对于 ...

  5. Apache shiro学习总结

    Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...

  6. JS一个非常经典的问题:在遍历数组时对DOM监听事件,索引值将始终等于遍历结束后的值

    一个简单的Tab选项卡点击事件. <style type="text/css"> ul{padding:0;margin:0;} .tab{width:400px;} ...

  7. csu-2018年11月月赛Round2-div1题解

    csu-2018年11月月赛Round2-div1题解 A(2191):Wells的积木游戏 Description Wells有一堆N个积木,标号1~N,每个标号只出现一次 由于Wells是手残党, ...

  8. python 类中__init__,__new__,__class__的使用详解

    1.python中所有类默认继承object类,而object类提供了很多原始的内置属性和方法,所有用户定义的类在python 中也会继承这些内置属性.我们可以通过dir()进行查看.虽然python ...

  9. PAT——乙级1026and1046

    1026 程序运行时间 (15 point(s)) 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() ...

  10. Struts2拦截器原理

    拦截器是struts2处理的核心,本文主要说struts2的拦截器的基本原理/实现,其它框架处理的东西就不说了,得自己再看了.struts2版本:2.2.3当一个请求来了后,从org.apache.s ...