Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int n;
- int const N = 1000010;
- struct elem{
- int R,G,B;
- };
- elem fwtree[N];
- elem addE(elem a,elem b){
- return {a.R + b.R ,a.G + b.G , a.B + b.B};
- }
- elem minusE(elem a,elem b){
- return {a.R - b.R ,a.G - b.G , a.B - b.B};
- }
- void add(int I,elem e){
- for(int i = I ; i <= n ; i+=(i&-i)){
- fwtree[i] = addE(fwtree[i],e);
- }
- }
- elem query(int I){
- elem ans = {0,0,0};
- for(int i = I ; i > 0 ; i-=(i&-i)){
- ans = addE(ans,fwtree[i]);
- }
- return ans;
- }
- void check(elem e){
- if(e.R > e.B && e.R > e.G){
- printf("R\n");
- }
- else if(e.G > e.R && e.G > e.B){
- printf("G\n");
- }
- else if(e.B > e.G && e.B > e.R){
- printf("B\n");
- }
- else{
- printf("None\n");
- }
- }
- void testelem(elem an){
- printf("Test %d %d %d\n",an.R ,an.G,an.B);
- }
- int main()
- {
- int m;
- scanf("%d",&n);
- scanf("%d",&m);
- for(int i = 0 ; i <= n ; i ++)fwtree[i] = {0,0,0};
- elem data[n+1];
- for(int i = 1 ; i <= n ; i ++){
- if(i % 3 == 1){
- data[i] = {1,0,0};
- add(i,{1,0,0});
- }
- else if(i%3 == 2){
- data[i] = {0,1,0};
- add(i,{0,1,0});
- }
- else if(i%3 == 0){
- data[i] = {0,0,1};
- add(i,{0,0,1});
- }else{
- printf("Error %d\n",i);
- return 0;
- }
- }
- for(int q = 0 ; q < m ; q ++){
- int A;
- scanf("%d",&A);
- if(A == 1){
- int idx;
- char c;
- scanf("%d %c",&idx,&c);
- elem te = {0,0,0};
- te = minusE(te,data[idx]);
- if(c == 'R'){
- te.R++;
- data[idx] = {1,0,0};
- }else if(c == 'G'){
- te.G++;
- data[idx] = {0,1,0};
- }else if(c == 'B'){
- te.B++;
- data[idx] = {0,0,1};
- }else{
- printf("Error %c\n",c);
- return 0;
- }
- // printf("update (%d,%c): ",idx,c);testelem(te);
- add(idx,te);
- }
- else if(A == 2){
- int L,R;
- scanf("%d %d",&L,&R);
- elem an = minusE(query(R),query(L-1));
- // printf("query (%d,%d): ",L,R);testelem(an);
- check(an);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement