Submission #644917

# Submission time Handle Problem Language Result Execution time Memory
644917 2022-09-25T13:39:25 Z BackNoob Topovi (COCI15_topovi) C++14
120 / 120
1430 ms 35164 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
}
 
struct item{
    int r1, c1, r2, c2;
} query[mxN];

int n;
int k;
int p;
map<int, int> row;
map<int, int> col;
map<int, int> cntrow;
map<int, int> cntcol;
map<pair<int, int>, int> val;
int timer = 0;
ll res = 0;
 
void del(int r, int c)
{
    if(row[r] == 0) res -= (n - sz(col));
    res -= cntcol[row[r]];

    if(col[c] == 0) res -= (n - sz(row));
    res -= cntrow[col[c]];

    if(row[r] == col[c]) ++res;

    cntrow[row[r]]--;
    cntcol[col[c]]--;
    row[r] ^= val[{r, c}];
    col[c] ^= val[{r, c}];
    cntrow[row[r]]++;
    cntcol[col[c]]++;
    val[{r, c}] = 0;

    if(row[r] == 0) res += (n - sz(col));
    res += cntcol[row[r]];

    if(col[c] == 0) res += (n - sz(row));
    res += cntrow[col[c]];

    if(row[r] == col[c]) --res;
}

void add(int r, int c)
{
    if(row[r] == 0) res -= (n - sz(col));
    res -= cntcol[row[r]];

    if(col[c] == 0) res -= (n - sz(row));
    res -= cntrow[col[c]];

    if(row[r] == col[c]) ++res;

    cntrow[row[r]]--;
    cntcol[col[c]]--;
    row[r] ^= val[{r, c}];
    col[c] ^= val[{r, c}];
    cntrow[row[r]]++;
    cntcol[col[c]]++;

    if(row[r] == 0) res += (n - sz(col));
    res += cntcol[row[r]];

    if(col[c] == 0) res += (n - sz(row));
    res += cntrow[col[c]];

    if(row[r] == col[c]) --res;
}    


void solve()
{
    cin >> n >> k >> p;

    for(int i = 1; i <= k; i++) {
        int r, c, x;
        cin >> r >> c >> x;
        row[r] ^= x;
        col[c] ^= x;
        val[{r, c}] = x;
    }

    for(int i = 1; i <= p; i++) {
        cin >> query[i].r1 >> query[i].c1 >> query[i].r2 >> query[i].c2;
        row[query[i].r1] ^= 0;
        row[query[i].r2] ^= 0;
        col[query[i].c1] ^= 0;
        col[query[i].c2] ^= 0;
    }

    res = 1LL * (n - sz(row)) * (n - sz(col));


    for(auto it : col) cntcol[it.se]++;
    for(auto it : row) cntrow[it.se]++;


    for(auto it : row) {
        if(it.se == 0) res += (n - sz(col));
        res += cntcol[it.se];
    }

    for(auto it : col) {
        if(it.se == 0) res += (n - sz(row));
    }

    for(int i = 1; i <= p; i++) {
        int r1, c1, r2, c2;
        r1 = query[i].r1;
        c1 = query[i].c1;
        r2 = query[i].r2;
        c2 = query[i].c2;


        val[{r2, c2}] = val[{r1, c1}];
        del(r1, c1);
        add(r2, c2);
        cout << 1LL * n * n - res << endl;
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 155 ms 5600 KB Output is correct
7 Correct 102 ms 4856 KB Output is correct
8 Correct 90 ms 4044 KB Output is correct
9 Correct 83 ms 4192 KB Output is correct
10 Correct 99 ms 4428 KB Output is correct
11 Correct 1430 ms 34944 KB Output is correct
12 Correct 1384 ms 35036 KB Output is correct
13 Correct 1406 ms 34972 KB Output is correct
14 Correct 1361 ms 35036 KB Output is correct
15 Correct 1408 ms 35068 KB Output is correct
16 Correct 1360 ms 35036 KB Output is correct
17 Correct 1332 ms 35164 KB Output is correct
18 Correct 1372 ms 34968 KB Output is correct
19 Correct 1380 ms 35132 KB Output is correct
20 Correct 1374 ms 35048 KB Output is correct