Submission #963623

#TimeUsernameProblemLanguageResultExecution timeMemory
963623vladburacTopovi (COCI15_topovi)C++17
6 / 120
2102 ms51568 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<long long, long long> 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> line_xor, fCol; map<int, int> col_xor, fLine; ll ans = 0; int n; void upd( int lin, int col, int put ) { int oldx = line_xor[lin]; line_xor[lin] ^= put; int oldy = col_xor[col]; col_xor[col] ^= put; ans -= ( n - fCol[oldx] ); fCol[oldy]--, fCol[col_xor[col]]++; ans += ( n - fCol[line_xor[lin]] ); ans -= ( n - fLine[oldy] ); fLine[oldx]--, fLine[line_xor[lin]]++; ans += ( n - fLine[col_xor[col]] ); } void solve() { int k, p, i, lin, col, put, lin1, col1, lin2, col2; cin >> n >> k >> p; fLine[0] = n, fCol[0] = n; for( i = 0; i < n; i++ ) { cin >> lin >> col >> put; upd( lin, col, put ); power[{lin, col}] = put; } for( i = 0; i < p; i++ ) { cin >> lin1 >> col1 >> lin2 >> col2; upd( lin1, col1, power[{lin1,col1}] ); upd( lin2, col2, power[{lin1,col1}] ); swap( power[{lin1,col1}], power[{lin2,col2}] ); 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...