Submission #489700

# Submission time Handle Problem Language Result Execution time Memory
489700 2021-11-24T01:44:08 Z Killer2501 Topovi (COCI15_topovi) C++14
120 / 120
1091 ms 53096 KB
#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

topovi.cpp: In function 'int main()':
topovi.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 135 ms 11904 KB Output is correct
7 Correct 93 ms 11196 KB Output is correct
8 Correct 77 ms 10096 KB Output is correct
9 Correct 80 ms 10228 KB Output is correct
10 Correct 90 ms 10364 KB Output is correct
11 Correct 1091 ms 52916 KB Output is correct
12 Correct 1069 ms 52860 KB Output is correct
13 Correct 1069 ms 52876 KB Output is correct
14 Correct 1058 ms 52836 KB Output is correct
15 Correct 1054 ms 52804 KB Output is correct
16 Correct 1086 ms 53096 KB Output is correct
17 Correct 1069 ms 52752 KB Output is correct
18 Correct 1082 ms 52868 KB Output is correct
19 Correct 1063 ms 52744 KB Output is correct
20 Correct 1070 ms 52804 KB Output is correct