Submission #678872

# Submission time Handle Problem Language Result Execution time Memory
678872 2023-01-06T19:28:06 Z qwerasdfzxcl Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
689 ms 227624 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 (l==r) {tree[i].x += x; return;}

        int m = (l+r)>>1;
        if (p<=m) update(tree[i].l = cp(tree[i].l), l, m, p, x);
        else 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:99:32: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   99 |         sr += dx[k], sc += dy[k];
      |                            ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19156 KB Output is correct
2 Correct 12 ms 19688 KB Output is correct
3 Correct 11 ms 19156 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 14 ms 19752 KB Output is correct
6 Correct 10 ms 19112 KB Output is correct
7 Correct 10 ms 19084 KB Output is correct
8 Correct 10 ms 19028 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19012 KB Output is correct
11 Correct 12 ms 19284 KB Output is correct
12 Correct 12 ms 19468 KB Output is correct
13 Correct 13 ms 19840 KB Output is correct
14 Correct 13 ms 20068 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 18988 KB Output is correct
17 Correct 10 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 18988 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 434 ms 110372 KB Output is correct
4 Correct 557 ms 176924 KB Output is correct
5 Correct 594 ms 168916 KB Output is correct
6 Correct 467 ms 124860 KB Output is correct
7 Correct 477 ms 121052 KB Output is correct
8 Correct 278 ms 24280 KB Output is correct
9 Correct 548 ms 176264 KB Output is correct
10 Correct 556 ms 174668 KB Output is correct
11 Correct 473 ms 124900 KB Output is correct
12 Correct 297 ms 173424 KB Output is correct
13 Correct 293 ms 176420 KB Output is correct
14 Correct 307 ms 175044 KB Output is correct
15 Correct 242 ms 125112 KB Output is correct
16 Correct 447 ms 115184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 260 ms 209180 KB Output is correct
3 Correct 266 ms 226864 KB Output is correct
4 Correct 262 ms 212624 KB Output is correct
5 Correct 244 ms 192104 KB Output is correct
6 Correct 94 ms 72596 KB Output is correct
7 Correct 136 ms 107768 KB Output is correct
8 Correct 189 ms 130088 KB Output is correct
9 Correct 187 ms 121176 KB Output is correct
10 Correct 60 ms 49056 KB Output is correct
11 Correct 138 ms 105912 KB Output is correct
12 Correct 244 ms 209276 KB Output is correct
13 Correct 252 ms 226816 KB Output is correct
14 Correct 259 ms 212676 KB Output is correct
15 Correct 217 ms 192088 KB Output is correct
16 Correct 84 ms 67452 KB Output is correct
17 Correct 132 ms 108108 KB Output is correct
18 Correct 251 ms 210120 KB Output is correct
19 Correct 223 ms 193640 KB Output is correct
20 Correct 221 ms 193496 KB Output is correct
21 Correct 180 ms 130088 KB Output is correct
22 Correct 168 ms 121120 KB Output is correct
23 Correct 60 ms 49056 KB Output is correct
24 Correct 138 ms 105880 KB Output is correct
25 Correct 252 ms 209284 KB Output is correct
26 Correct 254 ms 226840 KB Output is correct
27 Correct 249 ms 212512 KB Output is correct
28 Correct 228 ms 192272 KB Output is correct
29 Correct 84 ms 67436 KB Output is correct
30 Correct 134 ms 108136 KB Output is correct
31 Correct 246 ms 210008 KB Output is correct
32 Correct 223 ms 193584 KB Output is correct
33 Correct 222 ms 193444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19156 KB Output is correct
2 Correct 12 ms 19688 KB Output is correct
3 Correct 11 ms 19156 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 14 ms 19752 KB Output is correct
6 Correct 10 ms 19112 KB Output is correct
7 Correct 10 ms 19084 KB Output is correct
8 Correct 10 ms 19028 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19012 KB Output is correct
11 Correct 12 ms 19284 KB Output is correct
12 Correct 12 ms 19468 KB Output is correct
13 Correct 13 ms 19840 KB Output is correct
14 Correct 13 ms 20068 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 18988 KB Output is correct
17 Correct 10 ms 19028 KB Output is correct
18 Correct 460 ms 72408 KB Output is correct
19 Correct 180 ms 21716 KB Output is correct
20 Correct 126 ms 20096 KB Output is correct
21 Correct 144 ms 20516 KB Output is correct
22 Correct 151 ms 20728 KB Output is correct
23 Correct 182 ms 21536 KB Output is correct
24 Correct 126 ms 20464 KB Output is correct
25 Correct 147 ms 20672 KB Output is correct
26 Correct 151 ms 21012 KB Output is correct
27 Correct 274 ms 69048 KB Output is correct
28 Correct 258 ms 43548 KB Output is correct
29 Correct 287 ms 62016 KB Output is correct
30 Correct 404 ms 107836 KB Output is correct
31 Correct 12 ms 19040 KB Output is correct
32 Correct 386 ms 63284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19156 KB Output is correct
2 Correct 12 ms 19688 KB Output is correct
3 Correct 11 ms 19156 KB Output is correct
4 Correct 12 ms 19284 KB Output is correct
5 Correct 14 ms 19752 KB Output is correct
6 Correct 10 ms 19112 KB Output is correct
7 Correct 10 ms 19084 KB Output is correct
8 Correct 10 ms 19028 KB Output is correct
9 Correct 10 ms 19028 KB Output is correct
10 Correct 10 ms 19012 KB Output is correct
11 Correct 12 ms 19284 KB Output is correct
12 Correct 12 ms 19468 KB Output is correct
13 Correct 13 ms 19840 KB Output is correct
14 Correct 13 ms 20068 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 11 ms 18988 KB Output is correct
17 Correct 10 ms 19028 KB Output is correct
18 Correct 460 ms 72408 KB Output is correct
19 Correct 180 ms 21716 KB Output is correct
20 Correct 126 ms 20096 KB Output is correct
21 Correct 144 ms 20516 KB Output is correct
22 Correct 151 ms 20728 KB Output is correct
23 Correct 182 ms 21536 KB Output is correct
24 Correct 126 ms 20464 KB Output is correct
25 Correct 147 ms 20672 KB Output is correct
26 Correct 151 ms 21012 KB Output is correct
27 Correct 274 ms 69048 KB Output is correct
28 Correct 258 ms 43548 KB Output is correct
29 Correct 287 ms 62016 KB Output is correct
30 Correct 404 ms 107836 KB Output is correct
31 Correct 12 ms 19040 KB Output is correct
32 Correct 386 ms 63284 KB Output is correct
33 Correct 260 ms 209180 KB Output is correct
34 Correct 266 ms 226864 KB Output is correct
35 Correct 262 ms 212624 KB Output is correct
36 Correct 244 ms 192104 KB Output is correct
37 Correct 94 ms 72596 KB Output is correct
38 Correct 136 ms 107768 KB Output is correct
39 Correct 189 ms 130088 KB Output is correct
40 Correct 187 ms 121176 KB Output is correct
41 Correct 60 ms 49056 KB Output is correct
42 Correct 138 ms 105912 KB Output is correct
43 Correct 244 ms 209276 KB Output is correct
44 Correct 252 ms 226816 KB Output is correct
45 Correct 259 ms 212676 KB Output is correct
46 Correct 217 ms 192088 KB Output is correct
47 Correct 84 ms 67452 KB Output is correct
48 Correct 132 ms 108108 KB Output is correct
49 Correct 251 ms 210120 KB Output is correct
50 Correct 223 ms 193640 KB Output is correct
51 Correct 221 ms 193496 KB Output is correct
52 Correct 180 ms 130088 KB Output is correct
53 Correct 168 ms 121120 KB Output is correct
54 Correct 60 ms 49056 KB Output is correct
55 Correct 138 ms 105880 KB Output is correct
56 Correct 252 ms 209284 KB Output is correct
57 Correct 254 ms 226840 KB Output is correct
58 Correct 249 ms 212512 KB Output is correct
59 Correct 228 ms 192272 KB Output is correct
60 Correct 84 ms 67436 KB Output is correct
61 Correct 134 ms 108136 KB Output is correct
62 Correct 246 ms 210008 KB Output is correct
63 Correct 223 ms 193584 KB Output is correct
64 Correct 222 ms 193444 KB Output is correct
65 Correct 434 ms 110372 KB Output is correct
66 Correct 557 ms 176924 KB Output is correct
67 Correct 594 ms 168916 KB Output is correct
68 Correct 467 ms 124860 KB Output is correct
69 Correct 477 ms 121052 KB Output is correct
70 Correct 278 ms 24280 KB Output is correct
71 Correct 548 ms 176264 KB Output is correct
72 Correct 556 ms 174668 KB Output is correct
73 Correct 473 ms 124900 KB Output is correct
74 Correct 297 ms 173424 KB Output is correct
75 Correct 293 ms 176420 KB Output is correct
76 Correct 307 ms 175044 KB Output is correct
77 Correct 242 ms 125112 KB Output is correct
78 Correct 447 ms 115184 KB Output is correct
79 Correct 663 ms 130792 KB Output is correct
80 Correct 689 ms 121812 KB Output is correct
81 Correct 301 ms 49756 KB Output is correct
82 Correct 424 ms 106624 KB Output is correct
83 Correct 677 ms 209960 KB Output is correct
84 Correct 607 ms 227624 KB Output is correct
85 Correct 630 ms 213276 KB Output is correct
86 Correct 579 ms 192908 KB Output is correct
87 Correct 425 ms 68332 KB Output is correct
88 Correct 465 ms 108872 KB Output is correct
89 Correct 591 ms 210764 KB Output is correct
90 Correct 643 ms 194356 KB Output is correct
91 Correct 566 ms 194284 KB Output is correct