Codeforces 371D Vessels (模拟)
题目链接 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 (模拟)的更多相关文章
- CodeForces 371D. Vessels
暴力+胡乱优化就过了..tags给的东西似乎什么都没用到.....CF的数据是不是有点水啊.....果然是没有营养的题目..... D. Vessels time limit per test 2 s ...
- 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 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces 679B. Barnicle 模拟
B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...
- CodeForces 382C【模拟】
活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...
随机推荐
- 最短路径(最基础,经典的模板和思想):HDU-2544最短路
题目: 最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- POJ 3041 Asteroids (二分图最小点覆盖集)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24789 Accepted: 13439 Descr ...
- phpmyadmin漏洞利用general_log和general_log_file拿权限
我们如果知道phpmyadmin和网站的绝对路径后,可以利用into outfile写马拿到权限,但是吧有新版本的mysql和一些系统设置的问题这个函数受到了secure-file-priv这个的影响 ...
- selenium随笔
1.点击一个连接通常录制一个click命令,通常需要改变它到clickAndWait命令,确保案例暂停,新的页面完全被转载进来. 2.测试案例需要检查Web页的属性,需要assert和verify命令 ...
- 理解机器为什么可以学习(三)---Theory of Generalization
前边讨论了我们介绍了成长函数和break point,现在继续讨论m是否成长很慢,是否能够取代M. 成长函数就是二分类的排列组合的数量.break point是第一个不能shatter(覆盖所有情形) ...
- javascript计算两个时间的差
function GetDateDiff(startTime, endTime, diffType) { //将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式 startTime ...
- VS 2013插件
http://www.spersky.com/post/vsPlugins.html http://vswebessentials.com/download http://developer.51ct ...
- MySQL Innodb表导致死锁日志情况分析与归纳
发现当备份表格的sql语句与删除该表部分数据的sql语句同时运行时,mysql会检测出死锁,并打印出日志 案例描述在定时脚本运行过程中,发现当备份表格的sql语句与删除该表部分数据的sql语句同时 ...
- redis应用场景及实例
Redis在很多方面与其他数据库解决方案不同:它使用内存提供主存储支持,而仅使用硬盘做持久性的存储;它的数据模型非常独特,用的是单线程.另一个大区别在于,你可以在开发环境中使用Redis的功能,但却不 ...
- P2846 [USACO08NOV]光开关Light Switching
题目描述 Farmer John tries to keep the cows sharp by letting them play with intellectual toys. One of th ...