답안 #464790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464790 2021-08-14T07:12:03 Z kilikuma XORanges (eJOI19_xoranges) C++14
100 / 100
175 ms 12684 KB
#include <bits/stdc++.h> 
using namespace std;
long arbreImpair[(1<<19)+42] = {0}; 
long arbrePair[(1<<19)+42] = {0}; 
long xorImpair = 0, xorPair = 0; 
void modifieImpair(int a) {
  while (a>0) {
    arbreImpair[a] = arbreImpair[a*2]^arbreImpair[a*2+1]; 
   // printf("%ld\n", arbreImpair[a]); 
    a = a/2; 
  }
}
void modifiePair(int a) {
  while (a>0) {
    arbrePair[a] = arbrePair[a*2]^arbrePair[a*2+1]; 
   // printf("%ld\n", arbrePair[a]); 
    a = a/2; 
  }
}
void interImpair(int a, int b) {
  if (a>b) return; 
  if (a==b) {
    xorImpair = xorImpair^arbreImpair[a]; 
    return; 
  }
  if ((a%2) == 1){
    xorImpair = xorImpair^arbreImpair[a]; 
    a++; 
  }
  if ((b%2) == 0) {
    xorImpair = xorImpair^arbreImpair[b];
    b--; 
  }
  interImpair(a/2, b/2);  
}
void interPair(int a, int b) {
  if (a>b) {
  //  printf("what did happen"); 
    return; 
  }
    
//  printf("%d %d\n", a, b); 
  //printf("Please tell me where this went wrong"); 
  if (a==b) {
    xorPair = xorPair^arbrePair[a]; 
    // printf("%ld\n", arbrePair[a]); 
    return; 
  }
  if ((a%2) == 1) {
    xorPair = xorPair^arbrePair[a]; 
   // printf("%ld\n", arbrePair[a]); 
    a ++; 
  }
  if ((b%2) == 0) {
    xorPair = xorPair^arbrePair[b];
   //printf("%ld\n", arbrePair[b]); 
   // ;
    b--;
  }
//  printf("OMG"); 
  interPair(a/2, b/2);  
}
int main() {
  int DEC = (1<<18); 
  int nbElements, nbRequetes; 
  scanf("%d%d",&nbElements,&nbRequetes); 
  long b; 
  int l, r; 
  int pos; long val; 
  for (int i = 0; i< nbElements;i++) {
    scanf("%ld",&b); 
    if ((i+1)%2) {
      arbreImpair[i+DEC] = b; 
      modifieImpair((i+DEC)/2); 
   //   printf("%d\n", (i+DEC)); 
    }
    else {
      arbrePair[i+DEC] = b; 
      modifiePair((i+DEC)/2); 
  //    printf("%d\n", (i+DEC)); 
    }
  }
  for (int q = 0; q < nbRequetes; q ++) {
    int idQ; scanf("%d",&idQ); 
    if (idQ == 1) {
      scanf("%d%ld", &pos, &val); 
      if (pos%2) {
        arbreImpair[pos+DEC-1] = val; 
        modifieImpair((pos+DEC-1)/2); 
      }
      else {
        arbrePair[pos+DEC-1] = val; 
        modifiePair((pos+DEC-1)/2); 
      }
    }
    else {
      scanf("%d%d",&l,&r); 
      xorImpair = 0; xorPair = 0; 
      if ((r-l)%2) {
 
        printf("%d\n", 0); 
      } 
      else {
        if (r%2) {
          interImpair(l+DEC-1,r+DEC-1); 
       //   printf("%ld %ld\n", l+DEC-1, r+DEC-1); 
          printf("%ld \n", xorImpair); 
        }
        else {
          interPair(l+DEC-1,r+DEC-1); 
          printf("%ld\n", xorPair); 
        }
      }
    }
  }
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d%d",&nbElements,&nbRequetes);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     scanf("%ld",&b);
      |     ~~~~~^~~~~~~~~~
xoranges.cpp:84:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     int idQ; scanf("%d",&idQ);
      |              ~~~~~^~~~~~~~~~~
xoranges.cpp:86:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |       scanf("%d%ld", &pos, &val);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:97:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |       scanf("%d%d",&l,&r);
      |       ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 12684 KB Output is correct
2 Correct 175 ms 12628 KB Output is correct
3 Correct 160 ms 12660 KB Output is correct
4 Correct 149 ms 12304 KB Output is correct
5 Correct 144 ms 12312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 4 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 4 ms 588 KB Output is correct
15 Correct 163 ms 12684 KB Output is correct
16 Correct 175 ms 12628 KB Output is correct
17 Correct 160 ms 12660 KB Output is correct
18 Correct 149 ms 12304 KB Output is correct
19 Correct 144 ms 12312 KB Output is correct
20 Correct 158 ms 12388 KB Output is correct
21 Correct 159 ms 12288 KB Output is correct
22 Correct 158 ms 12296 KB Output is correct
23 Correct 150 ms 12276 KB Output is correct
24 Correct 146 ms 12228 KB Output is correct