Submission #599275

#TimeUsernameProblemLanguageResultExecution timeMemory
599275PlurmIntergalactic ship (IZhO19_xorsum)C++11
9 / 100
2083 ms2632 KiB
#include <bits/stdc++.h>
using namespace std;

int a[1024];
int qs[1024];
const int MOD = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  int q;
  scanf("%d", &q);
  vector<tuple<int, int, int>> updates;
  for (int i = 0; i < q; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    updates.push_back({l, r, x});
  }
  if (q <= 20) {
    int ans = 0;
    for (int bit = 0; bit < (1 << q); bit++) {
      for (int i = 0; i < q; i++) {
        if (bit & (1 << i)) {
          int l, r, x;
          tie(l, r, x) = updates[i];
          for (int i = l; i <= r; i++) {
            a[i] ^= x;
          }
        }
      }
      for (int i = 1; i <= n; i++) {
        qs[i] = (qs[i - 1] + a[i]) % MOD;
      }
      for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
          // computing sum(i, j)^2
          int k = 1ll * (qs[j] - qs[i - 1]) * (qs[j] - qs[i - 1]) % MOD;
          ans += k;
          ans %= MOD;
        }
      }
      for (int i = 0; i < q; i++) {
        if (bit & (1 << i)) {
          int l, r, x;
          tie(l, r, x) = updates[i];
          for (int i = l; i <= r; i++) {
            a[i] ^= x;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
xorsum.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d", a + i);
      |     ~~~~~^~~~~~~~~~~~~
xorsum.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
xorsum.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d%d%d", &l, &r, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...