Submission #1210057

#TimeUsernameProblemLanguageResultExecution timeMemory
1210057sunflowerXORanges (eJOI19_xoranges)C++17
0 / 100
48 ms5444 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];
int f[MAX_N + 2];

#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];

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

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

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

      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];

      f[0] = 0;
      for (int i = 1; i <= n; ++i) f[i] = f[i - 1] ^ sumXor[i];
    } else {
      int l, r;
      cin >> l >> r;

      int ans = 0;
      if ((r - l + 1) % 2 == 1) {
          ans = sumXor[r];
          ans ^= sumXor[(l - 2 > 0 ? l - 2 : 0)];
      }
      ans ^= f[r - 1] ^ f[l - 1];
      ans ^= f[r - 1] ^ f[l - 2];

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

  return 0;
}

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
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.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     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...