답안 #942428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942428 2024-03-10T16:03:03 Z LOLOLO I want to be the very best too! (NOI17_pokemonmaster) C++17
71 / 100
5000 ms 23620 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 = 340;
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;
}
 
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);

    if (sz(mp[a]) < sz(mp[b]))
        swap(mp[a], mp[b]);
    
    sz[a] += sz[b];
    p[b] = a;
 
    for (auto x : mp[b]) {
        mp[a][x.f] += x.s;
    }
}
 
vector <vector <int>> action;
 
void upd(int c, int x) {
    c = get(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) {
            mp[t[0]].erase(t[1]);
        } else {
            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)
                mp[j][P[j]]++;
 
            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] = sz(mp[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 33 ms 15888 KB Output is correct
2 Correct 44 ms 16392 KB Output is correct
3 Correct 44 ms 16656 KB Output is correct
4 Correct 32 ms 16484 KB Output is correct
5 Correct 33 ms 16524 KB Output is correct
6 Correct 38 ms 16204 KB Output is correct
7 Correct 25 ms 16564 KB Output is correct
8 Correct 31 ms 16368 KB Output is correct
9 Correct 39 ms 16400 KB Output is correct
10 Correct 46 ms 16856 KB Output is correct
11 Correct 34 ms 16388 KB Output is correct
12 Correct 58 ms 17412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 15888 KB Output is correct
2 Correct 20 ms 15888 KB Output is correct
3 Correct 23 ms 16144 KB Output is correct
4 Correct 22 ms 17932 KB Output is correct
5 Correct 32 ms 18368 KB Output is correct
6 Correct 25 ms 18440 KB Output is correct
7 Correct 31 ms 18632 KB Output is correct
8 Correct 40 ms 20176 KB Output is correct
9 Correct 47 ms 18696 KB Output is correct
10 Correct 55 ms 22020 KB Output is correct
11 Correct 48 ms 20736 KB Output is correct
12 Correct 59 ms 23300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 860 ms 17376 KB Output is correct
2 Correct 1457 ms 17648 KB Output is correct
3 Correct 1141 ms 18436 KB Output is correct
4 Correct 1127 ms 19632 KB Output is correct
5 Correct 1391 ms 19604 KB Output is correct
6 Correct 1054 ms 18276 KB Output is correct
7 Correct 3219 ms 20512 KB Output is correct
8 Correct 2532 ms 20516 KB Output is correct
9 Correct 3235 ms 21268 KB Output is correct
10 Correct 2940 ms 20524 KB Output is correct
11 Correct 2924 ms 20516 KB Output is correct
12 Correct 2865 ms 20492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 15888 KB Output is correct
2 Correct 44 ms 16392 KB Output is correct
3 Correct 44 ms 16656 KB Output is correct
4 Correct 32 ms 16484 KB Output is correct
5 Correct 33 ms 16524 KB Output is correct
6 Correct 38 ms 16204 KB Output is correct
7 Correct 25 ms 16564 KB Output is correct
8 Correct 31 ms 16368 KB Output is correct
9 Correct 39 ms 16400 KB Output is correct
10 Correct 46 ms 16856 KB Output is correct
11 Correct 34 ms 16388 KB Output is correct
12 Correct 58 ms 17412 KB Output is correct
13 Correct 939 ms 17248 KB Output is correct
14 Correct 2051 ms 17620 KB Output is correct
15 Correct 3260 ms 18540 KB Output is correct
16 Correct 1232 ms 18520 KB Output is correct
17 Correct 1977 ms 17688 KB Output is correct
18 Correct 2443 ms 17616 KB Output is correct
19 Correct 1087 ms 17608 KB Output is correct
20 Correct 1800 ms 17608 KB Output is correct
21 Correct 1282 ms 17604 KB Output is correct
22 Correct 3614 ms 17848 KB Output is correct
23 Correct 2225 ms 17624 KB Output is correct
24 Correct 4907 ms 18700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 15888 KB Output is correct
2 Correct 44 ms 16392 KB Output is correct
3 Correct 44 ms 16656 KB Output is correct
4 Correct 32 ms 16484 KB Output is correct
5 Correct 33 ms 16524 KB Output is correct
6 Correct 38 ms 16204 KB Output is correct
7 Correct 25 ms 16564 KB Output is correct
8 Correct 31 ms 16368 KB Output is correct
9 Correct 39 ms 16400 KB Output is correct
10 Correct 46 ms 16856 KB Output is correct
11 Correct 34 ms 16388 KB Output is correct
12 Correct 58 ms 17412 KB Output is correct
13 Correct 19 ms 15888 KB Output is correct
14 Correct 20 ms 15888 KB Output is correct
15 Correct 23 ms 16144 KB Output is correct
16 Correct 22 ms 17932 KB Output is correct
17 Correct 32 ms 18368 KB Output is correct
18 Correct 25 ms 18440 KB Output is correct
19 Correct 31 ms 18632 KB Output is correct
20 Correct 40 ms 20176 KB Output is correct
21 Correct 47 ms 18696 KB Output is correct
22 Correct 55 ms 22020 KB Output is correct
23 Correct 48 ms 20736 KB Output is correct
24 Correct 59 ms 23300 KB Output is correct
25 Correct 860 ms 17376 KB Output is correct
26 Correct 1457 ms 17648 KB Output is correct
27 Correct 1141 ms 18436 KB Output is correct
28 Correct 1127 ms 19632 KB Output is correct
29 Correct 1391 ms 19604 KB Output is correct
30 Correct 1054 ms 18276 KB Output is correct
31 Correct 3219 ms 20512 KB Output is correct
32 Correct 2532 ms 20516 KB Output is correct
33 Correct 3235 ms 21268 KB Output is correct
34 Correct 2940 ms 20524 KB Output is correct
35 Correct 2924 ms 20516 KB Output is correct
36 Correct 2865 ms 20492 KB Output is correct
37 Correct 939 ms 17248 KB Output is correct
38 Correct 2051 ms 17620 KB Output is correct
39 Correct 3260 ms 18540 KB Output is correct
40 Correct 1232 ms 18520 KB Output is correct
41 Correct 1977 ms 17688 KB Output is correct
42 Correct 2443 ms 17616 KB Output is correct
43 Correct 1087 ms 17608 KB Output is correct
44 Correct 1800 ms 17608 KB Output is correct
45 Correct 1282 ms 17604 KB Output is correct
46 Correct 3614 ms 17848 KB Output is correct
47 Correct 2225 ms 17624 KB Output is correct
48 Correct 4907 ms 18700 KB Output is correct
49 Correct 931 ms 17248 KB Output is correct
50 Correct 2135 ms 17704 KB Output is correct
51 Correct 3306 ms 18624 KB Output is correct
52 Correct 1381 ms 19624 KB Output is correct
53 Correct 2238 ms 20032 KB Output is correct
54 Correct 2395 ms 19080 KB Output is correct
55 Correct 2238 ms 20292 KB Output is correct
56 Correct 4296 ms 21696 KB Output is correct
57 Correct 2478 ms 20536 KB Output is correct
58 Execution timed out 5063 ms 23620 KB Time limit exceeded
59 Halted 0 ms 0 KB -