input
q n
q行 F a b或者Q a b
output
face left face top face right
可以用map或者线段树做
1 //map 2 #include<cstdio> 3 #include<map> 4 using namespace std; 5 map<int, char>a; 6 int main() 7 { 8 int n, t, i, d2, d1, r, l, s; 9 char com; 10 map<int, char>::iterator p, q; 11 while (~scanf("%d%d", &n, &t)) 12 { 13 a.insert(make_pair(0, ‘t‘)); 14 a.insert(make_pair(1, ‘t‘)); 15 a.insert(make_pair(t + 1, ‘t‘)); 16 for (i = 0; i < n; i++) 17 { 18 scanf("\n%c%d%d", &com, &d1, &d2); 19 if (com == ‘F‘) 20 { 21 if (d1 > d2) 22 { 23 com = ‘l‘; 24 for (p = a.begin(); p->first < d2; p++); 25 for (q = p; q->first <= d1; q++); 26 q--; 27 char tmp; 28 tmp = q->second; 29 q++; 30 if (p != q) a.erase(p, q); 31 a.insert(make_pair(d2, com)); 32 a.insert(make_pair(d1 + 1, tmp)); 33 } 34 else 35 { 36 com = ‘r‘; 37 for (p = a.begin(); p->first < d1; p++); 38 for (q = p; q->first <= d2; q++); 39 q--; 40 char tmp; 41 tmp = q->second; 42 q++; 43 if (p != q) a.erase(p, q); 44 a.insert(make_pair(d1, com)); 45 a.insert(make_pair(d2 + 1, tmp)); 46 } 47 } 48 else 49 { 50 r = 0; l = 0; s = 0; 51 for (p = a.begin(); p->first <= d1; p++); 52 for (q = p; q->first <= d2; q++); 53 q--; 54 p--; 55 for (; p != q;) 56 { 57 if (p->second == ‘r‘) 58 r += (++p)->first - d1; 59 else if (p->second == ‘l‘) 60 l += (++p)->first - d1; 61 else s += (++p)->first - d1; 62 d1 = p->first; 63 } 64 if (q->second == ‘r‘) r += d2 - d1 + 1; 65 else if (q->second == ‘l‘) l += d2 - d1 + 1; 66 else s += d2 - d1 + 1; 67 printf("%d %d %d\n", l, s, r); 68 } 69 } 70 a.clear(); 71 } 72 return 0; 73 }
1 #include <cstdio> 2 #include <queue> 3 #include <cstring> 4 #include <iostream> 5 #include <cstdlib> 6 #include <algorithm> 7 #include <vector> 8 #include <map> 9 #include <set> 10 #include <ctime> 11 #include <cmath> 12 #define MAX 100000 13 using namespace std; 14 int q,n,setv[MAX*3],v,a,b,sum[3],sumv[MAX*3][3]; 15 void pushdown(int &l,int &r,int &k) 16 { 17 if(setv[k]<0) return; 18 int m=l+((r-l)>>1),lc=k<<1,rc=(k<<1)+1; 19 setv[rc]=setv[lc]=setv[k]; 20 memset(sumv[lc],0,sizeof(sumv[0])); 21 memset(sumv[rc],0,sizeof(sumv[0])); 22 sumv[lc][setv[k]]=m-l+1; 23 sumv[rc][setv[k]]=r-m; 24 setv[k]=-1; 25 } 26 void reset(int l,int r,int k) 27 { 28 int lc=k<<1,rc=(k<<1)+1; 29 sumv[k][0]=sumv[lc][0]+sumv[rc][0]; 30 sumv[k][1]=sumv[lc][1]+sumv[rc][1]; 31 sumv[k][2]=sumv[lc][2]+sumv[rc][2]; 32 } 33 void update(int l,int r,int k) 34 { 35 int lc=k<<1,rc=(k<<1)+1; 36 if(a<=l&&b>=r) 37 { 38 setv[k]=v; 39 memset(sumv[k],0,sizeof(sumv[0])); 40 sumv[k][setv[k]]=r-l+1; 41 return; 42 } 43 pushdown(l,r,k); 44 int m=l+((r-l)>>1); 45 if(a<=m) update(l,m,lc); 46 if(b>m) update(m+1,r,rc); 47 reset(l,r,k); 48 } 49 void query(int l,int r,int k) 50 { 51 // printf("%d:%d %d %d %d\n",k,setv[k],sumv[k][0],sumv[k][1],sumv[k][2]); 52 if(setv[k]>=0) 53 { 54 sum[setv[k]]+=min(r,b)-max(l,a)+1; 55 return; 56 } 57 if(a<=l&&b>=r) 58 { 59 sum[0]+=sumv[k][0]; 60 sum[1]+=sumv[k][1]; 61 sum[2]+=sumv[k][2]; 62 return; 63 } 64 int m=l+((r-l)>>1); 65 if(a<=m) query(l,m,k<<1); 66 if(b>m) query(m+1,r,(k<<1)+1); 67 } 68 int main() 69 { 70 //freopen("/home/user/桌面/in","r",stdin); 71 while(scanf("%d%d",&q,&n)==2) 72 { 73 memset(setv,-1,sizeof(setv[0])*3*n); 74 memset(sumv,0,sizeof(sumv[0])*3*n); 75 a=1;b=n;v=0; 76 update(1,n,1); 77 char op[2]; 78 while(q--) 79 { 80 scanf("%s%d%d",op,&a,&b); 81 if(op[0]==‘F‘) 82 { 83 v=2; 84 if(a>b) 85 { 86 v=1; 87 swap(a,b); 88 } 89 update(1,n,1); 90 // for(int i=1;i<3*n;i++) printf("%d:%d %d %d %d\n",i,setv[i],sumv[i][0],sumv[i][1],sumv[i][2]); 91 } 92 else 93 { 94 sum[0]=sum[1]=sum[2]=0; 95 query(1,n,1); 96 printf("%d %d %d\n",sum[1],sum[0],sum[2]); 97 } 98 } 99 } 100 //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); 101 return 0; 102 }
时间: 2024-10-09 17:08:51