Submission #43198

#TimeUsernameProblemLanguageResultExecution timeMemory
43198baactree즐거운 사진 수집 (JOI13_collecting)C++14
100 / 100
2528 ms44520 KiB
#include <bits/stdc++.h> using namespace std; int n, q; int r[21], c[21]; int ro[1 << 20], co[1 << 20]; int rs[21][1 << 20], cs[21][1 << 20]; int main() { scanf("%d%d", &n, &q); long long cnt = 0; for (int i = 1; i <= n; i++) r[i] = c[i] = 1 << (n - i); while (q--) { int a, b; scanf("%d%d", &a, &b); b--; if (a) { //col for (int i = 1, d = 2; i <= n; i++,d<<=1) { int pre = rs[i][b / d]; int now = 0; if (pre == 0)now = 1; else if (pre == d)now = d - 1; else if (co[b])now = pre - 1; else now = pre + 1; rs[i][b / d] = now; pre %= d; now %= d; if (!pre)c[i]--; if (!now)c[i]++; long long k = 0; if (pre == 0)k = 1; else if (now == 0)k = -1; cnt += r[i] * k; } co[b] ^= 1; } else { //col for (int i = 1, d = 2; i <= n; i++, d <<= 1) { int pre = cs[i][b / d]; int now = 0; if (pre == 0)now = 1; else if (pre == d)now = d - 1; else if (ro[b])now = pre - 1; else now = pre + 1; cs[i][b / d] = now; pre %= d; now %= d; if (!pre)r[i]--; if (!now)r[i]++; long long k = 0; if (pre == 0)k = 1; else if (now == 0)k = -1; cnt += c[i] * k; } ro[b] ^= 1; } printf("%lld\n", cnt * 4 + 1); } return 0; }

Compilation message (stderr)

collecting.cpp: In function 'int main()':
collecting.cpp:8:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
                       ^
collecting.cpp:14:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...