답안 #907473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
907473 2024-01-15T17:18:33 Z LOLOLO I want to be the very best too! (NOI17_pokemonmaster) C++17
71 / 100
5000 ms 35252 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int M = 1e5 + 100;
const int N = M;
const int SZ = 1000;
int t[N], x[N], l[N], r[N], n, m, change[M], L[M], P[M], sz[N], y[N], p[N], C[N], ans[N];
vector <pair <int, int>> save[M];

int cov(int a, int b) {
    return (a - 1) * m + b;
}

int get(int a) {
    return p[a] ? get(p[a]) : a;
}

int cc[N];
unordered_map <int, int> mp[N];

void unite(int a, int b) {
    a = get(a), b = get(b);
    if (a == b)
        return;

    if (sz[a] < sz[b])
        swap(a, b);

    sz[a] += sz[b];
    p[b] = a;

    for (auto x : mp[b]) {
        if (mp[a][x.f] == 0 && x.s)
            cc[a]++;
        mp[a][x.f] += x.s;
    }
}

vector <vector <int>> action;

void upd(int c, int x) {
    c = get(c);

    if (mp[c][x] == 0)
        cc[c]++;

    action.pb({c, x, mp[c][x]});
    mp[c][x]++;
}

void rollback() {
    while (sz(action)) {
        auto t = action.back();
        action.pop_back();
        if (t[2] == 0) {
            cc[t[0]]--;
        }

        mp[t[0]][t[1]] = t[2];
    }
}

ll solve() {
    mem(L, 0x3f);
    mem(P, 0x3f);

    int q;
    cin >> n >> m >> q;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> L[cov(i, j)];

    vector <vector <int>> edge;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i < n)
                edge.pb({max(L[cov(i + 1, j)], L[cov(i, j)]), cov(i + 1, j), cov(i, j)});

            if (j < m)
                edge.pb({max(L[cov(i, j + 1)], L[cov(i, j)]), cov(i, j + 1), cov(i, j)});
        }
    }

    sort(all(edge));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> P[cov(i, j)];

    for (int i = 1; i <= q; i++) {
        cin >> t[i] >> y[i] >> x[i] >> r[i];
    }

    for (int i = 1; i <= q; i += SZ) {
        int X = i, Y = min(q, i + SZ - 1);
        vector <int> ask, up;
        for (int j = X; j <= Y; j++) {
            if (t[j] == 2) {
                ask.pb(j);
            } else {
                up.pb(j);
                change[cov(x[j], y[j])] = 1;
            }
        }

        for (int j = X; j <= Y; j++) {
            if (t[j] == 1) {
                P[cov(x[j], y[j])] = r[j];
            } else {
                save[j - X].clear();
                for (auto t : up) {
                    save[j - X].pb({cov(x[t], y[t]), P[cov(x[t], y[t])]});
                }
            }
        }

        sort(all(ask), [&](int a, int b) { return r[a] < r[b]; });
        for (int j = 1; j <= n * m; j++) {
            mp[j].clear();
            if (change[j] == 0) {
                cc[j] = 1;
                mp[j][P[j]]++;
            } else {
                cc[j] = 0;
            }

            sz[j] = 1;
            p[j] = 0;
        }

        int j = 0;
        for (auto id : ask) {
            while (j < sz(edge) && r[id] >= edge[j][0]) {
                unite(edge[j][1], edge[j][2]);
                j++;
            }

            for (auto t : save[id - X]) {
                upd(t.f, t.s);
            }

            if (r[id] >= L[cov(x[id], y[id])])
                ans[id] = cc[get(cov(x[id], y[id]))];

            rollback();
        }

        for (auto id : up)
            change[cov(x[id], y[id])] = 0;
    }

    for (int i = 1; i <= q; i++) {
        if (t[i] == 2) {
            cout << ans[i] << "\n";
        }
    }

    return 0;
}

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

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
        //cout << solve() << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 23568 KB Output is correct
2 Correct 45 ms 24752 KB Output is correct
3 Correct 43 ms 24336 KB Output is correct
4 Correct 37 ms 24144 KB Output is correct
5 Correct 45 ms 24584 KB Output is correct
6 Correct 31 ms 23824 KB Output is correct
7 Correct 42 ms 24564 KB Output is correct
8 Correct 49 ms 24592 KB Output is correct
9 Correct 50 ms 24592 KB Output is correct
10 Correct 50 ms 25164 KB Output is correct
11 Correct 50 ms 24592 KB Output is correct
12 Correct 52 ms 25340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 22596 KB Output is correct
2 Correct 26 ms 22800 KB Output is correct
3 Correct 31 ms 23048 KB Output is correct
4 Correct 29 ms 24020 KB Output is correct
5 Correct 29 ms 24588 KB Output is correct
6 Correct 32 ms 23816 KB Output is correct
7 Correct 46 ms 25280 KB Output is correct
8 Correct 55 ms 26376 KB Output is correct
9 Correct 56 ms 25612 KB Output is correct
10 Correct 89 ms 28376 KB Output is correct
11 Correct 60 ms 27528 KB Output is correct
12 Correct 73 ms 29356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 812 ms 24320 KB Output is correct
2 Correct 2467 ms 31884 KB Output is correct
3 Correct 1666 ms 31316 KB Output is correct
4 Correct 1705 ms 32572 KB Output is correct
5 Correct 2521 ms 34000 KB Output is correct
6 Correct 806 ms 25272 KB Output is correct
7 Correct 3696 ms 34800 KB Output is correct
8 Correct 3797 ms 34660 KB Output is correct
9 Correct 3938 ms 34336 KB Output is correct
10 Correct 3943 ms 34820 KB Output is correct
11 Correct 4684 ms 34504 KB Output is correct
12 Correct 4446 ms 34552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 23568 KB Output is correct
2 Correct 45 ms 24752 KB Output is correct
3 Correct 43 ms 24336 KB Output is correct
4 Correct 37 ms 24144 KB Output is correct
5 Correct 45 ms 24584 KB Output is correct
6 Correct 31 ms 23824 KB Output is correct
7 Correct 42 ms 24564 KB Output is correct
8 Correct 49 ms 24592 KB Output is correct
9 Correct 50 ms 24592 KB Output is correct
10 Correct 50 ms 25164 KB Output is correct
11 Correct 50 ms 24592 KB Output is correct
12 Correct 52 ms 25340 KB Output is correct
13 Correct 889 ms 24200 KB Output is correct
14 Correct 3351 ms 31692 KB Output is correct
15 Correct 2525 ms 31532 KB Output is correct
16 Correct 2387 ms 31420 KB Output is correct
17 Correct 3285 ms 31648 KB Output is correct
18 Correct 956 ms 24836 KB Output is correct
19 Correct 2594 ms 32020 KB Output is correct
20 Correct 3251 ms 31708 KB Output is correct
21 Correct 2764 ms 31768 KB Output is correct
22 Correct 3693 ms 31760 KB Output is correct
23 Correct 3124 ms 31552 KB Output is correct
24 Correct 3399 ms 32692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 23568 KB Output is correct
2 Correct 45 ms 24752 KB Output is correct
3 Correct 43 ms 24336 KB Output is correct
4 Correct 37 ms 24144 KB Output is correct
5 Correct 45 ms 24584 KB Output is correct
6 Correct 31 ms 23824 KB Output is correct
7 Correct 42 ms 24564 KB Output is correct
8 Correct 49 ms 24592 KB Output is correct
9 Correct 50 ms 24592 KB Output is correct
10 Correct 50 ms 25164 KB Output is correct
11 Correct 50 ms 24592 KB Output is correct
12 Correct 52 ms 25340 KB Output is correct
13 Correct 26 ms 22596 KB Output is correct
14 Correct 26 ms 22800 KB Output is correct
15 Correct 31 ms 23048 KB Output is correct
16 Correct 29 ms 24020 KB Output is correct
17 Correct 29 ms 24588 KB Output is correct
18 Correct 32 ms 23816 KB Output is correct
19 Correct 46 ms 25280 KB Output is correct
20 Correct 55 ms 26376 KB Output is correct
21 Correct 56 ms 25612 KB Output is correct
22 Correct 89 ms 28376 KB Output is correct
23 Correct 60 ms 27528 KB Output is correct
24 Correct 73 ms 29356 KB Output is correct
25 Correct 812 ms 24320 KB Output is correct
26 Correct 2467 ms 31884 KB Output is correct
27 Correct 1666 ms 31316 KB Output is correct
28 Correct 1705 ms 32572 KB Output is correct
29 Correct 2521 ms 34000 KB Output is correct
30 Correct 806 ms 25272 KB Output is correct
31 Correct 3696 ms 34800 KB Output is correct
32 Correct 3797 ms 34660 KB Output is correct
33 Correct 3938 ms 34336 KB Output is correct
34 Correct 3943 ms 34820 KB Output is correct
35 Correct 4684 ms 34504 KB Output is correct
36 Correct 4446 ms 34552 KB Output is correct
37 Correct 889 ms 24200 KB Output is correct
38 Correct 3351 ms 31692 KB Output is correct
39 Correct 2525 ms 31532 KB Output is correct
40 Correct 2387 ms 31420 KB Output is correct
41 Correct 3285 ms 31648 KB Output is correct
42 Correct 956 ms 24836 KB Output is correct
43 Correct 2594 ms 32020 KB Output is correct
44 Correct 3251 ms 31708 KB Output is correct
45 Correct 2764 ms 31768 KB Output is correct
46 Correct 3693 ms 31760 KB Output is correct
47 Correct 3124 ms 31552 KB Output is correct
48 Correct 3399 ms 32692 KB Output is correct
49 Correct 942 ms 24236 KB Output is correct
50 Correct 3229 ms 31800 KB Output is correct
51 Correct 2487 ms 31804 KB Output is correct
52 Correct 1948 ms 32572 KB Output is correct
53 Correct 3087 ms 33116 KB Output is correct
54 Correct 1111 ms 25804 KB Output is correct
55 Correct 3831 ms 34900 KB Output is correct
56 Execution timed out 5052 ms 35252 KB Time limit exceeded
57 Halted 0 ms 0 KB -