Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Others)
Total Submission(s): 33 Accepted Submission(s): 11
1 #define LOCAL 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<iostream> 7 using namespace std; 8 const int maxn=1000100; 9 10 struct node 11 { 12 int lef,rig; //通过和的大小来比较种类是否一样 13 int cnt; //跟新的种类 14 int type; //保存的种类 15 int mid(){ 16 return lef+(rig-lef>>1); 17 } 18 }; 19 20 node sac[maxn<<3]; 21 int ans[maxn*4],ct; 22 23 void Build(int left,int right,int pos) 24 { 25 sac[pos]=(node){left,right,0,2}; //单一 26 if(left==right) return ; 27 int mid=sac[pos].mid(); 28 Build(left,mid,pos<<1); 29 Build(mid+1,right,pos<<1|1); 30 } 31 32 void Update(int left,int right,int pos,int val) 33 { 34 if(left<=sac[pos].lef&&sac[pos].rig<=right) 35 { 36 sac[pos].cnt=val; 37 sac[pos].type=val; 38 return ; 39 } 40 41 if(sac[pos].cnt!=0) 42 { //向下更新一次 43 sac[pos<<1|1].cnt=sac[pos<<1].cnt=sac[pos].cnt; 44 sac[pos<<1|1].type=sac[pos<<1].type=sac[pos].type; 45 sac[pos].cnt=0; 46 } 47 int mid=sac[pos].mid(); 48 if(mid>=left) 49 Update(left,right,pos<<1,val); 50 if(mid<right) 51 Update(left,right,pos<<1|1,val); 52 if(sac[pos<<1].type==sac[pos<<1|1].type) 53 sac[pos].type=sac[pos<<1].type; 54 else sac[pos].type=0; 55 } 56 57 void Query(int pos,int left,int right) {//查找操作 58 59 if(sac[pos].lef>right||sac[pos].rig<left) 60 return ; 61 62 if(sac[pos].type) 63 { 64 ans[ct++]=sac[pos].type; 65 return ; 66 } 67 Query(pos<<1,left,right); 68 Query(pos<<1|1,left,right); 69 70 } 71 72 int main() 73 { 74 int n,m,a,b,c; 75 char s[2]; 76 #ifdef LOCAL 77 freopen("test.in","r",stdin); 78 #endif 79 while(scanf("%d%d",&n,&m),n+m!=0){ 80 Build(1,n,1); 81 ct=0; 82 while(m--) 83 { 84 scanf("%s",s); 85 if(s[0]=='P'){ 86 scanf("%d%d%d",&a,&b,&c); 87 Update(a,b,1,c); 88 } 89 else 90 { 91 scanf("%d%d",&a,&b); 92 Query(1,a,b); 93 sort(ans,ans+ct); 94 printf("%d",ans[0]); 95 for(int i=1;i<ct;i++){ 96 if(ans[i]!=ans[i-1]) 97 printf(" %d",ans[i]); 98 } 99 printf("\n"); 100 ct=0; 101 } 102 } 103 } 104 return 0; 105 }