답안 #253368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253368 2020-07-27T19:04:10 Z Vimmer Topovi (COCI15_topovi) C++14
60 / 120
2000 ms 19580 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 10005
#define M ll(998244353)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 4> a4;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll ans;

map <pair <ll, ll>, ll> a;

unordered_map <ll, ll> valx, valy, row, col;

set <ll> se;

void de(ll t, bool ob)
{
    if (ob) valx[row[t]]--; else valy[col[t]]--;
}

void ad(ll t, bool ob)
{
    if (ob) valx[row[t]]++; else  valy[col[t]]++;
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, k, p;

    cin >> n >> k >> p;

    for (ll i = 0; i < k; i++)
    {
        ll x, y, val;

        cin >> x >> y >> val;

        row[x] ^= val;

        col[y] ^= val;

        a[{x, y}] = val;
    }

    valy[0] = valx[0] = n;

    for (auto it : col) {valy[0]--; valy[it.S]++;}

    for (auto it : row) {valx[0]--; valx[it.S]++;}

    for (auto it : valx) ans += it.S * valy[it.F];

    for (; p > 0; p--)
    {
        ll x1, x2, y1, y2;

        cin >> x1 >> y1 >> x2 >> y2;

        ll val = a[{x2, y2}] = a[{x1, y1}];

        for (auto it : valx) ans -= it.S * valy[it.F];

        de(x1, 1); de(x2, 1); de(y1, 0); de(y2, 0);

        row[x1] ^= val; col[y1] ^= val; row[x2] ^= val; col[y2] ^= val;

        ad(x1, 1); ad(x2, 1); ad(y1, 0); ad(y2, 0);

        for (auto it : valx) ans += it.S * valy[it.F];

        cout << n * n - ans << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 238 ms 5332 KB Output is correct
7 Correct 216 ms 4904 KB Output is correct
8 Correct 137 ms 3704 KB Output is correct
9 Correct 139 ms 3704 KB Output is correct
10 Correct 155 ms 3960 KB Output is correct
11 Execution timed out 2091 ms 19260 KB Time limit exceeded
12 Execution timed out 2085 ms 19416 KB Time limit exceeded
13 Execution timed out 2083 ms 19436 KB Time limit exceeded
14 Execution timed out 2083 ms 19380 KB Time limit exceeded
15 Execution timed out 2081 ms 19452 KB Time limit exceeded
16 Execution timed out 2088 ms 19328 KB Time limit exceeded
17 Execution timed out 2091 ms 19416 KB Time limit exceeded
18 Execution timed out 2089 ms 19580 KB Time limit exceeded
19 Execution timed out 2096 ms 19288 KB Time limit exceeded
20 Execution timed out 2082 ms 19104 KB Time limit exceeded