Submission #201249

# Submission time Handle Problem Language Result Execution time Memory
201249 2020-02-10T03:20:47 Z BThero Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
1221 ms 72516 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<int> T[N + 5];

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

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

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

    ll prectS(int x, int ly, int ry) {
        ll ret = 0;
        
        for (; x > 0; --x) {
            ret += upper_bound(all(T[x]), ry) - lower_bound(all(T[x]), ly);
            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];

vector<pii> V[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;
    sort(arr, arr + k + 1);

    for (int i = 0; i <= k; ++i) {
        if (i > 0 && arr[i] == arr[i - 1]) {
            continue;
        }

        int x, y;
        tie(x, y) = arr[i];
        mnx = min(mnx, x);
        mxx = max(mxx, x);
        mny = min(mny, y);
        mxy = max(mxy, y);
        V[0].pb(mp(x, y));
        V[1].pb(mp(x, y));
        V[1].pb(mp(x - 1, y));
        V[2].pb(mp(x, y));
        V[2].pb(mp(x, y - 1));
        V[3].pb(mp(x, y));
        V[3].pb(mp(x - 1, y));
        V[3].pb(mp(x, y - 1));
        V[3].pb(mp(x - 1, y - 1));
    }

    for (int i = 0; i < 4; ++i) {
        sort(all(V[i]));
        V[i].resize(unique(all(V[i])) - V[i].begin());

        for (auto it : V[i]) {
            H[i].update(it.fi, it.se);
        }

        H[i].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 22 ms 19192 KB Output is correct
2 Correct 24 ms 19576 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 22 ms 19320 KB Output is correct
5 Correct 26 ms 19704 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 18 ms 19064 KB Output is correct
9 Correct 19 ms 19064 KB Output is correct
10 Correct 20 ms 19064 KB Output is correct
11 Correct 30 ms 19320 KB Output is correct
12 Correct 23 ms 19448 KB Output is correct
13 Correct 27 ms 19832 KB Output is correct
14 Correct 29 ms 20084 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 19 ms 19064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19064 KB Output is correct
2 Correct 19 ms 19064 KB Output is correct
3 Correct 507 ms 50132 KB Output is correct
4 Correct 755 ms 72388 KB Output is correct
5 Correct 748 ms 72132 KB Output is correct
6 Correct 623 ms 57796 KB Output is correct
7 Correct 654 ms 55876 KB Output is correct
8 Correct 92 ms 21368 KB Output is correct
9 Correct 639 ms 72384 KB Output is correct
10 Correct 673 ms 72132 KB Output is correct
11 Correct 628 ms 57920 KB Output is correct
12 Correct 819 ms 71236 KB Output is correct
13 Correct 601 ms 72516 KB Output is correct
14 Correct 607 ms 72260 KB Output is correct
15 Correct 558 ms 57796 KB Output is correct
16 Correct 520 ms 54556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19064 KB Output is correct
2 Correct 440 ms 56760 KB Output is correct
3 Correct 204 ms 57536 KB Output is correct
4 Correct 227 ms 57248 KB Output is correct
5 Correct 227 ms 47660 KB Output is correct
6 Correct 90 ms 27116 KB Output is correct
7 Correct 123 ms 31700 KB Output is correct
8 Correct 446 ms 63300 KB Output is correct
9 Correct 399 ms 55872 KB Output is correct
10 Correct 86 ms 27616 KB Output is correct
11 Correct 181 ms 38480 KB Output is correct
12 Correct 439 ms 56896 KB Output is correct
13 Correct 204 ms 57536 KB Output is correct
14 Correct 226 ms 57160 KB Output is correct
15 Correct 224 ms 47812 KB Output is correct
16 Correct 75 ms 25824 KB Output is correct
17 Correct 153 ms 35412 KB Output is correct
18 Correct 416 ms 66448 KB Output is correct
19 Correct 286 ms 53316 KB Output is correct
20 Correct 348 ms 57796 KB Output is correct
21 Correct 434 ms 63224 KB Output is correct
22 Correct 399 ms 56132 KB Output is correct
23 Correct 89 ms 27744 KB Output is correct
24 Correct 182 ms 38604 KB Output is correct
25 Correct 436 ms 56924 KB Output is correct
26 Correct 202 ms 57672 KB Output is correct
27 Correct 231 ms 57284 KB Output is correct
28 Correct 224 ms 47684 KB Output is correct
29 Correct 75 ms 25952 KB Output is correct
30 Correct 154 ms 35428 KB Output is correct
31 Correct 417 ms 66612 KB Output is correct
32 Correct 295 ms 53444 KB Output is correct
33 Correct 354 ms 57920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 24 ms 19576 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 22 ms 19320 KB Output is correct
5 Correct 26 ms 19704 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 18 ms 19064 KB Output is correct
9 Correct 19 ms 19064 KB Output is correct
10 Correct 20 ms 19064 KB Output is correct
11 Correct 30 ms 19320 KB Output is correct
12 Correct 23 ms 19448 KB Output is correct
13 Correct 27 ms 19832 KB Output is correct
14 Correct 29 ms 20084 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 19 ms 19064 KB Output is correct
18 Correct 1221 ms 43320 KB Output is correct
19 Correct 316 ms 22116 KB Output is correct
20 Correct 244 ms 20856 KB Output is correct
21 Correct 275 ms 21112 KB Output is correct
22 Correct 303 ms 21240 KB Output is correct
23 Correct 296 ms 21880 KB Output is correct
24 Correct 290 ms 20856 KB Output is correct
25 Correct 313 ms 21240 KB Output is correct
26 Correct 326 ms 21368 KB Output is correct
27 Correct 472 ms 40148 KB Output is correct
28 Correct 382 ms 30176 KB Output is correct
29 Correct 432 ms 37204 KB Output is correct
30 Correct 1109 ms 67936 KB Output is correct
31 Correct 23 ms 19192 KB Output is correct
32 Correct 801 ms 42324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Correct 24 ms 19576 KB Output is correct
3 Correct 21 ms 19320 KB Output is correct
4 Correct 22 ms 19320 KB Output is correct
5 Correct 26 ms 19704 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 19 ms 19064 KB Output is correct
8 Correct 18 ms 19064 KB Output is correct
9 Correct 19 ms 19064 KB Output is correct
10 Correct 20 ms 19064 KB Output is correct
11 Correct 30 ms 19320 KB Output is correct
12 Correct 23 ms 19448 KB Output is correct
13 Correct 27 ms 19832 KB Output is correct
14 Correct 29 ms 20084 KB Output is correct
15 Correct 19 ms 19064 KB Output is correct
16 Correct 18 ms 19064 KB Output is correct
17 Correct 19 ms 19064 KB Output is correct
18 Correct 1221 ms 43320 KB Output is correct
19 Correct 316 ms 22116 KB Output is correct
20 Correct 244 ms 20856 KB Output is correct
21 Correct 275 ms 21112 KB Output is correct
22 Correct 303 ms 21240 KB Output is correct
23 Correct 296 ms 21880 KB Output is correct
24 Correct 290 ms 20856 KB Output is correct
25 Correct 313 ms 21240 KB Output is correct
26 Correct 326 ms 21368 KB Output is correct
27 Correct 472 ms 40148 KB Output is correct
28 Correct 382 ms 30176 KB Output is correct
29 Correct 432 ms 37204 KB Output is correct
30 Correct 1109 ms 67936 KB Output is correct
31 Correct 23 ms 19192 KB Output is correct
32 Correct 801 ms 42324 KB Output is correct
33 Correct 440 ms 56760 KB Output is correct
34 Correct 204 ms 57536 KB Output is correct
35 Correct 227 ms 57248 KB Output is correct
36 Correct 227 ms 47660 KB Output is correct
37 Correct 90 ms 27116 KB Output is correct
38 Correct 123 ms 31700 KB Output is correct
39 Correct 446 ms 63300 KB Output is correct
40 Correct 399 ms 55872 KB Output is correct
41 Correct 86 ms 27616 KB Output is correct
42 Correct 181 ms 38480 KB Output is correct
43 Correct 439 ms 56896 KB Output is correct
44 Correct 204 ms 57536 KB Output is correct
45 Correct 226 ms 57160 KB Output is correct
46 Correct 224 ms 47812 KB Output is correct
47 Correct 75 ms 25824 KB Output is correct
48 Correct 153 ms 35412 KB Output is correct
49 Correct 416 ms 66448 KB Output is correct
50 Correct 286 ms 53316 KB Output is correct
51 Correct 348 ms 57796 KB Output is correct
52 Correct 434 ms 63224 KB Output is correct
53 Correct 399 ms 56132 KB Output is correct
54 Correct 89 ms 27744 KB Output is correct
55 Correct 182 ms 38604 KB Output is correct
56 Correct 436 ms 56924 KB Output is correct
57 Correct 202 ms 57672 KB Output is correct
58 Correct 231 ms 57284 KB Output is correct
59 Correct 224 ms 47684 KB Output is correct
60 Correct 75 ms 25952 KB Output is correct
61 Correct 154 ms 35428 KB Output is correct
62 Correct 417 ms 66612 KB Output is correct
63 Correct 295 ms 53444 KB Output is correct
64 Correct 354 ms 57920 KB Output is correct
65 Correct 811 ms 64504 KB Output is correct
66 Correct 841 ms 57156 KB Output is correct
67 Correct 413 ms 28768 KB Output is correct
68 Correct 544 ms 39636 KB Output is correct
69 Correct 796 ms 57796 KB Output is correct
70 Correct 872 ms 58692 KB Output is correct
71 Correct 693 ms 58436 KB Output is correct
72 Correct 642 ms 48964 KB Output is correct
73 Correct 280 ms 26848 KB Output is correct
74 Correct 402 ms 36436 KB Output is correct
75 Correct 707 ms 67584 KB Output is correct
76 Correct 844 ms 54208 KB Output is correct
77 Correct 688 ms 58728 KB Output is correct
78 Correct 507 ms 50132 KB Output is correct
79 Correct 755 ms 72388 KB Output is correct
80 Correct 748 ms 72132 KB Output is correct
81 Correct 623 ms 57796 KB Output is correct
82 Correct 654 ms 55876 KB Output is correct
83 Correct 92 ms 21368 KB Output is correct
84 Correct 639 ms 72384 KB Output is correct
85 Correct 673 ms 72132 KB Output is correct
86 Correct 628 ms 57920 KB Output is correct
87 Correct 819 ms 71236 KB Output is correct
88 Correct 601 ms 72516 KB Output is correct
89 Correct 607 ms 72260 KB Output is correct
90 Correct 558 ms 57796 KB Output is correct
91 Correct 520 ms 54556 KB Output is correct