답안 #963642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963642 2024-04-15T12:16:02 Z vladburac Topovi (COCI15_topovi) C++17
120 / 120
915 ms 33788 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
using ll = long long;
const int NMAX = 5e5;
const int VALMAX = 1e6;
const int LOGMAX = 18;
const int INF = 1e9;
const int MOD = 998244353;
mt19937 rnd( chrono::steady_clock::now().time_since_epoch().count() );

/*
#ifndef HOME
  ifstream fin( "regate.in" );
  ofstream fout( "regate.out" );
  #define cin fin
  #define cout fout
#endif // HOME
*/

map<pii, int> power;
map<int, int> l_xor, fCol;
map<int, int> c_xor, fLin;

ll ans = 0;
int n;
void upd( int lin, int col, int put ) {
  ans -= n - fCol[l_xor[lin]];
  ans -= n - fLin[c_xor[col]];
  if( l_xor[lin] ^ c_xor[col] )
    ans++;

  fLin[l_xor[lin]]--;
  l_xor[lin] ^= put;
  fLin[l_xor[lin]]++;

  fCol[c_xor[col]]--;
  c_xor[col] ^= put;
  fCol[c_xor[col]]++;

  ans += n - fCol[l_xor[lin]];
  ans += n - fLin[c_xor[col]];
  if( l_xor[lin] ^ c_xor[col] )
    ans--;
  power[{lin,col}] ^= put;
}
void solve() {
  int k, p, i, lin, col, put, lin1, col1, lin2, col2;
  cin >> n >> k >> p;
  fLin[0] = n, fCol[0] = n;
  for( i = 0; i < k; i++ ) {
    cin >> lin >> col >> put;
    upd( lin, col, put );
  }
  for( i = 0; i < p; i++ ) {
    cin >> lin1 >> col1 >> lin2 >> col2;
    int aux = power[{lin1,col1}];
    upd( lin1, col1, aux );
    upd( lin2, col2, aux );
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio( false );
  cin.tie( NULL );
  cout.tie( NULL );
  int t = 1;
  //cin >> t;
  while( t-- ) {
    solve();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 94 ms 5448 KB Output is correct
7 Correct 78 ms 4752 KB Output is correct
8 Correct 58 ms 3924 KB Output is correct
9 Correct 68 ms 3924 KB Output is correct
10 Correct 66 ms 4176 KB Output is correct
11 Correct 880 ms 33580 KB Output is correct
12 Correct 915 ms 33404 KB Output is correct
13 Correct 852 ms 33588 KB Output is correct
14 Correct 886 ms 33596 KB Output is correct
15 Correct 893 ms 33596 KB Output is correct
16 Correct 835 ms 33600 KB Output is correct
17 Correct 907 ms 33788 KB Output is correct
18 Correct 875 ms 33752 KB Output is correct
19 Correct 879 ms 33356 KB Output is correct
20 Correct 889 ms 33372 KB Output is correct