Submission #401514

# Submission time Handle Problem Language Result Execution time Memory
401514 2021-05-10T12:50:14 Z raid XORanges (eJOI19_xoranges) C++17
100 / 100
657 ms 13420 KB
#include <iostream>

using namespace std;

const int MAXN = 200002;
int v[MAXN], n;

struct segtree {
  int tree[4 * MAXN], m;
  
  void init( int dim ) {
	for ( int i = 0; i <= 4 * n; ++i ) {
      this -> tree[i] = 0;
	}
	this -> m = dim;
  }
  void update( int node, int l, int r, int x, int pos ) {
	if ( l == r ) {
      this -> tree[node] = x;
	  return;
	}
	int mid = (l + r) / 2;
	if ( pos <= mid ) {
      update( 2 * node, l, mid, x, pos );
	} else {
	  update( 2 * node + 1, mid + 1, r, x, pos );
	}
	this -> tree[node] = this -> tree[2 * node] ^ this -> tree[2 * node + 1];
  }
  int query( int node, int l, int r, int x, int y ) {
    int a = 0, b = 0;
	if ( x <= l && r <= y ) {
	  return this -> tree[node];
	}
	int mid = (l + r) / 2;
	if ( x <= mid ) {
      a = query( 2 * node, l, mid, x, y );
	}
	if ( y > mid ) {
      b = query( 2 * node + 1, mid + 1, r, x, y );
	}
	return a ^ b;
  }
  void update( int x, int pos ) {
	update( 1, 1, m, x, pos );
  } 
  int query( int x, int y ) {
    return query( 1, 1, m, x, y );
  }
};

int main() {
  int q, t, x, y;
  segtree odd, even;

  cin >> n >> q;
  for ( int i = 1; i <= n; ++i ) {
	cin >> v[i];
  }
  odd.init( ((n + 1) >> 1) );
  even.init( (n >> 1) );
  for ( int i = 1; i <= n; ++i ) {
    if ( i & 1 ) {
      odd.update( v[i], (i >> 1) + 1 );
	} else {
      even.update( v[i], (i >> 1) );
	}
  }
  while ( q-- ) {
    cin >> t >> x >> y;
    if ( t == 1 ) {
	  if ( x & 1 ) {
        odd.update( y, (x >> 1) + 1 );      
	  } else {
        even.update( y, (x >> 1) );
	  }
	} else {
	  if ( (y - x + 1) & 1 ) {
        if ( x & 1 ) {
		  cout << odd.query( (x >> 1) + 1, (y >> 1) + 1 ) << "\n";
		} else {
		  cout << even.query( (x >> 1), (y >> 1) ) << "\n";
		}
	  } else {
		cout << "0\n";
	  }
	}
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 12 ms 588 KB Output is correct
12 Correct 13 ms 588 KB Output is correct
13 Correct 15 ms 588 KB Output is correct
14 Correct 15 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 648 ms 13420 KB Output is correct
2 Correct 642 ms 13288 KB Output is correct
3 Correct 653 ms 13252 KB Output is correct
4 Correct 612 ms 13000 KB Output is correct
5 Correct 657 ms 13036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 12 ms 588 KB Output is correct
12 Correct 13 ms 588 KB Output is correct
13 Correct 15 ms 588 KB Output is correct
14 Correct 15 ms 620 KB Output is correct
15 Correct 648 ms 13420 KB Output is correct
16 Correct 642 ms 13288 KB Output is correct
17 Correct 653 ms 13252 KB Output is correct
18 Correct 612 ms 13000 KB Output is correct
19 Correct 657 ms 13036 KB Output is correct
20 Correct 497 ms 13084 KB Output is correct
21 Correct 496 ms 13124 KB Output is correct
22 Correct 497 ms 12984 KB Output is correct
23 Correct 628 ms 12948 KB Output is correct
24 Correct 598 ms 12964 KB Output is correct