# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489700 | Killer2501 | Topovi (COCI15_topovi) | C++14 | 1091 ms | 53096 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 pll pair<int, int>
#define task "test"
#define fi first
#define se second
#define pb push_back
using namespace std;
using ll = long long;
const int N = 2e5+15;
const ll mod = 1e9+7;
const ll base = 311;
const ll inf = 1e9;
ll m, n, t, k,ans, tong, a[N], b[N], d[N];
vector<ll> adj[N], kq, gr;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
string s, p;
map<ll, ll> r, c, vr, vc;
map<pll, ll> mp;
void add(ll x, ll y)
{
++vr[r[x]];
++vc[c[y]];
ans += n-vr[c[y]];
ans += n-vc[r[x]];
if(r[x] != c[y])ans -= 2;
if((r[x]^c[y]^mp[{x, y}]) > 0)++ans;
}
void del(ll x, ll y)
{
ans -= n-vr[c[y]];
ans -= n-vc[r[x]];
--vr[r[x]];
--vc[c[y]];
if(r[x] != c[y])ans += 2;
if((r[x]^c[y]^mp[{x, y}]) > 0)--ans;
}
inline void sol()
{
cin >> n >> k >> m;
for(int i = 1; i <= k; i ++)
{
cin >> a[i] >> b[i] >> d[i];
r[a[i]] ^= d[i];
c[b[i]] ^= d[i];
mp[{a[i], b[i]}] = d[i];
}
for(pll x: r)++vr[x.se];
vr[0] += n-r.size();
for(pll x: c)++vc[x.se];
vc[0] += n-c.size();
for(pll x: vr)
{
//cout << x.fi <<" "<<x.se<<" "<<vc[x.fi] << '\n';
ans += x.se*(n - vc[x.fi]);
}
//cout << ans << '\n';
//cout << ans << '\n';
while(m -- > 0)
{
ll x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
del(x1, y1);
r[x1] ^= mp[{x1, y1}];
c[y1] ^= mp[{x1, y1}];
add(x1, y1);
del(x2, y2);
r[x2] ^= mp[{x1, y1}];
c[y2] ^= mp[{x1, y1}];
add(x2, y2);
mp[{x2, y2}] = mp[{x1, y1}];
cout << ans << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
x + y - 2 - a =
y - x =
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |