Submission #1210051

#TimeUsernameProblemLanguageResultExecution timeMemory
1210051sunflowerXORanges (eJOI19_xoranges)C++17
55 / 100
1094 ms2816 KiB
#include <bits/stdc++.h>
using namespace std;

int n, q;

#define MAX_N 200'200
int a[MAX_N + 7], pre[MAX_N + 7], sumXor[MAX_N + 7];

#undef MAX_N

int main() {
  ios_base::sync_with_stdio(false);cin.tie(nullptr);
  if (fopen("test.inp","r")) {
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
  }
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i];

  pre[0] = 0;
  for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] ^ a[i];

  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      a[pos] = val;
    } else {
      int l, r;
      cin >> l >> r;

      pre[0] = 0;
      for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] ^ a[i];

      sumXor[0] = 0;
      for (int i = 1; i <= n; ++i) sumXor[i] = sumXor[i - 1] ^ pre[i];

      int ans = 0;
      for (int len = 1; len <= r - l + 1; ++len) {
        /// canh duoi:
//        i = L -> R - len + 1
//  -1:      L - 1 R - len;
        /// canh tren;
//        i = L + len - 1 --> R;

        ans ^= (sumXor[(l - 2 > 0 ? l - 2 : 0)] ^ sumXor[r - len]) ^ (sumXor[r] ^ sumXor[l + len - 2]);
      }

      cout << ans << "\n";
    }
  }

  return 0;
}

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("test.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("test.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...