Submission #201246

# Submission time Handle Problem Language Result Execution time Memory
201246 2020-02-10T03:14:19 Z BThero Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
2084 ms 133188 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
#include "rainbow.h"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)2e5 + 5;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const char dc[] = {'E', 'S', 'W', 'N'};

template<int N> struct BIT {
    vector<pii> T[N + 5];

    void update(int x, int y) {
        if (x < 1 || y < 1) {
            return;
        }
        
        int stx = x;

        for (; x <= N; x |= (x + 1)) {
            T[x].pb(mp(y, stx));            
        }
    }

    void build() {
        for (int i = 1; i <= N; ++i) {
            sort(all(T[i]));
            T[i].resize(unique(all(T[i])) - T[i].begin());           
        }
    }

    ll prectS(int x, int ly, int ry) {
        ll ret = 0;
        
        for (; x > 0; --x) {
            ret += lower_bound(all(T[x]), mp(ry + 1, 0)) - lower_bound(all(T[x]), mp(ly, 0));
            x &= (x + 1);
        }

        return ret;
    }

    ll rectS(int ax, int bx, int ay, int by) {
        if (ax > bx || ay > by) {
            return 0;
        }

        return prectS(bx, ay, by) - prectS(ax - 1, ay, by);
    }
};

int mnx, mxx, mny, mxy;

BIT<200000> H[4];

pii arr[MAXN];

int n, m, k;

void init(int R, int C, int stx, int sty, int M, char *S) {
    n = R;
    m = C;
    k = M;
    arr[0] = mp(stx, sty);

    for (int i = 0; i < k; ++i) {
        int dir = find(dc, dc + 4, S[i]) - dc;
        stx += dx[dir];
        sty += dy[dir];
        arr[i + 1] = mp(stx, sty);                                
    }

    mnx = mxx = arr[0].fi;
    mny = mxy = arr[0].se;

    for (int i = 0; i <= k; ++i) {
        int x, y;
        tie(x, y) = arr[i];
        mnx = min(mnx, x);
        mxx = max(mxx, x);
        mny = min(mny, y);
        mxy = max(mxy, y);
        H[0].update(x, y);
        H[1].update(x, y);
        H[1].update(x - 1, y);
        H[2].update(x, y);
        H[2].update(x, y - 1);
        H[3].update(x, y);
        H[3].update(x - 1, y);
        H[3].update(x, y - 1);
        H[3].update(x - 1, y - 1);
    }    

    H[0].build();
    H[1].build();
    H[2].build();
    H[3].build();
}

int colour(int ax, int ay, int bx, int by) {
    ll ans = 1;

    if (ax < mnx && mxx < bx && ay < mny && mxy < by) {
        ++ans;        
    }    

    ans += H[1].rectS(ax, bx - 1, ay, by);
    ans += H[2].rectS(ax, bx, ay, by - 1);
    ans -= H[3].rectS(ax, bx - 1, ay, by - 1);
    ans -= H[0].rectS(ax, bx, ay, by);     
    return ans; 
}

# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 36 ms 21112 KB Output is correct
3 Correct 23 ms 19448 KB Output is correct
4 Correct 25 ms 19708 KB Output is correct
5 Correct 41 ms 22776 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 19 ms 19064 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 19 ms 19192 KB Output is correct
11 Correct 31 ms 20472 KB Output is correct
12 Correct 35 ms 21240 KB Output is correct
13 Correct 34 ms 21112 KB Output is correct
14 Correct 57 ms 23800 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 18 ms 19064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19064 KB Output is correct
2 Correct 18 ms 19064 KB Output is correct
3 Correct 465 ms 87972 KB Output is correct
4 Correct 724 ms 129240 KB Output is correct
5 Correct 744 ms 128244 KB Output is correct
6 Correct 839 ms 128652 KB Output is correct
7 Correct 640 ms 118556 KB Output is correct
8 Correct 735 ms 128324 KB Output is correct
9 Correct 720 ms 128512 KB Output is correct
10 Correct 767 ms 129092 KB Output is correct
11 Correct 842 ms 129340 KB Output is correct
12 Correct 592 ms 126284 KB Output is correct
13 Correct 612 ms 128096 KB Output is correct
14 Correct 667 ms 129416 KB Output is correct
15 Correct 768 ms 128644 KB Output is correct
16 Correct 468 ms 96548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19064 KB Output is correct
2 Correct 386 ms 101136 KB Output is correct
3 Correct 427 ms 92340 KB Output is correct
4 Correct 397 ms 96332 KB Output is correct
5 Correct 543 ms 87828 KB Output is correct
6 Correct 731 ms 99176 KB Output is correct
7 Correct 559 ms 82628 KB Output is correct
8 Correct 1222 ms 125884 KB Output is correct
9 Correct 1285 ms 129496 KB Output is correct
10 Correct 460 ms 56828 KB Output is correct
11 Correct 772 ms 104364 KB Output is correct
12 Correct 378 ms 101152 KB Output is correct
13 Correct 431 ms 92092 KB Output is correct
14 Correct 398 ms 96456 KB Output is correct
15 Correct 541 ms 87836 KB Output is correct
16 Correct 740 ms 102860 KB Output is correct
17 Correct 821 ms 108800 KB Output is correct
18 Correct 1033 ms 121468 KB Output is correct
19 Correct 429 ms 82348 KB Output is correct
20 Correct 388 ms 94284 KB Output is correct
21 Correct 1234 ms 125872 KB Output is correct
22 Correct 1287 ms 129768 KB Output is correct
23 Correct 469 ms 57088 KB Output is correct
24 Correct 764 ms 104464 KB Output is correct
25 Correct 377 ms 101132 KB Output is correct
26 Correct 435 ms 92408 KB Output is correct
27 Correct 400 ms 96712 KB Output is correct
28 Correct 539 ms 87780 KB Output is correct
29 Correct 744 ms 102992 KB Output is correct
30 Correct 809 ms 109028 KB Output is correct
31 Correct 1033 ms 121412 KB Output is correct
32 Correct 424 ms 82352 KB Output is correct
33 Correct 374 ms 94316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 36 ms 21112 KB Output is correct
3 Correct 23 ms 19448 KB Output is correct
4 Correct 25 ms 19708 KB Output is correct
5 Correct 41 ms 22776 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 19 ms 19064 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 19 ms 19192 KB Output is correct
11 Correct 31 ms 20472 KB Output is correct
12 Correct 35 ms 21240 KB Output is correct
13 Correct 34 ms 21112 KB Output is correct
14 Correct 57 ms 23800 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 18 ms 19064 KB Output is correct
18 Correct 2084 ms 122804 KB Output is correct
19 Correct 336 ms 26360 KB Output is correct
20 Correct 250 ms 23288 KB Output is correct
21 Correct 281 ms 23672 KB Output is correct
22 Correct 309 ms 24544 KB Output is correct
23 Correct 320 ms 26104 KB Output is correct
24 Correct 330 ms 26360 KB Output is correct
25 Correct 337 ms 26872 KB Output is correct
26 Correct 363 ms 27028 KB Output is correct
27 Correct 1120 ms 116724 KB Output is correct
28 Correct 1277 ms 123028 KB Output is correct
29 Correct 1234 ms 118612 KB Output is correct
30 Correct 1831 ms 124948 KB Output is correct
31 Correct 23 ms 19320 KB Output is correct
32 Correct 1719 ms 123884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 19448 KB Output is correct
2 Correct 36 ms 21112 KB Output is correct
3 Correct 23 ms 19448 KB Output is correct
4 Correct 25 ms 19708 KB Output is correct
5 Correct 41 ms 22776 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 19 ms 19064 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 19 ms 19192 KB Output is correct
11 Correct 31 ms 20472 KB Output is correct
12 Correct 35 ms 21240 KB Output is correct
13 Correct 34 ms 21112 KB Output is correct
14 Correct 57 ms 23800 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 18 ms 19064 KB Output is correct
18 Correct 2084 ms 122804 KB Output is correct
19 Correct 336 ms 26360 KB Output is correct
20 Correct 250 ms 23288 KB Output is correct
21 Correct 281 ms 23672 KB Output is correct
22 Correct 309 ms 24544 KB Output is correct
23 Correct 320 ms 26104 KB Output is correct
24 Correct 330 ms 26360 KB Output is correct
25 Correct 337 ms 26872 KB Output is correct
26 Correct 363 ms 27028 KB Output is correct
27 Correct 1120 ms 116724 KB Output is correct
28 Correct 1277 ms 123028 KB Output is correct
29 Correct 1234 ms 118612 KB Output is correct
30 Correct 1831 ms 124948 KB Output is correct
31 Correct 23 ms 19320 KB Output is correct
32 Correct 1719 ms 123884 KB Output is correct
33 Correct 386 ms 101136 KB Output is correct
34 Correct 427 ms 92340 KB Output is correct
35 Correct 397 ms 96332 KB Output is correct
36 Correct 543 ms 87828 KB Output is correct
37 Correct 731 ms 99176 KB Output is correct
38 Correct 559 ms 82628 KB Output is correct
39 Correct 1222 ms 125884 KB Output is correct
40 Correct 1285 ms 129496 KB Output is correct
41 Correct 460 ms 56828 KB Output is correct
42 Correct 772 ms 104364 KB Output is correct
43 Correct 378 ms 101152 KB Output is correct
44 Correct 431 ms 92092 KB Output is correct
45 Correct 398 ms 96456 KB Output is correct
46 Correct 541 ms 87836 KB Output is correct
47 Correct 740 ms 102860 KB Output is correct
48 Correct 821 ms 108800 KB Output is correct
49 Correct 1033 ms 121468 KB Output is correct
50 Correct 429 ms 82348 KB Output is correct
51 Correct 388 ms 94284 KB Output is correct
52 Correct 1234 ms 125872 KB Output is correct
53 Correct 1287 ms 129768 KB Output is correct
54 Correct 469 ms 57088 KB Output is correct
55 Correct 764 ms 104464 KB Output is correct
56 Correct 377 ms 101132 KB Output is correct
57 Correct 435 ms 92408 KB Output is correct
58 Correct 400 ms 96712 KB Output is correct
59 Correct 539 ms 87780 KB Output is correct
60 Correct 744 ms 102992 KB Output is correct
61 Correct 809 ms 109028 KB Output is correct
62 Correct 1033 ms 121412 KB Output is correct
63 Correct 424 ms 82352 KB Output is correct
64 Correct 374 ms 94316 KB Output is correct
65 Correct 1637 ms 129380 KB Output is correct
66 Correct 1762 ms 133188 KB Output is correct
67 Correct 829 ms 60520 KB Output is correct
68 Correct 1186 ms 108172 KB Output is correct
69 Correct 796 ms 104708 KB Output is correct
70 Correct 1111 ms 95932 KB Output is correct
71 Correct 892 ms 100168 KB Output is correct
72 Correct 1037 ms 91296 KB Output is correct
73 Correct 1000 ms 106440 KB Output is correct
74 Correct 1115 ms 112496 KB Output is correct
75 Correct 1325 ms 124824 KB Output is correct
76 Correct 1049 ms 86068 KB Output is correct
77 Correct 773 ms 97760 KB Output is correct
78 Correct 465 ms 87972 KB Output is correct
79 Correct 724 ms 129240 KB Output is correct
80 Correct 744 ms 128244 KB Output is correct
81 Correct 839 ms 128652 KB Output is correct
82 Correct 640 ms 118556 KB Output is correct
83 Correct 735 ms 128324 KB Output is correct
84 Correct 720 ms 128512 KB Output is correct
85 Correct 767 ms 129092 KB Output is correct
86 Correct 842 ms 129340 KB Output is correct
87 Correct 592 ms 126284 KB Output is correct
88 Correct 612 ms 128096 KB Output is correct
89 Correct 667 ms 129416 KB Output is correct
90 Correct 768 ms 128644 KB Output is correct
91 Correct 468 ms 96548 KB Output is correct