Submission #253224

# Submission time Handle Problem Language Result Execution time Memory
253224 2020-07-27T13:31:31 Z Sprdalo Topovi (COCI15_topovi) C++17
120 / 120
411 ms 53220 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

unordered_map<int, int> r, c, tr, tc;

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

unordered_map<pi, int, HASH> mapa;
void fast(){
    mapa.reserve(131072);
    mapa.max_load_factor(0.25);
    r.reserve(131072);
    r.max_load_factor(0.25);
    c.reserve(131072);
    c.max_load_factor(0.25);

    tr.reserve(131072);
    tr.max_load_factor(0.25);
    tc.reserve(131072);
    tc.max_load_factor(0.25);
}    

ll sol, n;    

void dodaj(int x, int y, int z){
    sol -= n -  tc[r[x]];
    sol -= n - tr[c[y]];

    if (r[x] != c[y])
        ++sol;

    if (tr[r[x]])
        --tr[r[x]];
    r[x] ^= z;
    ++tr[r[x]];

    if (tc[c[y]])
        --tc[c[y]];
    c[y] ^= z;
    ++tc[c[y]];

    sol += n - tc[r[x]];
    sol += n - tr[c[y]];
    if (r[x] != c[y])
        --sol;

    mapa[{x, y}] ^= z;
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    
    fast();

    int k, p;
    cin >> n >> k >> p;

    tr[0] = n;
    tc[0] = n;
    for (int i = 0; i < k; ++i){
        int x, y, z;
        cin >> x >> y >> z;
        dodaj(x, y, z);
    }

    for (int i = 0; i < p; ++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        int z = mapa[{x1, y1}];
        dodaj(x1, y1, z);
        dodaj(x2, y2, z);

        cout << sol << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5632 KB Output is correct
2 Correct 4 ms 5632 KB Output is correct
3 Correct 3 ms 5760 KB Output is correct
4 Correct 4 ms 5632 KB Output is correct
5 Correct 4 ms 5632 KB Output is correct
6 Correct 45 ms 9208 KB Output is correct
7 Correct 35 ms 8952 KB Output is correct
8 Correct 30 ms 8340 KB Output is correct
9 Correct 30 ms 8312 KB Output is correct
10 Correct 32 ms 8440 KB Output is correct
11 Correct 390 ms 53080 KB Output is correct
12 Correct 388 ms 53076 KB Output is correct
13 Correct 382 ms 53076 KB Output is correct
14 Correct 379 ms 53040 KB Output is correct
15 Correct 411 ms 53220 KB Output is correct
16 Correct 410 ms 53208 KB Output is correct
17 Correct 398 ms 53072 KB Output is correct
18 Correct 396 ms 53076 KB Output is correct
19 Correct 396 ms 53076 KB Output is correct
20 Correct 403 ms 53036 KB Output is correct