# [整体二分] Codechef January Challenge 2018 #MONSTER Killing Monsters

104人阅读 评论(0)

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define pb push_back
using namespace std;
typedef long long ll;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
}
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()) if (c=='-') b=-1;
}
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()) if (c=='-') b=-1;
}

const int N=500005;

int n,m;
ll h[N];
int x[N],y[N];

int tim[N],cc[N];

const int S=12;
const int ss=(1<<S)-1;
ll a[N];
int x0=x>>S,x1=x&ss;
for (int i=x0;;i=(i-1)&x0){
a[(i<<S)|x1]+=y;
if (i==0) break;
}
}
inline void Dec(int x,int y){
int x0=x>>S,x1=x&ss;
for (int i=x0;;i=(i-1)&x0){
a[(i<<S)|x1]-=y;
if (i==0) break;
}
}
inline bool Query(int x,ll y){
int x0=x>>S,x1=x&ss;
for (int i=x1^ss;;i=(i-1)&(x1^ss)){
y-=a[x0<<S|(i^ss)];
if (y<=0) return 0;
if (i==0) break;
}
return 1;
}

inline void Solve(int l,int r,vector<int> &v){
if (l==r){
for (int i:v) tim[i]=l;
return;
}
vector<int> lv,rv;
int mid=(l+r)>>1;
for (int i=l;i<=mid;i++)
for (int i:v)
if (Query(i,h[i]))
rv.pb(i);
else
lv.pb(i);
Solve(mid+1,r,rv);
for (int i=l;i<=mid;i++)
Dec(x[i],y[i]);
Solve(l,mid,lv);
}

int main(){
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
vector<int> v; for (int i=0;i<n;i++) v.pb(i);
Solve(1,m+1,v);
for (int i=0;i<n;i++) cc[tim[i]]++;
int ret=n;
for (int i=1;i<=m;i++)
printf("%d\n",ret-=cc[i]);
return 0;
}

0
0

个人资料
• 访问：364255次
• 积分：13016
• 等级：
• 排名：第1238名
• 原创：975篇
• 转载：3篇
• 译文：0篇
• 评论：56条
文章分类
阅读排行
最新评论