답안 #1054109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054109 2024-08-12T06:31:53 Z juicy 즐거운 사진 수집 (JOI13_collecting) C++17
30 / 100
703 ms 61580 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 20;

int n, q;
int s[2][1 << N + 1], cnt[2][N];

void upd(int *s, int *cnt, int i, int id = 1, int l = 1, int r = 1 << n, int lvl = 0) {
  if (l == r) {
    s[id] ^= 1;
    return;
  }
  int md = (l + r) / 2;
  if (i <= md) {
    upd(s, cnt, i, id * 2, l, md, lvl + 1);
  } else {
    upd(s, cnt, i, id * 2 + 1, md + 1, r, lvl + 1);
  }
  if (~s[id]) {
    --cnt[lvl];
  }
  s[id] = s[id * 2] == s[id * 2 + 1] ? s[id * 2] : -1;
  if (~s[id]) {
    ++cnt[lvl];
  }
}

long long qry() {
  long long res = 0;
  for (int i = 0; i <= n; ++i) {
    res += (1LL << 2 * i) - (long long) cnt[0][i] * cnt[1][i];;
  }
  return res * 4 + 1;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> q;
  for (int i = 0; i <= n; ++i) {
    for (auto it : {0, 1}) {
      cnt[it][i] = 1 << i;
    } 
  }
  while (q--) {
    int t, x; cin >> t >> x;
    upd(s[t], cnt[t], x);
    cout << qry() << "\n";
  }
  return 0;
}

Compilation message

collecting.cpp:14:17: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   14 | int s[2][1 << N + 1], cnt[2][N];
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2516 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 703 ms 61580 KB Output isn't correct
2 Halted 0 ms 0 KB -