제출 #1336172

#제출 시각아이디문제언어결과실행 시간메모리
1336172doantaolaaidiTopovi (COCI15_topovi)C++20
120 / 120
793 ms30536 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define AC "test"
#define foru(i, l, r) for (int i = (l); i <= (r); i++)
#define ford(i, l, r) for (int i = (l); i >= (r); i--)
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;

const ll inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const int base = 31;

void fastIO(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll mul(ll a, ll b){
    a%=mod;
    ll res = 0;
    while (b){
        if (b%2) res = (res + a)%mod;
        a = (a + a)%mod;
        b/=2;
    }
    return res;
}

ll Pow(ll a, ll b){
    ll ans = 1;
    while (b){
        if (b % 2) ans = mul(ans, a);
        a = mul(a, a);
        b/=2;
    }
    return ans;
}

map<ll, map<ll, ll>> val;
map<ll, ll> row_val, col_val;
map<ll, ll> cntR, cntC;
ll n, k, p, S;

void update_row(ll r, ll x) {
    ll old_v = row_val[r];
    ll new_v = old_v ^ x;
    S -= cntC[old_v];
    cntR[old_v]--;
    if (cntR[old_v] == 0) cntR.erase(old_v);
    row_val[r] = new_v;
    if (new_v == 0) row_val.erase(r);
    cntR[new_v]++;
    S += cntC[new_v];
}

void update_col(ll c, ll x) {
    ll old_v = col_val[c];
    ll new_v = old_v ^ x;
    S -= cntR[old_v];
    cntC[old_v]--;
    if (cntC[old_v] == 0) cntC.erase(old_v);
    col_val[c] = new_v;
    if (new_v == 0) col_val.erase(c);
    cntC[new_v]++;
    S += cntR[new_v];
}

void solve(){
    cin >> n >> k >> p;
    cntR[0] = n;
    cntC[0] = n;
    S = n * n;
    foru(i, 1, k){
        ll r, c, x;
        cin >> r >> c >> x;
        val[r][c] = x;
        update_row(r, x);
        update_col(c, x);
    }
    while (p--){
        ll r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        ll x = val[r1][c1];
        val[r1].erase(c1);
        if (val[r1].empty()) val.erase(r1);
        update_row(r1, x);
        update_col(c1, x);
        val[r2][c2] = x;
        update_row(r2, x);
        update_col(c2, x);
        cout << n * n - S << "\n";
    }
}

int main(){
    fastIO();
    if (fopen(AC".inp", "r")){
        freopen(AC".inp", "r", stdin);
        freopen(AC".out", "w", stdout);
    }
    solve();
}

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

topovi.cpp: In function 'int main()':
topovi.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(AC".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(AC".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...