Submission #678870

# Submission time Handle Problem Language Result Execution time Memory
678870 2023-01-06T19:26:18 Z qwerasdfzxcl Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
835 ms 351736 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
constexpr int INF = 1e9+100;

struct Node{
    int l, r, x;
    Node(){}
    Node(int _l, int _r, int _x): l(_l), r(_r), x(_x) {}
};

struct PST{
    vector<Node> tree;
    vector<int> root;
    int sz;

    int cp(int x){
        tree.push_back(tree[x]);
        return (int)tree.size()-1;
    }
    void init(int n){
        sz = n;
        tree.emplace_back(0, 0, 0);
        root.push_back(0);
    }
    void update(int i, int l, int r, int p, int x){
        if (r<p || p<l) return;
        if (l==r) {tree[i].x += x; return;}

        int m = (l+r)>>1;
        update(tree[i].l = cp(tree[i].l), l, m, p, x);
        update(tree[i].r = cp(tree[i].r), m+1, r, p, x);

        tree[i].x = tree[tree[i].l].x + tree[tree[i].r].x;
    }
    int query(int i, int l, int r, int s, int e){
        if (r<s || e<l) return 0;
        if (s<=l && r<=e) return tree[i].x;

        int m = (l+r)>>1;
        return query(tree[i].l, l, m, s, e) + query(tree[i].r, m+1, r, s, e);
    }

    void add_root(){root.push_back(cp(root.back()));}
    void update(int p, int x){update(root.back(), 1, sz, p, x);}
    int query(int t, int l, int r){return query(root[t], 1, sz, l, r);}
    int query2D(int t1, int t2, int l, int r){return query(t2, l, r) - query(t1-1, l, r);}

}treeV, treeEh, treeEv, treeF;

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}, n, m, mnx, mxx, mny, mxy;
vector<int> V[200200], Eh[200200], Ev[200200], F[200200];

void add_vertex(int x, int y){
    mnx = min(mnx, x);
    mxx = max(mxx, x);
    mny = min(mny, y);
    mxy = max(mxy, y);

    V[x].push_back(y);

    Eh[x].push_back(y-1);
    Eh[x].push_back(y);
    Ev[x-1].push_back(y);
    Ev[x].push_back(y);

    for (int i=-1;i<=0;i++){
        for (int j=-1;j<=0;j++){
            F[x+i].push_back(y+j);
        }
    }
}

void pst_init(vector<int> a[], PST &tree){
    tree.init(m);
    for (int i=1;i<=n;i++){
        sort(a[i].begin(), a[i].end());
        a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());

        tree.add_root();
        for (auto &y:a[i]) if (y>0) tree.update(y, 1);
    }
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    n = R, m = C;
    mnx = mny = 1e9;
    mxx = mxy = -1e9;
    add_vertex(sr, sc);

    for (int i=0;i<M;i++){
        int k;
        if (S[i]=='N') k = 0;
        if (S[i]=='E') k = 1;
        if (S[i]=='S') k = 2;
        if (S[i]=='W') k = 3;

        sr += dx[k], sc += dy[k];
        add_vertex(sr, sc);
    }

    pst_init(V, treeV);
    pst_init(Eh, treeEh);
    pst_init(Ev, treeEv);
    pst_init(F, treeF);
}


int colour(int ar, int ac, int br, int bc) {
    ll v = 0, e = 0, f = 0;
    if (ar < mnx && mxx < br && ac < mny && mxy < bc) f = 1;

    ll xL = br - ar, yL = bc - ac;

    v = xL * yL - treeV.query2D(ar, br, ac, bc);
    e = xL * (yL-1) - treeEh.query2D(ar, br, ac, bc-1);
    e += (xL-1) * yL - treeEv.query2D(ar, br-1, ac, bc);
    f += (xL-1) * (yL-1) - treeF.query2D(ar, br-1, ac, bc-1);

    return v - e + f;
}

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:100:32: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
  100 |         sr += dx[k], sc += dy[k];
      |                            ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19284 KB Output is correct
2 Correct 13 ms 20068 KB Output is correct
3 Correct 11 ms 19368 KB Output is correct
4 Correct 12 ms 19412 KB Output is correct
5 Correct 12 ms 20380 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 10 ms 19024 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19068 KB Output is correct
11 Correct 12 ms 19404 KB Output is correct
12 Correct 12 ms 19796 KB Output is correct
13 Correct 13 ms 20380 KB Output is correct
14 Correct 16 ms 20772 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 19028 KB Output is correct
17 Correct 9 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19028 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 522 ms 198444 KB Output is correct
4 Correct 702 ms 316232 KB Output is correct
5 Correct 741 ms 265880 KB Output is correct
6 Correct 573 ms 226184 KB Output is correct
7 Correct 622 ms 218452 KB Output is correct
8 Correct 310 ms 24356 KB Output is correct
9 Correct 742 ms 315592 KB Output is correct
10 Correct 689 ms 314620 KB Output is correct
11 Correct 585 ms 226108 KB Output is correct
12 Correct 418 ms 309736 KB Output is correct
13 Correct 415 ms 316064 KB Output is correct
14 Correct 404 ms 315040 KB Output is correct
15 Correct 320 ms 226524 KB Output is correct
16 Correct 517 ms 208040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 369 ms 346884 KB Output is correct
3 Correct 359 ms 351736 KB Output is correct
4 Correct 443 ms 350236 KB Output is correct
5 Correct 310 ms 307304 KB Output is correct
6 Correct 117 ms 108284 KB Output is correct
7 Correct 184 ms 178872 KB Output is correct
8 Correct 263 ms 236792 KB Output is correct
9 Correct 241 ms 218296 KB Output is correct
10 Correct 77 ms 70624 KB Output is correct
11 Correct 194 ms 182004 KB Output is correct
12 Correct 376 ms 346960 KB Output is correct
13 Correct 424 ms 351556 KB Output is correct
14 Correct 383 ms 350276 KB Output is correct
15 Correct 316 ms 307380 KB Output is correct
16 Correct 100 ms 98268 KB Output is correct
17 Correct 183 ms 179416 KB Output is correct
18 Correct 386 ms 347704 KB Output is correct
19 Correct 329 ms 331704 KB Output is correct
20 Correct 334 ms 331508 KB Output is correct
21 Correct 269 ms 236828 KB Output is correct
22 Correct 245 ms 218416 KB Output is correct
23 Correct 86 ms 70536 KB Output is correct
24 Correct 197 ms 182172 KB Output is correct
25 Correct 398 ms 346948 KB Output is correct
26 Correct 356 ms 351592 KB Output is correct
27 Correct 389 ms 350224 KB Output is correct
28 Correct 313 ms 307344 KB Output is correct
29 Correct 101 ms 98284 KB Output is correct
30 Correct 182 ms 179344 KB Output is correct
31 Correct 390 ms 347796 KB Output is correct
32 Correct 345 ms 331664 KB Output is correct
33 Correct 336 ms 331584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19284 KB Output is correct
2 Correct 13 ms 20068 KB Output is correct
3 Correct 11 ms 19368 KB Output is correct
4 Correct 12 ms 19412 KB Output is correct
5 Correct 12 ms 20380 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 10 ms 19024 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19068 KB Output is correct
11 Correct 12 ms 19404 KB Output is correct
12 Correct 12 ms 19796 KB Output is correct
13 Correct 13 ms 20380 KB Output is correct
14 Correct 16 ms 20772 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 19028 KB Output is correct
17 Correct 9 ms 19028 KB Output is correct
18 Correct 573 ms 119784 KB Output is correct
19 Correct 184 ms 23680 KB Output is correct
20 Correct 132 ms 20456 KB Output is correct
21 Correct 143 ms 20764 KB Output is correct
22 Correct 155 ms 21436 KB Output is correct
23 Correct 177 ms 23532 KB Output is correct
24 Correct 129 ms 20692 KB Output is correct
25 Correct 147 ms 21396 KB Output is correct
26 Correct 158 ms 21872 KB Output is correct
27 Correct 329 ms 113024 KB Output is correct
28 Correct 270 ms 62748 KB Output is correct
29 Correct 343 ms 99484 KB Output is correct
30 Correct 491 ms 191412 KB Output is correct
31 Correct 12 ms 19156 KB Output is correct
32 Correct 411 ms 102928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19284 KB Output is correct
2 Correct 13 ms 20068 KB Output is correct
3 Correct 11 ms 19368 KB Output is correct
4 Correct 12 ms 19412 KB Output is correct
5 Correct 12 ms 20380 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 10 ms 19028 KB Output is correct
8 Correct 10 ms 19024 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19068 KB Output is correct
11 Correct 12 ms 19404 KB Output is correct
12 Correct 12 ms 19796 KB Output is correct
13 Correct 13 ms 20380 KB Output is correct
14 Correct 16 ms 20772 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 19028 KB Output is correct
17 Correct 9 ms 19028 KB Output is correct
18 Correct 573 ms 119784 KB Output is correct
19 Correct 184 ms 23680 KB Output is correct
20 Correct 132 ms 20456 KB Output is correct
21 Correct 143 ms 20764 KB Output is correct
22 Correct 155 ms 21436 KB Output is correct
23 Correct 177 ms 23532 KB Output is correct
24 Correct 129 ms 20692 KB Output is correct
25 Correct 147 ms 21396 KB Output is correct
26 Correct 158 ms 21872 KB Output is correct
27 Correct 329 ms 113024 KB Output is correct
28 Correct 270 ms 62748 KB Output is correct
29 Correct 343 ms 99484 KB Output is correct
30 Correct 491 ms 191412 KB Output is correct
31 Correct 12 ms 19156 KB Output is correct
32 Correct 411 ms 102928 KB Output is correct
33 Correct 369 ms 346884 KB Output is correct
34 Correct 359 ms 351736 KB Output is correct
35 Correct 443 ms 350236 KB Output is correct
36 Correct 310 ms 307304 KB Output is correct
37 Correct 117 ms 108284 KB Output is correct
38 Correct 184 ms 178872 KB Output is correct
39 Correct 263 ms 236792 KB Output is correct
40 Correct 241 ms 218296 KB Output is correct
41 Correct 77 ms 70624 KB Output is correct
42 Correct 194 ms 182004 KB Output is correct
43 Correct 376 ms 346960 KB Output is correct
44 Correct 424 ms 351556 KB Output is correct
45 Correct 383 ms 350276 KB Output is correct
46 Correct 316 ms 307380 KB Output is correct
47 Correct 100 ms 98268 KB Output is correct
48 Correct 183 ms 179416 KB Output is correct
49 Correct 386 ms 347704 KB Output is correct
50 Correct 329 ms 331704 KB Output is correct
51 Correct 334 ms 331508 KB Output is correct
52 Correct 269 ms 236828 KB Output is correct
53 Correct 245 ms 218416 KB Output is correct
54 Correct 86 ms 70536 KB Output is correct
55 Correct 197 ms 182172 KB Output is correct
56 Correct 398 ms 346948 KB Output is correct
57 Correct 356 ms 351592 KB Output is correct
58 Correct 389 ms 350224 KB Output is correct
59 Correct 313 ms 307344 KB Output is correct
60 Correct 101 ms 98284 KB Output is correct
61 Correct 182 ms 179344 KB Output is correct
62 Correct 390 ms 347796 KB Output is correct
63 Correct 345 ms 331664 KB Output is correct
64 Correct 336 ms 331584 KB Output is correct
65 Correct 522 ms 198444 KB Output is correct
66 Correct 702 ms 316232 KB Output is correct
67 Correct 741 ms 265880 KB Output is correct
68 Correct 573 ms 226184 KB Output is correct
69 Correct 622 ms 218452 KB Output is correct
70 Correct 310 ms 24356 KB Output is correct
71 Correct 742 ms 315592 KB Output is correct
72 Correct 689 ms 314620 KB Output is correct
73 Correct 585 ms 226108 KB Output is correct
74 Correct 418 ms 309736 KB Output is correct
75 Correct 415 ms 316064 KB Output is correct
76 Correct 404 ms 315040 KB Output is correct
77 Correct 320 ms 226524 KB Output is correct
78 Correct 517 ms 208040 KB Output is correct
79 Correct 800 ms 237532 KB Output is correct
80 Correct 779 ms 219032 KB Output is correct
81 Correct 316 ms 71208 KB Output is correct
82 Correct 512 ms 182804 KB Output is correct
83 Correct 835 ms 346880 KB Output is correct
84 Correct 744 ms 351664 KB Output is correct
85 Correct 790 ms 350208 KB Output is correct
86 Correct 689 ms 307416 KB Output is correct
87 Correct 426 ms 98268 KB Output is correct
88 Correct 520 ms 180144 KB Output is correct
89 Correct 714 ms 347652 KB Output is correct
90 Correct 790 ms 331676 KB Output is correct
91 Correct 675 ms 331592 KB Output is correct