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 ...
随机推荐
- [Poj2761]Feed the dogs(主席树)
Desciption 题意:求区间第K小(N<=100000) Solution 主席树模板题 Code #include <cstdio> #include <algorit ...
- 牛课第二次多校I
链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 题目描述 White Cloud has a square of n*n from (1,1) ...
- Beats、Filebea入门
1. Filebeat配置简介 2. Filebeat收集nginx日志 3. packetbeat简介与演示
- Assigning Logon Hours
Assigning Logon Hours Updated: March 28, 2003 Applies To: Windows Server 2003, Windows Server 2003 R ...
- Windows网络编程笔记5 -- 其他套接字
包括红外线套接字(IrSock).IPX/SPX 套接字.NetBIOS 套接字.AppleTalk 套接字.ATM 套接字等.对这些套接字进行简单介绍. 第一.红外线套接字(I r S o c k) ...
- DirectShow简单入门程序
1.首先确认已安装过相关工具及配置环境,然后打开vs2010,新建一对话框应用程序 取名为Player_test1,然后打开菜单->项目->属性-> 添加strmmiids.lib库 ...
- day05_07 标志位讲解
continue: 需求:大于5才打印 for i in range(10): if i<6 : continue print(i) continue作用:结束本次循环,继续下次循环 break ...
- 数组线性表ArrayList 和链表类LinkedList
数组线性表类ArrayList 和链表类LinkedList 是实现List接口的两个具体类.ArrayList 数组储存元素,这个数组是动态创建的.如果元素个数超过了数组的容量,就创建一个更大的新数 ...
- 1020 PAT
在编译器上运行没问题,提交显示编译错误 # include<stdio.h> # include<stdlib.h> struct YB { int a,b; double c ...
- iOS-绘制UIView之drawCGRect
写在前面 UIView对于iOS开发来讲,再熟悉不过了.也正是因为这一点,我们可能会忽略UIView一些特有方法的理解和使用.今天,笔者主要整理一下对drawRect方法的理解和使用. 默认情况下,该 ...