我花了近一个小时编了这个程序,结果却是……
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000000;
int a[maxn],tree[4*maxn],n,m,x,y,k,v,setv[maxn],t;
char op;
void news(int o,int l,int r){
tree[o]=tree[o*2]|tree[o*2+1];
if(setv[o]>0)tree[o]=setv[o];
}
void down(int o){
if(setv[o]>0){
setv[o*2]=setv[o*2+1]=setv[o];
setv[o]=0;
}
}
void built(int o,int l,int r){
if(l==r){
tree[o]=setv[o]=1;
return;
}
int m=(l+r)/2;
built(o*2,l,m);
built(o*2+1,m+1,r);
news(o,l,r);
}
void chaxun(int o,int l,int r){
if(x<=l&&r<=y){
setv[o]=1<<v-1;
tree[o]=1<<v-1;
return;
}
down(o);
int m=(l+r)/2;
if(x<=m)chaxun(o*2,l,m);else news(o*2,l,m);
if(y>m) chaxun(o*2+1,m+1,r);else news(o*2+1,m+1,r);
news(o,l,r);
}
int he(int o,int l,int r){
if(setv[o]>0){
return setv[o];
}
if(x<=l&&r<=y){
return tree[o];
}
int m=(l+r)/2,ans=0;
if(x<=m)ans=ans|he(o*2,l,m);
if(y>m)ans=ans|he(o*2+1,m+1,r);
return ans;
}
int main(){
freopen("tree.in","r",stdin);
scanf("%d%d%d",&n,&t,&m);
built(1,1,n);
for(int i=1;i<=m;i++){
scanf("%c",&op);
if(op=='C'){
cin>>x>>y>>v;
if(x>y)swap(x,y);
chaxun(1,1,n);
}
else{
cin>>x>>y;
if(x>y)swap(x,y);
int t=he(1,1,n);
int ans=0;
while(t){
ans+=t%2;
t/=2;
}
printf("%d",&ans);
}
}
return 0;
}