| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:RE刷版了,求数据啊。。。给的都没问题啊。。。0也没问题啊In Reply To:RE刷版了,求数据啊。。。给的都没问题啊。。。0也没问题啊 Posted by:watashiwamajia at 2012-05-05 15:59:36 > 求数据
#include<cstdio>
#include<cstring>
#define M 132000
int ll=-10,rr=-10,jud=1,jj=0;
struct Node{
int l,r;
bool pure,val;
}n[4*M];
void build(int l,int r,int th){
n[th].l=l;
n[th].r=r;
n[th].val=0;
n[th].pure=1;
if(l==r) return;
int m=(l+r)>>1;
build(l,m,th<<1);
build(m+1,r,th<<1|1);
}
void update(int l,int r,int th,int val){
if(l==n[th].l&&r==n[th].r){
n[th].val=val;
n[th].pure=1;
return;
}
if(n[th].pure) {
n[th<<1].val=n[th<<1|1].val=n[th].val;
n[th<<1].pure=n[th<<1|1].pure=1;
}
n[th].pure=0;
int m=(n[th].l+n[th].r)>>1;
if(m>=r) update(l,r,th<<1,val);
else if(l>m) update(l,r,th<<1|1,val);
else {
update(l,m,th<<1,val);
update(m+1,r,th<<1|1,val);
}
if(n[th<<1].pure&&n[th<<1|1].pure&&n[th<<1].val==n[th<<1|1].val) {
n[th].val=n[th<<1].val;
n[th].pure=1;
}
}
void change(int l,int r,int th){
if(n[th].pure) {
if(l==n[th].l&&r==n[th].r){
n[th].val=!n[th].val;
return;
}
n[th].pure=0;
n[th<<1].pure=n[th<<1|1].pure=1;
n[th<<1].val=n[th<<1|1].val=n[th].val;
}
int m=(n[th].l+n[th].r)>>1;
if(m>=r) change(l,r,th<<1);
else if(l>m) change(l,r,th<<1|1);
else {
change(l,m,th<<1);
change(m+1,r,th<<1|1);
}
}
void out(){
//printf("%d %d\n",ll,rr);
if(ll==-10){
printf("empty set");
return;
}
if(!jud) printf(" ");
else jud=0;
if(ll&1) printf("(%d,",(ll-1)/2-1);
else printf("[%d,",ll/2-1);
if(rr&1) printf("%d)",(rr+1)/2-1);
else printf("%d]",rr/2-1);
}
void query(int l,int r,int th){
if(n[th].l==l&&n[th].r==r&&n[th].pure){
if(n[th].val){
if(n[th].l!=rr+1){
if(jj) out();
else jj=1;
ll=n[th].l;
rr=n[th].r;
}
else rr=n[th].r;
}
return;
}
int m=(n[th].l+n[th].r)>>1;
query(l,m,th<<1);
query(m+1,r,th<<1|1);
}
int main(){
int t1,t2;
char x[3],xx,yy;
build(0,M,1);
while(scanf("%s",x)!=EOF){
getchar();
scanf("%c%d,%d%c",&xx,&t1,&t2,&yy);
t1*=2;t2*=2;
if(xx=='(') t1++;
if(yy==')') t2--;
t1+=2;t2+=2;
if(t1>t2) continue;
if(x[0]=='U'){
update(t1,t2,1,1);
}
else if(x[0]=='D'){
update(t1,t2,1,0);
}
else if(x[0]=='S'){
change(t1,t2,1);
}
else if(x[0]=='C'){
update(0,t1-1,1,0);
update(t2+1,M-1,1,0);
change(t1,t2,1);
}
else{
update(0,t1-1,1,0);
update(t2+1,M-1,1,0);
}
}
query(0,M,1);
out();
printf("\n");
return 0;
}
自己生成的数据只跑了0.175s.....65536个操作。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator