# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
787322 |
2023-07-19T05:13:29 Z |
박영우(#10035) |
즐거운 사진 수집 (JOI13_collecting) |
C++17 |
|
977 ms |
44780 KB |
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 22
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 998244353
struct fenwick {
int N;
vector<int> tree;
fenwick(int N = 0) :N(N) { tree.resize(N + 1); }
void upd(int i, int x) { i++; while (i <= N) { tree[i] += x, i += i & -i; } }
int get(int i) { i++; int sum = 0; while (i) { sum += tree[i], i -= i & -i; } return sum; }
int get(int i, int j) { i++, j++; return get(j) - get(i - 1); }
};
int chk[2][1 << MAX];
int cnt[2][MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, Q;
cin >> N >> Q;
int i;
ll sum = 1;
for (i = 1; i <= N; i++) sum += 1ll << (i << 1);
fenwick fen[2];
fen[0] = fen[1] = fenwick(1 << N);
for (i = 0; i < N; i++) cnt[0][i] = cnt[1][i] = 1 << i;
while (Q--) {
int t, x;
cin >> t >> x;
x--;
if (chk[t][x]) fen[t].upd(x, -1);
else fen[t].upd(x, 1);
chk[t][x] ^= 1;
int l, r;
l = r = i;
for (i = 0; i < N; i++) {
l >>= i;
r = l | ((1 << i) - 1);
int res = fen[t].get(l, r);
if (!res) cnt[t][N - i - 1]--;
if (res == (1 << i)) cnt[t][N - i - 1]++;
}
ll ans = 0;
for (i = 0; i < N; i++) ans += cnt[0][i] * cnt[1][i];
cout << sum - 4 * ans << Ln;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
977 ms |
44780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |