Submission #98720

# Submission time Handle Problem Language Result Execution time Memory
98720 2019-02-25T09:15:30 Z win11905 Topovi (COCI15_topovi) C++11
120 / 120
1698 ms 33788 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};


class topovi {
private:
    int n, k, p;
    long sum = 0;
    map<int, int> fx, fy, vx, vy;
    map<pii, int> data;
public:
    void solve(istream& cin, ostream& cout) {
        cin >> n >> k >> p;
        fx[0] = fy[0] = n;
        for(int i = 0, x, y, v; i < k; ++i) {
            cin >> x >> y >> v;
            sum -= n - fy[vx[x]] + n - fx[vy[y]];
            fx[vx[x]]--, fy[vy[y]]--;
            data[pii(x, y)] = v;
            fx[vx[x] ^= v]++, fy[vy[y] ^= v]++;
            sum += n - fy[vx[x]] + n - fx[vy[y]];
        }
        for(int i = 0, x, y; i < p; ++i) {
            cin >> x >> y;
            sum -= n - fy[vx[x]] + n - fx[vy[y]];
            fx[vx[x]]--, fy[vy[y]]--;
            int v = data[pii(x, y)];
            fx[vx[x] ^= v]++, fy[vy[y] ^= v]++;
            sum += n - fy[vx[x]] + n - fx[vy[y]];
            cin >> x >> y;
            sum -= n - fy[vx[x]] + n - fx[vy[y]];
            fx[vx[x]]--, fy[vy[y]]--;
            data[pii(x, y)] = v;
            fx[vx[x] ^= v]++, fy[vy[y] ^= v]++;
            sum += n - fy[vx[x]] + n - fx[vy[y]];
            cout << sum << endl;
        }
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        topovi *obj = new topovi();
        obj->solve(in, out);
    }
};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 175 ms 5368 KB Output is correct
7 Correct 130 ms 4856 KB Output is correct
8 Correct 129 ms 3984 KB Output is correct
9 Correct 110 ms 4064 KB Output is correct
10 Correct 127 ms 4188 KB Output is correct
11 Correct 1573 ms 33556 KB Output is correct
12 Correct 1506 ms 33624 KB Output is correct
13 Correct 1605 ms 33620 KB Output is correct
14 Correct 1566 ms 33716 KB Output is correct
15 Correct 1698 ms 33708 KB Output is correct
16 Correct 1473 ms 33788 KB Output is correct
17 Correct 1579 ms 33548 KB Output is correct
18 Correct 1599 ms 33528 KB Output is correct
19 Correct 1578 ms 33756 KB Output is correct
20 Correct 1670 ms 33512 KB Output is correct