# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371240 | Atill83 | Topovi (COCI15_topovi) | C++14 | 567 ms | 25292 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.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, k, p;
unordered_map<int, int> col, row, kc, kr;
map<pii, int> mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
#endif
cin>>n>>k>>p;
kc[0] = kr[0] = n;
for(int i = 0; i < k; i++){
int x, y, pow;
cin>>x>>y>>pow;
mp[{x, y}] = pow;
kc[col[y]]--;
kr[row[x]]--;
col[y] = (col[y] ^ pow);
row[x] = (row[x] ^ pow);
kc[col[y]]++;
kr[row[x]]++;
}
ll ans = 1LL * n * n;
for(auto u: kc){
ans -= 1LL * u.ss * kr[u.ff];
}
for(int i = 0; i < p; i++){
int x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
auto u = mp.find({x1, y1});
int pwer = (*u).ss;
mp.erase(u);
mp[{x2, y2}] = pwer;
int degR = row[x1], degC = col[y1];
ans += kc[degR];
kr[degR]--;
ans += kr[degC];
kc[degC]--;
row[x1] ^= pwer;
col[y1] ^= pwer;
ans -= kr[col[y1]];
kc[col[y1]]++;
ans -= kc[row[x1]];
kr[row[x1]]++;
degR = row[x2], degC = col[y2];
ans += kc[degR];
kr[degR]--;
ans += kr[degC];
kc[degC]--;
row[x2] ^= pwer;
col[y2] ^= pwer;
ans -= kr[col[y2]];
kc[col[y2]]++;
ans -= kc[row[x2]];
kr[row[x2]]++;
cout<<ans<<endl;
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |