题目链接 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. jxl教程图文详解

    近来学习了下jxl的操作Excel报表功能,现有的API基本可以满足当前的需要,抽空做了一个学生成绩查询报表的例子. 先看效果图: 从图中可以看到这是一个交叉报表,横向到Q列,纵向有22行,全部是通过 ...

  2. 【word ladder】cpp

    题目: Given two words (beginWord and endWord), and a dictionary, find the length of shortest transform ...

  3. 精通CSS高级Web标准解决方案(4、对链接应用样式)

    4.1 简单的链接样式 锚可以作为内部引用,也可以作为外部链接,应该区分对待. 伪类选择器: :link 用来寻找没有访问过的链接 :visited 用来寻找已经访问过的链接 a:link{color ...

  4. 二分法 Binary Search

    二分法还是比较常见和简单的,之前也遇到过一些二分的相关题目,虽然不难,但是每次都需要在边界问题上诸多考虑,今天听了九章算法的课程,学习到一种方法使得边界问题简单化. 二分法的几个注意点: 1. mid ...

  5. springboot 热加载的问题 idea下的springboot热加载的

    最近在学spring框架,使用的是springboot可以省去很多的配置,可谓是初学者的福音啊. 尤其是在刚写代码的时候,都想马上看到自己写出来的效果,看看能不能输出hello world,所以要不断 ...

  6. vue的v-for循环普通数组、对象数组、对象、数字

    如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8& ...

  7. vue.js单文件组件中非父子组件的传值

    最近在研究vue.js,总体来说还算可以,但是在web开发群里有一些人问在单文件组件开发模式中非父子组件如何传值的问题,今天在这里讲讲,希望对大家有所帮助! 在官网api中的这段讲解很少,也很模糊:官 ...

  8. Java语法糖(二)

    语法糖之四:内部类 内部类:顾名思义,在类的内部在定义一个类.内部类仅仅是编译时的概念,编译成字节码后,内部类会生成单独的Class文件. 四种:成员内部类.局部内部类.匿名内部类.静态内部类. 1. ...

  9. HDOJ 1085 Holding Bin-Laden Captive!

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  10. UOJ Goodbye Bingshen

    在叶子童鞋的推荐下打了这场比赛... 感觉被虐爆了... 怎么这么多构造题... 我还没写过呢... 交互题是毛线...看了好久没看懂...就放弃了...(我语文好差QAQ...) 最后只会T1... ...