답안 #237584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237584 2020-06-07T14:23:13 Z tb_03 XORanges (eJOI19_xoranges) C++14
100 / 100
745 ms 5752 KB
#include <iostream>
 
using namespace std;
typedef unsigned int ui;
 
int n, q;
ui oranges[200005];
ui st_par[400005];
ui st_impar[400005];
 
void update_par(int index)
{
  st_par[n + index] = oranges[index];
 
  for (int i = n + index; i > 1; i >>= 1)
    st_par[i >> 1] = st_par[i] ^ st_par[i ^ 1];
}
 
void update_impar(int index)
{
  st_impar[n + index] = oranges[index];
 
  for (int i = n + index; i > 1; i >>= 1)
    st_impar[i >> 1] = st_impar[i] ^ st_impar[i ^ 1];
}
 
ui query_par(int l, int r)
{
  ui res = 0;
 
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1)
  {
    if (l & 1)
      res ^= st_par[l++];
 
    if (r & 1)
      res ^= st_par[--r];
  }
 
  return res;
}
 
ui query_impar(int l, int r)
{
  ui res = 0;
 
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1)
  {
    if (l & 1)
      res ^= st_impar[l++];
 
    if (r & 1)
      res ^= st_impar[--r];
  }
 
  return res;
}
 
int main()
{
  cin >> n >> q;
 
  for (int i = 0; i < n; i++)
    cin >> oranges[i];
 
  for (int i = 0; i < n; i++)
    st_par[n + i] = (i % 2 == 0 ? oranges[i] : 0);
 
  for (int i = n - 1; i > 0; i--)
    st_par[i] = st_par[i << 1] ^ st_par[i << 1 | 1];
 
  for (int i = 0; i < n; i++)
    st_impar[n + i] = (i % 2 == 0 ? 0 : oranges[i]);
 
  for (int i = n - 1; i > 0; i--)
    st_impar[i] = st_impar[i << 1] ^ st_impar[i << 1 | 1];
 
  while (q--)
  {
    int aux;
    cin >> aux;
 
    if (aux == 1)
    {
      //rescan
      int index;
      cin >> index;
      cin >> oranges[index - 1];
 
      if ((index - 1) % 2 == 0)
        update_par(index - 1);
      else
        update_impar(index - 1);
    }
    else
    {
      //query
      int l, u;
      cin >> l >> u;
 
      if ((u - l + 1) % 2 == 0)
        cout << 0 << '\n';
      else if ((l - 1) % 2 == 0)
        cout << query_par(l - 1, u - 1) << '\n';
      else
        cout << query_impar(l - 1, u - 1) << '\n';
    }
  }
 
  cout.flush();
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 18 ms 512 KB Output is correct
12 Correct 17 ms 512 KB Output is correct
13 Correct 23 ms 512 KB Output is correct
14 Correct 22 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 735 ms 5496 KB Output is correct
2 Correct 735 ms 5512 KB Output is correct
3 Correct 745 ms 5496 KB Output is correct
4 Correct 728 ms 5752 KB Output is correct
5 Correct 719 ms 5588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 18 ms 512 KB Output is correct
12 Correct 17 ms 512 KB Output is correct
13 Correct 23 ms 512 KB Output is correct
14 Correct 22 ms 512 KB Output is correct
15 Correct 735 ms 5496 KB Output is correct
16 Correct 735 ms 5512 KB Output is correct
17 Correct 745 ms 5496 KB Output is correct
18 Correct 728 ms 5752 KB Output is correct
19 Correct 719 ms 5588 KB Output is correct
20 Correct 579 ms 4984 KB Output is correct
21 Correct 570 ms 4856 KB Output is correct
22 Correct 571 ms 4956 KB Output is correct
23 Correct 703 ms 5496 KB Output is correct
24 Correct 704 ms 5624 KB Output is correct