# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43203 | baactree | 즐거운 사진 수집 (JOI13_collecting) | C++14 | 1551 ms | 44640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
namespace fio {
const int BSIZE = 1 << 17;
unsigned char buffer[BSIZE];
unsigned char *p = buffer + BSIZE;
inline unsigned char readChar() {
if (p == buffer + BSIZE) {
fread(buffer, 1, 1 << 17, stdin);
p = buffer;
}
return *p++;
}
int readInt() {
unsigned char c = readChar();
while (c<'-')c = readChar();
int ret = 0;
do {
ret = ret * 10 + c - '0';
c = readChar();
} while (c >= '-');
return ret;
}
}
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);
n = fio::readInt();
q = fio::readInt();
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);
a = fio::readInt();
b = fio::readInt();
b--;
if (a) {
//col
for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
int pre = cs[i][b / d];
int now = co[b] ? pre - 1 : pre + 1;
cs[i][b / d] = now;
int k = 0;
if (!(pre%d))c[i]--, k = 1;
if (!(now%d))c[i]++, k = -1;
cnt += r[i] * k;
}
co[b] ^= 1;
}
else {
//row
for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
int pre = rs[i][b / d];
int now = ro[b] ? pre - 1 : pre + 1;
rs[i][b / d] = now;
int k = 0;
if (!(pre%d))r[i]--, k = 1;
if (!(now%d))r[i]++, k = -1;
cnt += c[i] * k;
}
ro[b] ^= 1;
}
printf("%lld\n", cnt * 4 + 1);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |