Submission #815552

# Submission time Handle Problem Language Result Execution time Memory
815552 2023-08-08T16:53:37 Z EntityPlantt XORanges (eJOI19_xoranges) C++14
100 / 100
108 ms 7172 KB
#include <vector>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
class segment_tree {
    int n;
    vector <int> tree;
public:
    segment_tree(vector <int> &v) {
        n = 1 << int(ceil(log2(v.size())));
        tree.resize((n << 1) - 1, 0);
        copy(v.begin(), v.end(), tree.begin() + n - 1);
        for (int i = n - 2; i >= 0; i--) {
            tree[i] = tree[(i << 1) + 1] ^ tree[(i << 1) + 2];
        }
    }
    int size() { return n; }
    void set(int i, const int &val) {
        i += n - 1;
        tree[i] = val;
        while (i) {
            i = i - 1 >> 1;
            tree[i] = tree[(i << 1) + 1] ^ tree[(i << 1) + 2];
        }
    }
    int get(int l, int r, int node = 0, int cl = 0, int cr = -1) {
        if (cr < 0) cr = n - 1;
        if (cl == l && cr == r) return tree[node];
        if (cl > r || cr < l) return 0;
        return get(l, min(r, cl + cr >> 1), (node << 1) + 1, cl, cl + cr >> 1) ^ get(max(l - 1, cl + cr >> 1) + 1, r, (node << 1) + 2, (cl + cr >> 1) + 1, cr);
    }
};
int n, q, i, x;
vector <int> a, b;
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    a.resize(n, 0); b.resize(n, 0);
    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (i & 1) a[i] = x; else b[i] = x;
    }
    segment_tree A(a), B(b);
    while (q--) {
        scanf("%d%d%d", &n, &i, &x);
        if (n == 1) {
            if (--i & 1) A.set(i, x);
            else B.set(i, x);
        }
        else {
            if (--x - --i & 1) printf("0\n");
            else printf("%d\n", i & 1 ? A.get(i, x) : B.get(i, x));
        }
    }
}

Compilation message

xoranges.cpp: In member function 'void segment_tree::set(int, const int&)':
xoranges.cpp:23:19: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   23 |             i = i - 1 >> 1;
      |                 ~~^~~
xoranges.cpp: In member function 'int segment_tree::get(int, int, int, int, int)':
xoranges.cpp:31:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         return get(l, min(r, cl + cr >> 1), (node << 1) + 1, cl, cl + cr >> 1) ^ get(max(l - 1, cl + cr >> 1) + 1, r, (node << 1) + 2, (cl + cr >> 1) + 1, cr);
      |                              ~~~^~~~
xoranges.cpp:31:69: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         return get(l, min(r, cl + cr >> 1), (node << 1) + 1, cl, cl + cr >> 1) ^ get(max(l - 1, cl + cr >> 1) + 1, r, (node << 1) + 2, (cl + cr >> 1) + 1, cr);
      |                                                                  ~~~^~~~
xoranges.cpp:31:100: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         return get(l, min(r, cl + cr >> 1), (node << 1) + 1, cl, cl + cr >> 1) ^ get(max(l - 1, cl + cr >> 1) + 1, r, (node << 1) + 2, (cl + cr >> 1) + 1, cr);
      |                                                                                                 ~~~^~~~
xoranges.cpp:31:140: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         return get(l, min(r, cl + cr >> 1), (node << 1) + 1, cl, cl + cr >> 1) ^ get(max(l - 1, cl + cr >> 1) + 1, r, (node << 1) + 2, (cl + cr >> 1) + 1, cr);
      |                                                                                                                                         ~~~^~~~
xoranges.cpp: In function 'int main()':
xoranges.cpp:52:21: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   52 |             if (--x - --i & 1) printf("0\n");
      |                 ~~~~^~~~~
xoranges.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
xoranges.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d%d%d", &n, &i, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 7096 KB Output is correct
2 Correct 101 ms 7172 KB Output is correct
3 Correct 108 ms 7140 KB Output is correct
4 Correct 95 ms 7080 KB Output is correct
5 Correct 93 ms 7060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 102 ms 7096 KB Output is correct
16 Correct 101 ms 7172 KB Output is correct
17 Correct 108 ms 7140 KB Output is correct
18 Correct 95 ms 7080 KB Output is correct
19 Correct 93 ms 7060 KB Output is correct
20 Correct 96 ms 6520 KB Output is correct
21 Correct 87 ms 6556 KB Output is correct
22 Correct 98 ms 6456 KB Output is correct
23 Correct 94 ms 7084 KB Output is correct
24 Correct 97 ms 6980 KB Output is correct