답안 #230570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230570 2020-05-10T13:07:13 Z soroush Topovi (COCI15_topovi) C++14
120 / 120
1326 ms 33740 KB
#include <cstdio>
#include <iostream>
#include <map>

using namespace std;

int n, k, q;
long long sol;
map <int, int> rcnt, ccnt;
map <int, int> rxor, cxor;
map <pair<int, int>, int> rook;

void moveRook(int r, int c, int val) {
  sol -= n - ccnt[rxor[r]];
  sol -= n - rcnt[cxor[c]];
  if (rxor[r] != cxor[c])
    sol += 1;

  --rcnt[rxor[r]];
  rxor[r] ^= val;
  ++rcnt[rxor[r]];

  --ccnt[cxor[c]];
  cxor[c] ^= val;
  ++ccnt[cxor[c]];

  sol += n - ccnt[rxor[r]];
  sol += n - rcnt[cxor[c]];
  if (rxor[r] != cxor[c])
    sol -= 1;

  rook[make_pair(r, c)] ^= val;
}

void init(void) {
  scanf("%d %d %d",&n,&k,&q);
  rcnt[0] = ccnt[0] = n;
  for (int i = 0; i < k; ++i) {
    int r, c, val;
    scanf("%d %d %d",&r,&c,&val);
    --r;
    --c;
    moveRook(r, c, val);
  }
}

void solve(void) {
  while (q-- > 0) {
    int r1, c1, r2, c2;
    scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
    --r1; --c1;
    --r2; --c2;
    int rookValue = rook[make_pair(r1, c1)];
    moveRook(r1, c1, rookValue);
    moveRook(r2, c2, rookValue);
    printf("%lld\n",sol);
  }
}

int main(void) {
  init();
  solve();
  return 0;
}

Compilation message

topovi.cpp: In function 'void init()':
topovi.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&n,&k,&q);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
topovi.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&r,&c,&val);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp: In function 'void solve()':
topovi.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 142 ms 5368 KB Output is correct
7 Correct 115 ms 4856 KB Output is correct
8 Correct 93 ms 3960 KB Output is correct
9 Correct 94 ms 3960 KB Output is correct
10 Correct 108 ms 4216 KB Output is correct
11 Correct 1298 ms 33580 KB Output is correct
12 Correct 1326 ms 33656 KB Output is correct
13 Correct 1280 ms 33528 KB Output is correct
14 Correct 1272 ms 33740 KB Output is correct
15 Correct 1268 ms 33724 KB Output is correct
16 Correct 1278 ms 33528 KB Output is correct
17 Correct 1286 ms 33528 KB Output is correct
18 Correct 1271 ms 33544 KB Output is correct
19 Correct 1270 ms 33656 KB Output is correct
20 Correct 1285 ms 33732 KB Output is correct