直接模拟。。。从最低的开始向两边拓展= =

 /**************************************************************
Problem: 1595
User: rausen
Language: C++
Result: Accepted
Time:328 ms
Memory:3932 kb
****************************************************************/ #include <cstdio> using namespace std;
typedef long long ll;
const int N = 1e5 + ;
const ll inf = (ll) 1e18; inline int read(); struct data {
ll w, h;
int pre, nxt; inline void get(int x) {
w = read(), h = read();
pre = x - , nxt = x + ;
}
} a[N]; int n, now;
ll now_ans, ans[N]; int main() {
int i;
n = read();
for (i = now = ; i <= n; ++i) {
a[i].get(i);
if (a[i].h < a[now].h) now = i;
}
a[].w = a[n + ].w = , a[].h = a[n + ].h = inf, a[].nxt = , a[n + ].pre = n;
#define Pre a[now].pre
#define Nxt a[now].nxt
for (i = ; i <= n; ++i) {
while (a[Pre].h < a[now].h) now = Pre;
while (a[Nxt].h < a[now].h) now = Nxt;
ans[now] = now_ans + a[now].w;
a[Pre].nxt = Nxt, a[Nxt].pre = Pre;
if (a[Pre].h < a[Nxt].h) {
now_ans += a[now].w * (a[Pre].h - a[now].h);
a[Pre].w += a[now].w, now = Pre;
} else {
now_ans += a[now].w * (a[Nxt].h - a[now].h);
a[Nxt].w += a[now].w, now = Nxt;
}
}
for (i = ; i <= n; ++i)
printf("%lld\n", ans[i]);
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}

BZOJ1595 [Usaco2008 Jan]人工湖的更多相关文章

  1. [BZOJ1595] [Usaco2008 Jan]人工湖(单调栈)

    传送门 好难的题..至少对我来说. 这题就是模拟从最低的平台注水,然后将最低的填满以后从最低的平台向两边扩展,每次找最近的最低的平台h,然后将水填到h高度. 栈里存的是向外扩展的时候,有时会遇到高度递 ...

  2. 【BZOJ 1594】 [Usaco2008 Jan]猜数游戏 (二分+并查集)

    1594: [Usaco2008 Jan]猜数游戏 Description 为了提高自己低得可怜的智商,奶牛们设计了一个新的猜数游戏,来锻炼她们的逻辑推理能力. 游戏开始前,一头指定的奶牛会在牛棚后面 ...

  3. BZOJ1612: [Usaco2008 Jan]Cow Contest奶牛的比赛

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 645  Solved: 433 ...

  4. Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 891  Solved: 590 ...

  5. BZOJ1596: [Usaco2008 Jan]电话网络

    1596: [Usaco2008 Jan]电话网络 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 513  Solved: 232[Submit][S ...

  6. BZOJ 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛( floyd )

    对于第 i 头牛 , 假如排名比它高和低的数位 n - 1 , 那么他的 rank 便可以确定 . floyd -------------------------------------------- ...

  7. 1596: [Usaco2008 Jan]电话网络

    1596: [Usaco2008 Jan]电话网络 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 601  Solved: 265[Submit][S ...

  8. Usaco2008 Jan

    [Usaco2008 Jan] https://www.luogu.org/problemnew/show/P2419 题目描述 N (1 ≤ N ≤ 100) cows, conveniently ...

  9. 【BZOJ1594】[Usaco2008 Jan]猜数游戏 二分答案+并查集

    [BZOJ1594][Usaco2008 Jan]猜数游戏 Description 为了提高自己低得可怜的智商,奶牛们设计了一个新的猜数游戏,来锻炼她们的逻辑推理能力. 游戏开始前,一头指定的奶牛会在 ...

随机推荐

  1. catkin_make broken after intalling python 3.5 with anaconda

    "No module named catkin_pkg.package" on catkin_make w/ Indigo I have the problem after ana ...

  2. python_way day16 JQuary

    python_way day16 JQuery 封装dom js代码 jQuery(1.10,1.12-兼容性好,2.0.以后放弃了ie9以下) - 封装了Dom & JavaScript 查 ...

  3. iOS - OC NSProcessInfo 系统进程信息

    前言 @interface NSProcessInfo : NSObject NSProcessInfo 类中包含一些方法,允许你设置或检索正在运行的应用程序(即进程)的各种类型的信息. 1.获取系统 ...

  4. js实现checkbox的全选和全不选功能

    html代码: <form name="form1" method="post" action="manage.php?act=sub" ...

  5. Java编程思想学习笔记_1(Java内存和垃圾回收)

    1.Java中对象的存储数据的地方: 共有五个不同的地方可以存储数据. 1)寄存器.最快,因为位于处理器的内部,寄存器按需求分配,不能直接控制. 2)堆栈.位于通用RAM,通过堆栈指针可以从处理器那里 ...

  6. Android版本升级同时Sqlite数据库的升级及之前数据的保留

    http://www.cnblogs.com/wang340/archive/2013/05/06/3063135.html http://www.eoeandroid.com/forum.php?m ...

  7. listview某一项不可点击

    listview 整个都不可操作 listview.setEnable(false); listview 某一项不可点击 重写 isEnable()方法,在方法内部判断position,不可点击的项 ...

  8. armp启动

    1.启动apahcehttpd.exe -k starthttpd.exe -k restart 重启httpd.exe -k install 安装 2.php启动apache.conf文件添加:Lo ...

  9. 如何在大量jar包中搜索特定字符

    欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...

  10. 浏览器编码的函数简介escape(),encodeURI(),encodeURIComponent()

    1.escape() escape()是js编码函数中最古老的一个.虽然这个函数现在已经不提倡使用了,但是由于历史原因,很多地方还在使用它,所以有必要先从它讲起. 实际上,escape()不能直接用于 ...