BZOJ 2527 Meteors
http://www.lydsy.com/JudgeOnline/problem.php?id=2527
思路:整体二分
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 1000000010
int n,m,a[],first[],next[],tot;
int tol[],tor[],ans[],id[],K;
ll cur[],tmp[],h[],go[];
struct node{
int id,l,r,w;
}q[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll sum(int x){
ll res=;
while (x){
res+=h[x];
x-=(x)&(-x);
}
return res;
}
void add(int x,ll v){
for (int i=x;i<=m;i+=(i)&(-i))
h[i]+=v;
}
void add(int x,int y,ll v){
add(x,v);add(y+,-v);
}
void solve(int l,int r,int x,int y){
if (x>y) return;
if (l==r){
for (int i=x;i<=y;i++)
ans[id[i]]=l;
return;
}
int lnum=,rnum=;
int mid=(l+r)>>;
for (int i=l;i<=mid;i++)
if (q[i].l<=q[i].r) add(q[i].l,q[i].r,q[i].w);
else add(q[i].l,m,q[i].w),add(,q[i].r,q[i].w);
for (int i=x;i<=y;i++){
tmp[id[i]]=;
for (int j=first[id[i]];j;j=next[j]){
int pur=go[j];
tmp[id[i]]+=sum(pur);
if (tmp[id[i]]+cur[id[i]]>=a[id[i]]) break;
}
if (tmp[id[i]]+cur[id[i]]>=a[id[i]]) tol[++lnum]=id[i];
else tor[++rnum]=id[i],cur[id[i]]+=tmp[id[i]];
}
for (int i=l;i<=mid;i++)
if (q[i].l<=q[i].r) add(q[i].l,q[i].r,-q[i].w);
else add(q[i].l,m,-q[i].w),add(,q[i].r,-q[i].w);
for (int i=;i<lnum;i++)
id[x+i]=tol[i+];
for (int i=;i<rnum;i++)
id[x+lnum+i]=tor[i+];
solve(l,mid,x,x+lnum-);
solve(mid+,r,x+lnum,y);
}
int main(){
n=read();m=read();
for (int i=;i<=m;i++){
int x=read();
tot++;
next[tot]=first[x];
first[x]=tot;
go[tot]=i;
}
for (int i=;i<=n;i++)
a[i]=read();
K=read();
for (int i=;i<=K;i++){
q[i].l=read();q[i].r=read();q[i].w=read();
q[i].id=i;
}
K++;
q[K].l=;q[K].r=m;q[K].w=inf;
q[K].id=K;
for (int i=;i<=n;i++)
id[i]=i;
solve(,K,,n);
for (int i=;i<=n;i++){
if (ans[i]!=K) printf("%d\n",ans[i]);
else puts("NIE");
}
return ;
}
BZOJ 2527 Meteors的更多相关文章
- BZOJ 2527 Meteors | 整体二分
BZOJ 2527 Meteors 题意 一个圆环上有m个位置,编号为1~m,分别属于n个国家. 有k个时刻,每个时刻都会给圆环上的一个区间中每个位置的值加上一个数. 每个国家有一个目标,问对于每个国 ...
- bzoj 2527 Meteors - 整体二分 - 树状数组
Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gala ...
- BZOJ 2527 [Poi2011]Meteors(整体二分)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2527 [题目大意] 有N个成员国.现在它发现了一颗新的星球, 这颗星球的轨道被分为M份 ...
- BZOJ 2527 [Poi2011]Meteors:整体二分
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2527 题意: 有n个国家和m个空间站,每个空间站都属于一个国家,一个国家可以有多个空间站, ...
- bzoj 2527: [Poi2011]Meteors 整体二分
给每个国家建一个链表,这样分治过程中的复杂度就和序列长度线形相关了,无脑套整体二分就可以. (最坑的地方是如果所有位置都是一个国家,那么它的样本个数会爆longlong!!被这个坑了一次,大于p[i] ...
- 【bzoj 2527】[Poi2011]Meteors
Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gala ...
- bzoj 2527: [Poi2011]Meteors
昨天写了一晚,越写复杂度越感觉不对,早上一想果然是假的. (这里n,m,k我就不区分了) 首先一个城市的询问可以很容易的二分 check用树状数组维护区间(区间修改,单点查询的那种) 一次是\(O(n ...
- BZOJ 2527 [Poi2011]Meteors (整体二分+树状数组)
整体二分板题,没啥好讲的-注意是个环-还有所有贡献会爆longlong,那么只要在加之前判断一下有没有达到需要的值就行了- CODE #include <set> #include < ...
- BZOJ 2527 & 整体二分
Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站. 这个星球经常会下陨石雨 ...
随机推荐
- 总结:man, info, hwclock, cal, type, which, dirname, basename, who, which, whatis, makewhatis, hash, tty
man, info, help, date, hwclock, cal, shutdown, reboot, halt, poweroff, type, cd, which, dirname, bas ...
- redis 异常排查
异常排查 redis-server redis.windows.conf D:\redis-2.8.17>redis-server.exe redis.windows.conf[4692] 27 ...
- [LeetCode] 160. Intersection of Two Linked Lists 解题思路
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- Linux grep 命令中的正则表达式详解
在 Linux .类 Unix 系统中我该如何使用 Grep 命令的正则表达式呢? Linux 附带有 GNU grep 命令工具,它支持扩展正则表达式(extended regular expres ...
- 我对Laravel ThinkPHP Yii symfony2 CI cakephp 的看法
这是我的真心体会,在尝试使用Laravel.ThinkPHP.Yii.symfony2.CI.cakephp.Yii2 之后的真实想法(default7#zbphp.com). 1)ThinkPHP ...
- 差别client、offset、scroll系列以及event的几个距离属性
element元素结点属性 一. offset系列 1.offsetWidth 和offsetHeight element.offsetWidth是一个仅仅读属性,它包含了: css width + ...
- Zend Studio使用
也许你能够用Dreamweaver.Notepad++或者Editplus这种东西完毕你的系统,但所谓“工欲善其事,必先利其器”,偶觉得 一个给力的IDE对于新手还是非常必要的,而Zend作为PHPe ...
- angularjs之双向绑定
今天所学习的东西虽然不是很多 但是对我来说受益匪浅, 就比如说在table中要选中一行的话我们可以这样写: 模板中: <table ng-controller="tableContro ...
- 初学Pexpect
概述 Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块 ...
- PropertyGird( 属性表格) 组件
本节课重点了解 EasyUI 中 PropertyGird(属性表格)组件的使用方法,这个组件依赖于 DataGrid(数据表格)组件. 一. 加载方式 //class 加载方式<table i ...