Submission #252294

# Submission time Handle Problem Language Result Execution time Memory
252294 2020-07-25T07:22:50 Z balbit Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
1742 ms 135652 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#ifndef BALBIT
#include "rainbow.h"
#endif

int n,m;
vector<pii> pts;
vector<pii> linev, lineh, face; // record top-left for all

bool H(pii &p) {
    return *lower_bound(ALL(pts), p) == p;
}
const int maxn = 2e5+5;

struct PBIT{
    vector<vector<pii> > s;
    void MO(int e, int v, int tm) {
        for (++e; e<maxn; e += e&-e) {
            s[e].pb({tm, s[e].back().s + v});
        }
    }
    int QU(int e, int tm) {
        int re = 0;
        for (++e; e>0; e -= e&-e) {
            re += prev(upper_bound(ALL(s[e]), pii{tm,10000000})) -> s;
        }
        return re;
    }
    int GT(int r1, int r2, int c1, int c2) {
        return max(0,QU(c2,r2) + QU(c1-1,r1-1) - QU(c2, r1-1) - QU(c1-1, r2));
    }
    PBIT (vector<pii> v){
        s.resize(maxn+2, {{-1,0}});
        // sorted by r
        for (pii p : v) {
            if (p.f >=1 && p.s >=1)
                MO(p.s, 1, p.f);
        }
    }
    PBIT(){}
};

PBIT bitV, bitEv, bitEh, bitF;

int minr, maxr, minc, maxc;

void init(signed R, signed C, signed sr, signed sc, signed M, char *S) {
    n = R, m = C;
    minr = maxr = sr; minc = maxc = sc;
    pts.pb({sr, sc});
    for (int i = 0; i<M; ++i) {
        if (S[i] == 'N') {
            --sr;
        }
        if (S[i] == 'S') {
            ++sr;
        }
        if (S[i] == 'E') {
            ++sc;
        }
        if (S[i] == 'W') {
            --sc;
        }
        pts.pb({sr, sc});
        minr = min(minr, sr); maxr = max(maxr, sr);
        minc = min(minc, sc); maxc = max(maxc, sc);
    }
    sort(ALL(pts));
    pts.resize(unique(ALL(pts)) - pts.begin());
    for (pii p : pts) {
        linev.pb({p.f-1, p.s});
        linev.pb({p.f, p.s});
        lineh.pb({p.f, p.s-1});
        lineh.pb({p.f, p.s});
        face.pb({p.f-1, p.s-1});
        face.pb({p.f, p.s-1});
        face.pb({p.f-1, p.s});
        face.pb({p.f, p.s});
    }
    bug("HI");
    sort(ALL(linev));
    sort(ALL(lineh));
    sort(ALL(face));
    linev.resize(unique(ALL(linev)) - linev.begin());
    lineh.resize(unique(ALL(lineh)) - lineh.begin());
    face.resize(unique(ALL(face)) - face.begin());
    bug("HI");
    bitV =  PBIT(pts);
    bitF =  PBIT(face);
    bitEh = PBIT(lineh);
    bitEv = PBIT(linev);
}

int r1, c1, r2, c2;


signed colour(signed R1, signed C1, signed R2, signed C2) {
    tie(r1,c1,r2,c2) = tie(R1,C1,R2,C2);
    ll rd = R2-R1+1, cd = C2-C1+1;
    ll V = rd * cd -bitV.GT(r1,r2,c1,c2);
    ll F = (rd - 1) * (cd - 1) - bitF.GT(r1,r2-1,c1,c2-1) + (r1 < minr && r2 > maxr && c1 < minc && c2 > maxc);
    ll E = (rd-1) * cd + (rd) * (cd-1) - (bitEh.GT(r1,r2,c1,c2-1) + bitEv.GT(r1,r2-1,c1,c2));
    bug(V, E, F);
    assert(E>=0 && V >= 0 && F >= 0);
    return V-E+F;
}





#ifdef BALBIT
signed main(){
    IOS();
    init(6,4,3,3,10,"NWESSWEWSE");
    bug(colour(2, 3, 2, 3));
    bug(colour(3, 1, 6, 4));
    bug(colour(6, 3, 6, 4));
    bug(colour(1, 2, 5, 3));
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 59 ms 44408 KB Output is correct
2 Correct 70 ms 44920 KB Output is correct
3 Correct 59 ms 44408 KB Output is correct
4 Correct 59 ms 44408 KB Output is correct
5 Correct 70 ms 45304 KB Output is correct
6 Correct 59 ms 44152 KB Output is correct
7 Correct 55 ms 44152 KB Output is correct
8 Correct 56 ms 44060 KB Output is correct
9 Correct 57 ms 44152 KB Output is correct
10 Correct 56 ms 44152 KB Output is correct
11 Correct 66 ms 44536 KB Output is correct
12 Correct 68 ms 44792 KB Output is correct
13 Correct 74 ms 45560 KB Output is correct
14 Correct 73 ms 45980 KB Output is correct
15 Correct 62 ms 44280 KB Output is correct
16 Correct 60 ms 44152 KB Output is correct
17 Correct 60 ms 44156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 44152 KB Output is correct
2 Correct 60 ms 44156 KB Output is correct
3 Correct 845 ms 84872 KB Output is correct
4 Correct 1152 ms 105852 KB Output is correct
5 Correct 1086 ms 102872 KB Output is correct
6 Correct 963 ms 86628 KB Output is correct
7 Correct 945 ms 90612 KB Output is correct
8 Correct 465 ms 45804 KB Output is correct
9 Correct 1141 ms 105504 KB Output is correct
10 Correct 1219 ms 102980 KB Output is correct
11 Correct 891 ms 86736 KB Output is correct
12 Correct 373 ms 107728 KB Output is correct
13 Correct 380 ms 105592 KB Output is correct
14 Correct 385 ms 102992 KB Output is correct
15 Correct 348 ms 86480 KB Output is correct
16 Correct 891 ms 88920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 44280 KB Output is correct
2 Correct 300 ms 117736 KB Output is correct
3 Correct 203 ms 111184 KB Output is correct
4 Correct 254 ms 115792 KB Output is correct
5 Correct 207 ms 97488 KB Output is correct
6 Correct 107 ms 56936 KB Output is correct
7 Correct 145 ms 70500 KB Output is correct
8 Correct 242 ms 98264 KB Output is correct
9 Correct 255 ms 94160 KB Output is correct
10 Correct 120 ms 61936 KB Output is correct
11 Correct 171 ms 81640 KB Output is correct
12 Correct 324 ms 117716 KB Output is correct
13 Correct 212 ms 111440 KB Output is correct
14 Correct 248 ms 115792 KB Output is correct
15 Correct 206 ms 97488 KB Output is correct
16 Correct 109 ms 56552 KB Output is correct
17 Correct 131 ms 68708 KB Output is correct
18 Correct 254 ms 131928 KB Output is correct
19 Correct 285 ms 117976 KB Output is correct
20 Correct 266 ms 118616 KB Output is correct
21 Correct 263 ms 98380 KB Output is correct
22 Correct 251 ms 94160 KB Output is correct
23 Correct 122 ms 61928 KB Output is correct
24 Correct 186 ms 81632 KB Output is correct
25 Correct 309 ms 117848 KB Output is correct
26 Correct 217 ms 111312 KB Output is correct
27 Correct 274 ms 115792 KB Output is correct
28 Correct 190 ms 97492 KB Output is correct
29 Correct 109 ms 56552 KB Output is correct
30 Correct 139 ms 68712 KB Output is correct
31 Correct 271 ms 132048 KB Output is correct
32 Correct 258 ms 117968 KB Output is correct
33 Correct 260 ms 118532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 44408 KB Output is correct
2 Correct 70 ms 44920 KB Output is correct
3 Correct 59 ms 44408 KB Output is correct
4 Correct 59 ms 44408 KB Output is correct
5 Correct 70 ms 45304 KB Output is correct
6 Correct 59 ms 44152 KB Output is correct
7 Correct 55 ms 44152 KB Output is correct
8 Correct 56 ms 44060 KB Output is correct
9 Correct 57 ms 44152 KB Output is correct
10 Correct 56 ms 44152 KB Output is correct
11 Correct 66 ms 44536 KB Output is correct
12 Correct 68 ms 44792 KB Output is correct
13 Correct 74 ms 45560 KB Output is correct
14 Correct 73 ms 45980 KB Output is correct
15 Correct 62 ms 44280 KB Output is correct
16 Correct 60 ms 44152 KB Output is correct
17 Correct 60 ms 44156 KB Output is correct
18 Correct 1337 ms 88604 KB Output is correct
19 Correct 431 ms 50072 KB Output is correct
20 Correct 323 ms 48040 KB Output is correct
21 Correct 371 ms 48504 KB Output is correct
22 Correct 403 ms 48916 KB Output is correct
23 Correct 433 ms 49912 KB Output is correct
24 Correct 368 ms 48672 KB Output is correct
25 Correct 409 ms 48888 KB Output is correct
26 Correct 411 ms 49272 KB Output is correct
27 Correct 712 ms 86756 KB Output is correct
28 Correct 457 ms 65128 KB Output is correct
29 Correct 597 ms 79584 KB Output is correct
30 Correct 1064 ms 135516 KB Output is correct
31 Correct 61 ms 44280 KB Output is correct
32 Correct 1052 ms 89112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 44408 KB Output is correct
2 Correct 70 ms 44920 KB Output is correct
3 Correct 59 ms 44408 KB Output is correct
4 Correct 59 ms 44408 KB Output is correct
5 Correct 70 ms 45304 KB Output is correct
6 Correct 59 ms 44152 KB Output is correct
7 Correct 55 ms 44152 KB Output is correct
8 Correct 56 ms 44060 KB Output is correct
9 Correct 57 ms 44152 KB Output is correct
10 Correct 56 ms 44152 KB Output is correct
11 Correct 66 ms 44536 KB Output is correct
12 Correct 68 ms 44792 KB Output is correct
13 Correct 74 ms 45560 KB Output is correct
14 Correct 73 ms 45980 KB Output is correct
15 Correct 62 ms 44280 KB Output is correct
16 Correct 60 ms 44152 KB Output is correct
17 Correct 60 ms 44156 KB Output is correct
18 Correct 1337 ms 88604 KB Output is correct
19 Correct 431 ms 50072 KB Output is correct
20 Correct 323 ms 48040 KB Output is correct
21 Correct 371 ms 48504 KB Output is correct
22 Correct 403 ms 48916 KB Output is correct
23 Correct 433 ms 49912 KB Output is correct
24 Correct 368 ms 48672 KB Output is correct
25 Correct 409 ms 48888 KB Output is correct
26 Correct 411 ms 49272 KB Output is correct
27 Correct 712 ms 86756 KB Output is correct
28 Correct 457 ms 65128 KB Output is correct
29 Correct 597 ms 79584 KB Output is correct
30 Correct 1064 ms 135516 KB Output is correct
31 Correct 61 ms 44280 KB Output is correct
32 Correct 1052 ms 89112 KB Output is correct
33 Correct 300 ms 117736 KB Output is correct
34 Correct 203 ms 111184 KB Output is correct
35 Correct 254 ms 115792 KB Output is correct
36 Correct 207 ms 97488 KB Output is correct
37 Correct 107 ms 56936 KB Output is correct
38 Correct 145 ms 70500 KB Output is correct
39 Correct 242 ms 98264 KB Output is correct
40 Correct 255 ms 94160 KB Output is correct
41 Correct 120 ms 61936 KB Output is correct
42 Correct 171 ms 81640 KB Output is correct
43 Correct 324 ms 117716 KB Output is correct
44 Correct 212 ms 111440 KB Output is correct
45 Correct 248 ms 115792 KB Output is correct
46 Correct 206 ms 97488 KB Output is correct
47 Correct 109 ms 56552 KB Output is correct
48 Correct 131 ms 68708 KB Output is correct
49 Correct 254 ms 131928 KB Output is correct
50 Correct 285 ms 117976 KB Output is correct
51 Correct 266 ms 118616 KB Output is correct
52 Correct 263 ms 98380 KB Output is correct
53 Correct 251 ms 94160 KB Output is correct
54 Correct 122 ms 61928 KB Output is correct
55 Correct 186 ms 81632 KB Output is correct
56 Correct 309 ms 117848 KB Output is correct
57 Correct 217 ms 111312 KB Output is correct
58 Correct 274 ms 115792 KB Output is correct
59 Correct 190 ms 97492 KB Output is correct
60 Correct 109 ms 56552 KB Output is correct
61 Correct 139 ms 68712 KB Output is correct
62 Correct 271 ms 132048 KB Output is correct
63 Correct 258 ms 117968 KB Output is correct
64 Correct 260 ms 118532 KB Output is correct
65 Correct 1583 ms 101900 KB Output is correct
66 Correct 1742 ms 97752 KB Output is correct
67 Correct 799 ms 65388 KB Output is correct
68 Correct 1113 ms 85088 KB Output is correct
69 Correct 995 ms 121424 KB Output is correct
70 Correct 756 ms 114904 KB Output is correct
71 Correct 864 ms 119376 KB Output is correct
72 Correct 753 ms 101164 KB Output is correct
73 Correct 502 ms 60204 KB Output is correct
74 Correct 534 ms 72252 KB Output is correct
75 Correct 692 ms 135652 KB Output is correct
76 Correct 1067 ms 121428 KB Output is correct
77 Correct 792 ms 122088 KB Output is correct
78 Correct 845 ms 84872 KB Output is correct
79 Correct 1152 ms 105852 KB Output is correct
80 Correct 1086 ms 102872 KB Output is correct
81 Correct 963 ms 86628 KB Output is correct
82 Correct 945 ms 90612 KB Output is correct
83 Correct 465 ms 45804 KB Output is correct
84 Correct 1141 ms 105504 KB Output is correct
85 Correct 1219 ms 102980 KB Output is correct
86 Correct 891 ms 86736 KB Output is correct
87 Correct 373 ms 107728 KB Output is correct
88 Correct 380 ms 105592 KB Output is correct
89 Correct 385 ms 102992 KB Output is correct
90 Correct 348 ms 86480 KB Output is correct
91 Correct 891 ms 88920 KB Output is correct