# bzoj2527: [Poi2011]Meteors

#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=(n);i++)
#define inf 0x3f3f3f3f
using namespace std;
const int N=300005;
typedef long long ll;
vector<int> a[N];
int n,m,K,p[N],l[N],r[N],id[N],stone[N],ans[N],T=0,sta[N];
ll tr[N];

ll Q(int x){ll tmp=0;for(;x;x-=(x&-x))tmp+=tr[x];return tmp;}

void up(int k,int f){
}
void solve(int l,int r,int L,int R){
if(l>r)return;
if(L==R){rep(i,l,r)ans[id[i]]=L;return;}
int mid=(L+R)>>1;
while(T<mid)up(T+1,1),T++;
while(T>mid)up(T,-1),T--;
int cnt=l,cnt2=r;
ll tot;
rep(i,l,r){
tot=0;
if(a[id[i]].size())
rep(j,0,a[id[i]].size()-1){
tot+=Q(a[id[i]][j]);
if(tot>=p[id[i]]){
sta[cnt++]=id[i];
break;
}
}
if(tot<p[id[i]])sta[cnt2--]=id[i];
}
rep(i,l,r)id[i]=sta[i];
solve(l,cnt-1,L,mid);
solve(cnt,r,mid+1,R);
}
int main(){//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
scanf("%d%d",&n,&m);int x;
rep(i,1,m)scanf("%d",&x),a[x].push_back(i);
rep(i,1,n)scanf("%d",&p[i]),id[i]=i;
scanf("%d",&K);
rep(i,1,K)scanf("%d%d%d",&l[i],&r[i],&stone[i]);
K++;l[K]=1,r[K]=m,stone[K]=inf;
solve(1,n,1,K);
rep(i,1,n){if(ans[i]>=K)printf("NIE\n");
else printf("%d\n",ans[i]);
}
}

• 本文已收录于以下专栏：

## BZOJ 2527 [Poi2011]Meteors [整体二分+线段树]

BZOJ 2527 [Poi2011]Meteors [整体二分+线段树]

## 【POI2011】【BZOJ2527】Meteors

Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gal...

## BZOJ 2527: [Poi2011]Meteors

• QWsin
• 2017-02-15 20:29
• 363

## BZOJ2527: [Poi2011]Meteors

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)