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 ...
随机推荐
- 动态规划:最长上升子序列之基础(经典算法 n^2)
解题心得: 1.注意动态转移方程式,d[j]+1>d[i]>?d[i]=d[j]+1:d[i] 2.动态规划的基本思想:将大的问题化为小的,再逐步扩大得到答案,但是小问题的基本性质要和大的 ...
- C++ 11 从C++ primer第五版的学习笔记
1. auto (page107) auto 推断会忽略const const int ci = i, & cr = ci; auto b = ci; // b is an int (to ...
- OpenCV学习笔记(六) 滤波器 形态学操作(腐蚀、膨胀等)
转自:OpenCV 教程 另附:计算机视觉:算法与应用(2012),Learning OpenCV(2009) 平滑图像:滤波器 平滑 也称 模糊, 是一项简单且使用频率很高的图像处理方法.平滑处理的 ...
- hashlib加密模块
python hashlib密码加密 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/dss_dssssd/article/details/828 ...
- POJ 2771 Guardian of Decency (二分图最大点独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6133 Accepted: 25 ...
- 大数据面试(HR电话了解)
1什么是HA集群? 所谓HA,即高可用(7*24小时不中断服务) HA集群是hadoop高可用集群,即有两个namenode,一个active,一个stanby,active的name挂掉之后,sta ...
- 继承Thread类使用多线程
java实现多线程有两种方式,一种是继承Thread类,另外一种就是实现Runnable接口. 两种实现方法的优缺点: 使用Thread类实现多线程局限性就是不支持多继承,因为java是不支持类多继承 ...
- Java类和对象 详解(一)---写的很好通俗易懂---https://blog.csdn.net/wei_zhi/article/details/52745268
https://blog.csdn.net/wei_zhi/article/details/52745268
- 设计模式之迭代器模式 Iterator
代码实现 public interface MyIterator { void first(); //将游标指向第一个元素 void next(); //将游标指向下一个元素 boolean hasN ...
- Django-缓存机制、跨域请求(CORS)、ContentType组件
Django缓存机制: 在settings中间件里面设置: 三个粒度: 1 全站缓存 用中间件: MIDDLEWARE = [ # 'django.middleware.cache.UpdateCac ...