Advertisement
Emiliatan

c651

Sep 3rd, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. /* c651              */
  2. /* AC (0.1s, 11.8MB) */
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. //
  8. #ifdef __GNUC__
  9.         #include <unistd.h>
  10.         #include <fcntl.h>
  11.         #include <sys/types.h>
  12.         #include <sys/stat.h>
  13.  
  14.         #define fread fread_unlocked
  15.         #define putchar putchar_unlocked
  16. #else
  17.         #define getc getchar
  18. #endif
  19.  
  20. namespace IO
  21. {
  22.     constexpr int buf_s = 1 << 15;
  23.     static char ch;
  24.     static bool negative;
  25.     inline int getc()
  26.     {
  27.         static char buf[buf_s], *p1 = buf, *p2 = buf;
  28.         return p1 == p2 && (p2 = (p1 = buf) + read(STDIN_FILENO, buf, buf_s), p1 == p2) ? EOF : *p1++;
  29.     }
  30.     inline int nextInt32(int &out)
  31.     {
  32.         if (ch == EOF) return -1;
  33.  
  34.         static int tmp;
  35.         tmp = 0;
  36.         negative = false;
  37.  
  38.         ch = getc();
  39.         if (ch != '-' && (ch < '0' || ch > '9'))
  40.             return (ch == EOF ? -1 : ch);
  41.  
  42.         (ch == '-' ? negative = true : tmp = ch - '0');
  43.  
  44.         while ((ch = getc()) && ch >= '0' && ch <= '9')
  45.             tmp = tmp * 10 + ch - '0';
  46.  
  47.         out = (negative ? -tmp : tmp);
  48.  
  49.         return 1;
  50.     }
  51.  
  52.     static char s[25];
  53.     static int index;
  54.     inline void printInt32(int x)
  55.     {
  56.         if (x == 0) putchar('0');
  57.         negative = (x < 0 && (x = -x));
  58.  
  59.         index = 0;
  60.         while (x) s[index++] = x % 10 + '0', x /= 10;
  61.  
  62.         (negative ? s[index++] = '-' : s[index]);
  63.  
  64.         while (index) putchar(s[--index]);
  65.     }
  66. }
  67.  
  68. using IO::nextInt32;
  69. using IO::printInt32;
  70. //
  71.  
  72. auto lowbit = [](const int &x) noexcept { return x & (-x); };
  73. const int MAXN = 1e6;
  74.  
  75. int N, Q, x, y;
  76. int BIT[MAXN + 2], arr[MAXN + 2];
  77.  
  78. int query(int l, int r)
  79. {
  80.     int ans = 0, ans_ = 0;
  81.  
  82.     for(;r; r -= lowbit(r))
  83.         ans ^= BIT[r];
  84.  
  85.     for(--l; l; l -= lowbit(l))
  86.         ans_ ^= BIT[l];
  87.  
  88.     return ans ^ ans_;
  89. }
  90.  
  91. void updata(int pos, int x)
  92. {
  93.     x = arr[pos] ^ x;
  94.  
  95.     for(;pos <= N; pos += lowbit(pos))
  96.         BIT[pos] ^= x;
  97. }
  98.  
  99. int main()
  100. {
  101.     nextInt32(N);
  102.     nextInt32(Q);
  103.  
  104.     for(int i = 1; i <= N && nextInt32(x); ++i)
  105.     {
  106.         updata(i, x);
  107.         arr[i] = x;
  108.     }
  109.  
  110.     for(int i = 0; i < Q; ++i)
  111.     {
  112.         nextInt32(x);
  113.         if(x == 0)
  114.         {
  115.             nextInt32(x);
  116.             nextInt32(y);
  117.  
  118.             printInt32(query(x, y));
  119.             putchar('\n');
  120.         }
  121.         else
  122.         {
  123.             nextInt32(x);
  124.             nextInt32(y);
  125.  
  126.             updata(x, y);
  127.             arr[x] = y;
  128.         }
  129.     }
  130.  
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement