# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34032 | ToMoClone | 즐거운 사진 수집 (JOI13_collecting) | C++14 | 2716 ms | 181336 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.
/*input
3 2
0 1
0 2
2 3
0 1
1 2
0 3
*/
#include <stdio.h>
using namespace std;
int n, q, sumr[21][1 << 20], sumc[21][1 << 20], col[1 << 20], row[1 << 20], fullrow[21], fullcol[21];
long long ans = 1;
int main(){
scanf("%d%d", &n, &q);
for(int i = 0; i <= n; ++i)
fullrow[i] = fullcol[i] = (1 << (n - i));
while(q--){
int sign, num; scanf("%d%d", &sign, &num);
--num;
if(sign == 0){
int val = row[num] ? -1 : 1;
row[num] ^= 1;
for(int i = 0; i <= n; ++i){
// num -= num & (1 << i);
if(sumr[i][num] == 0 || sumr[i][num] == (1 << i)) ans += 4 * fullcol[i], --fullrow[i];
sumr[i][num] += val;
if(sumr[i][num] == 0 || sumr[i][num] == (1 << i)) ans -= 4 * fullcol[i], ++fullrow[i];
num -= num & (1 << i);
}
}
if(sign == 1){
int val = col[num] ? -1 : 1;
col[num] ^= 1;
for(int i = 0; i <= n; ++i){
// num -= num & (1 << i);
if(sumc[i][num] == 0 || sumc[i][num] == (1 << i)) ans += 4 * fullrow[i], --fullcol[i];
sumc[i][num] += val;
if(sumc[i][num] == 0 || sumc[i][num] == (1 << i)) ans -= 4 * fullrow[i], ++fullcol[i];
num -= num & (1 << i);
}
}
printf("%lld\n", ans);
}
}
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... |