답안 #23193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23193 2017-05-04T11:45:36 Z model_code Topovi (COCI15_topovi) C++11
120 / 120
1639 ms 33576 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:29: 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:33: 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:41: 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 0 ms 2028 KB Output is correct
2 Correct 0 ms 2028 KB Output is correct
3 Correct 0 ms 2028 KB Output is correct
4 Correct 0 ms 2028 KB Output is correct
5 Correct 0 ms 2028 KB Output is correct
6 Correct 163 ms 6780 KB Output is correct
7 Correct 136 ms 6384 KB Output is correct
8 Correct 106 ms 5592 KB Output is correct
9 Correct 106 ms 5592 KB Output is correct
10 Correct 129 ms 5724 KB Output is correct
11 Correct 1569 ms 33576 KB Output is correct
12 Correct 1566 ms 33576 KB Output is correct
13 Correct 1586 ms 33576 KB Output is correct
14 Correct 1639 ms 33576 KB Output is correct
15 Correct 1586 ms 33576 KB Output is correct
16 Correct 1573 ms 33576 KB Output is correct
17 Correct 1599 ms 33576 KB Output is correct
18 Correct 1593 ms 33576 KB Output is correct
19 Correct 1396 ms 33576 KB Output is correct
20 Correct 1593 ms 33576 KB Output is correct