Submission #1193481

#TimeUsernameProblemLanguageResultExecution timeMemory
1193481InvMODTopovi (COCI15_topovi)C++17
120 / 120
822 ms39952 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pi pair<int,int>


int n, K, P, answer; map<pi, int> vrook;

map<int,int> vcol, vrow, ccol, crow;

void upd(int r, int c, int value){
    answer -= n - crow[vcol[r]];
    answer -= n - ccol[vrow[c]];
    answer += (vcol[r] == vrow[c]);

    --ccol[vcol[r]]; vcol[r] ^= value; ++ccol[vcol[r]];
    --crow[vrow[c]]; vrow[c] ^= value; ++crow[vrow[c]];

    answer += n - crow[vcol[r]];
    answer += n - ccol[vrow[c]];
    answer -= (vcol[r] == vrow[c]);

    vrook[pi(r, c)] ^= value;
}

void Main()
{
    cin >> n >> K >> P;

    crow[0] = n, ccol[0] = n;
    for(int i = 1; i <= K; i++){
        int r,c,X; cin >> r >> c >> X;

        upd(r, c, X);
    }

    for(int i = 1; i <= P; i++){
        int r,c; cin >> r >> c;
        int X = vrook[pi(r, c)];

        upd(r, c, X);
        cin >> r >> c;
        upd(r, c, X);
        cout << answer << "\n";
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    int t = 1; while(t--) Main();
    return 0;
}

Compilation message (stderr)

topovi.cpp: In function 'int32_t main()':
topovi.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
topovi.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...