답안 #776010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776010 2023-07-07T08:29:27 Z Trisanu_Das 무지개나라 (APIO17_rainbow) C++17
100 / 100
1006 ms 205568 KB
#include "rainbow.h"
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC target("sse4,avx2,fma,avx")
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;

const int MAXN = 2e5, MAXSEG = (6e5 + 9) * 19 + 1;

int cnt = 1, segtree[MAXSEG], left_c[MAXSEG], right_c[MAXSEG];

struct Segtree {
    set<int> data[MAXN + 1];
    int roots[MAXN + 2];

    void add(int x, int y) { data[x].insert(y); }

    void build() {
        FOR(i, 1, MAXN + 1) {
            roots[i + 1] = roots[i];
            for (int j : data[i]) update(j, roots[i + 1]);
        }
    }

    void update(int pos, int &node, int l = 1, int r = MAXN) {
        segtree[cnt] = segtree[node] + 1;
        left_c[cnt] = left_c[node];
        right_c[cnt] = right_c[node];
        node = cnt++;

        if (l == r) return;
        int mid = (l + r) / 2;
        if (pos > mid) update(pos, right_c[node], mid + 1, r);
        else update(pos, left_c[node], l, mid);
    }

    int query(int l1, int r1, int l2, int r2) {
        if (l2 > r2) return 0;
        return query(l2, r2, roots[r1 + 1], 1, MAXN) - query(l2, r2, roots[l1], 1, MAXN);
    }
    int query(int a, int b, int node, int l, int r) {
        if (a > r || b < l) return 0;
        if (a <= l && b >= r) return segtree[node];
        int mid = (l + r) / 2;
        return query(a, b, left_c[node], l, mid) + query(a, b, right_c[node], mid + 1, r);
    }
} vertices, edges_horiz, edges_vert, rivers;

int mx_r, mn_r, mx_c, mn_c;
 
void add_river(int x, int y) {
    vertices.add(x, y);
    vertices.add(x + 1, y);
    vertices.add(x, y + 1);
    vertices.add(x + 1, y + 1);
    edges_horiz.add(x, y);
    edges_horiz.add(x + 1, y);
    edges_vert.add(x, y);
    edges_vert.add(x, y + 1);
    rivers.add(x, y);
}
 
void init(int R, int C, int sr, int sc, int M, char *S) {
    add_river(sr, sc);
    mx_r = mn_r = sr;
    mx_c = mn_c = sc;
    FOR(i, 0, M) {
        if (S[i] == 'N') sr--;
        if (S[i] == 'E') sc++;
        if (S[i] == 'S') sr++;
        if (S[i] == 'W') sc--;
        add_river(sr, sc);
        mx_r = max(mx_r, sr);
        mn_r = min(mn_r, sr);
        mx_c = max(mx_c, sc);
        mn_c = min(mn_c, sc);
    }
    vertices.build();
    edges_horiz.build();
    edges_vert.build();
    rivers.build();
}
 
int colour(int ar, int ac, int br, int bc) {
    int E = edges_horiz.query(ar + 1, br, ac, bc) + edges_vert.query(ar, br, ac + 1, bc);
    int V = vertices.query(ar + 1, br, ac + 1, bc);
    int R = rivers.query(ar, br, ac, bc);
    int C = (ar >= mn_r || br <= mx_r || ac >= mn_c || bc <= mx_c ? 1 : 2);
    return E - V + C - R;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 41292 KB Output is correct
2 Correct 24 ms 42328 KB Output is correct
3 Correct 23 ms 41368 KB Output is correct
4 Correct 22 ms 41392 KB Output is correct
5 Correct 24 ms 42596 KB Output is correct
6 Correct 21 ms 40960 KB Output is correct
7 Correct 21 ms 40912 KB Output is correct
8 Correct 22 ms 41044 KB Output is correct
9 Correct 21 ms 41044 KB Output is correct
10 Correct 21 ms 41032 KB Output is correct
11 Correct 23 ms 41500 KB Output is correct
12 Correct 24 ms 42012 KB Output is correct
13 Correct 26 ms 43028 KB Output is correct
14 Correct 26 ms 43544 KB Output is correct
15 Correct 22 ms 40968 KB Output is correct
16 Correct 24 ms 41048 KB Output is correct
17 Correct 21 ms 41024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 41048 KB Output is correct
2 Correct 21 ms 41024 KB Output is correct
3 Correct 478 ms 139840 KB Output is correct
4 Correct 698 ms 204444 KB Output is correct
5 Correct 730 ms 203136 KB Output is correct
6 Correct 600 ms 166716 KB Output is correct
7 Correct 644 ms 164572 KB Output is correct
8 Correct 242 ms 44624 KB Output is correct
9 Correct 710 ms 204460 KB Output is correct
10 Correct 707 ms 203080 KB Output is correct
11 Correct 632 ms 166652 KB Output is correct
12 Correct 345 ms 193172 KB Output is correct
13 Correct 355 ms 204316 KB Output is correct
14 Correct 373 ms 203120 KB Output is correct
15 Correct 344 ms 166716 KB Output is correct
16 Correct 581 ms 157572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 40968 KB Output is correct
2 Correct 303 ms 200996 KB Output is correct
3 Correct 143 ms 198488 KB Output is correct
4 Correct 170 ms 201036 KB Output is correct
5 Correct 151 ms 159808 KB Output is correct
6 Correct 82 ms 71104 KB Output is correct
7 Correct 142 ms 101012 KB Output is correct
8 Correct 255 ms 183784 KB Output is correct
9 Correct 238 ms 167732 KB Output is correct
10 Correct 102 ms 72724 KB Output is correct
11 Correct 180 ms 119516 KB Output is correct
12 Correct 298 ms 201048 KB Output is correct
13 Correct 146 ms 198484 KB Output is correct
14 Correct 170 ms 200944 KB Output is correct
15 Correct 172 ms 159748 KB Output is correct
16 Correct 78 ms 65064 KB Output is correct
17 Correct 128 ms 100924 KB Output is correct
18 Correct 232 ms 200992 KB Output is correct
19 Correct 218 ms 202148 KB Output is correct
20 Correct 219 ms 202008 KB Output is correct
21 Correct 255 ms 183756 KB Output is correct
22 Correct 238 ms 167784 KB Output is correct
23 Correct 85 ms 72728 KB Output is correct
24 Correct 159 ms 119492 KB Output is correct
25 Correct 299 ms 201036 KB Output is correct
26 Correct 138 ms 198452 KB Output is correct
27 Correct 176 ms 200956 KB Output is correct
28 Correct 150 ms 159824 KB Output is correct
29 Correct 74 ms 64980 KB Output is correct
30 Correct 126 ms 100936 KB Output is correct
31 Correct 235 ms 200980 KB Output is correct
32 Correct 218 ms 202132 KB Output is correct
33 Correct 236 ms 202004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 41292 KB Output is correct
2 Correct 24 ms 42328 KB Output is correct
3 Correct 23 ms 41368 KB Output is correct
4 Correct 22 ms 41392 KB Output is correct
5 Correct 24 ms 42596 KB Output is correct
6 Correct 21 ms 40960 KB Output is correct
7 Correct 21 ms 40912 KB Output is correct
8 Correct 22 ms 41044 KB Output is correct
9 Correct 21 ms 41044 KB Output is correct
10 Correct 21 ms 41032 KB Output is correct
11 Correct 23 ms 41500 KB Output is correct
12 Correct 24 ms 42012 KB Output is correct
13 Correct 26 ms 43028 KB Output is correct
14 Correct 26 ms 43544 KB Output is correct
15 Correct 22 ms 40968 KB Output is correct
16 Correct 24 ms 41048 KB Output is correct
17 Correct 21 ms 41024 KB Output is correct
18 Correct 689 ms 125208 KB Output is correct
19 Correct 198 ms 48020 KB Output is correct
20 Correct 160 ms 45152 KB Output is correct
21 Correct 169 ms 45672 KB Output is correct
22 Correct 173 ms 46436 KB Output is correct
23 Correct 195 ms 47872 KB Output is correct
24 Correct 158 ms 45508 KB Output is correct
25 Correct 177 ms 46232 KB Output is correct
26 Correct 176 ms 46712 KB Output is correct
27 Correct 344 ms 109760 KB Output is correct
28 Correct 273 ms 75920 KB Output is correct
29 Correct 343 ms 104128 KB Output is correct
30 Correct 526 ms 204456 KB Output is correct
31 Correct 25 ms 41164 KB Output is correct
32 Correct 546 ms 110636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 41292 KB Output is correct
2 Correct 24 ms 42328 KB Output is correct
3 Correct 23 ms 41368 KB Output is correct
4 Correct 22 ms 41392 KB Output is correct
5 Correct 24 ms 42596 KB Output is correct
6 Correct 21 ms 40960 KB Output is correct
7 Correct 21 ms 40912 KB Output is correct
8 Correct 22 ms 41044 KB Output is correct
9 Correct 21 ms 41044 KB Output is correct
10 Correct 21 ms 41032 KB Output is correct
11 Correct 23 ms 41500 KB Output is correct
12 Correct 24 ms 42012 KB Output is correct
13 Correct 26 ms 43028 KB Output is correct
14 Correct 26 ms 43544 KB Output is correct
15 Correct 22 ms 40968 KB Output is correct
16 Correct 24 ms 41048 KB Output is correct
17 Correct 21 ms 41024 KB Output is correct
18 Correct 689 ms 125208 KB Output is correct
19 Correct 198 ms 48020 KB Output is correct
20 Correct 160 ms 45152 KB Output is correct
21 Correct 169 ms 45672 KB Output is correct
22 Correct 173 ms 46436 KB Output is correct
23 Correct 195 ms 47872 KB Output is correct
24 Correct 158 ms 45508 KB Output is correct
25 Correct 177 ms 46232 KB Output is correct
26 Correct 176 ms 46712 KB Output is correct
27 Correct 344 ms 109760 KB Output is correct
28 Correct 273 ms 75920 KB Output is correct
29 Correct 343 ms 104128 KB Output is correct
30 Correct 526 ms 204456 KB Output is correct
31 Correct 25 ms 41164 KB Output is correct
32 Correct 546 ms 110636 KB Output is correct
33 Correct 303 ms 200996 KB Output is correct
34 Correct 143 ms 198488 KB Output is correct
35 Correct 170 ms 201036 KB Output is correct
36 Correct 151 ms 159808 KB Output is correct
37 Correct 82 ms 71104 KB Output is correct
38 Correct 142 ms 101012 KB Output is correct
39 Correct 255 ms 183784 KB Output is correct
40 Correct 238 ms 167732 KB Output is correct
41 Correct 102 ms 72724 KB Output is correct
42 Correct 180 ms 119516 KB Output is correct
43 Correct 298 ms 201048 KB Output is correct
44 Correct 146 ms 198484 KB Output is correct
45 Correct 170 ms 200944 KB Output is correct
46 Correct 172 ms 159748 KB Output is correct
47 Correct 78 ms 65064 KB Output is correct
48 Correct 128 ms 100924 KB Output is correct
49 Correct 232 ms 200992 KB Output is correct
50 Correct 218 ms 202148 KB Output is correct
51 Correct 219 ms 202008 KB Output is correct
52 Correct 255 ms 183756 KB Output is correct
53 Correct 238 ms 167784 KB Output is correct
54 Correct 85 ms 72728 KB Output is correct
55 Correct 159 ms 119492 KB Output is correct
56 Correct 299 ms 201036 KB Output is correct
57 Correct 138 ms 198452 KB Output is correct
58 Correct 176 ms 200956 KB Output is correct
59 Correct 150 ms 159824 KB Output is correct
60 Correct 74 ms 64980 KB Output is correct
61 Correct 126 ms 100936 KB Output is correct
62 Correct 235 ms 200980 KB Output is correct
63 Correct 218 ms 202132 KB Output is correct
64 Correct 236 ms 202004 KB Output is correct
65 Correct 478 ms 139840 KB Output is correct
66 Correct 698 ms 204444 KB Output is correct
67 Correct 730 ms 203136 KB Output is correct
68 Correct 600 ms 166716 KB Output is correct
69 Correct 644 ms 164572 KB Output is correct
70 Correct 242 ms 44624 KB Output is correct
71 Correct 710 ms 204460 KB Output is correct
72 Correct 707 ms 203080 KB Output is correct
73 Correct 632 ms 166652 KB Output is correct
74 Correct 345 ms 193172 KB Output is correct
75 Correct 355 ms 204316 KB Output is correct
76 Correct 373 ms 203120 KB Output is correct
77 Correct 344 ms 166716 KB Output is correct
78 Correct 581 ms 157572 KB Output is correct
79 Correct 960 ms 187236 KB Output is correct
80 Correct 1006 ms 171340 KB Output is correct
81 Correct 357 ms 76136 KB Output is correct
82 Correct 438 ms 122972 KB Output is correct
83 Correct 648 ms 204544 KB Output is correct
84 Correct 429 ms 202052 KB Output is correct
85 Correct 527 ms 204492 KB Output is correct
86 Correct 432 ms 163256 KB Output is correct
87 Correct 296 ms 68520 KB Output is correct
88 Correct 346 ms 104468 KB Output is correct
89 Correct 455 ms 204588 KB Output is correct
90 Correct 591 ms 205568 KB Output is correct
91 Correct 507 ms 205452 KB Output is correct