제출 #489700

#제출 시각아이디문제언어결과실행 시간메모리
489700Killer2501Topovi (COCI15_topovi)C++14
120 / 120
1091 ms53096 KiB
#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 =

*/

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...