답안 #197339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197339 2020-01-20T12:41:43 Z stefdasca 무지개나라 (APIO17_rainbow) C++14
100 / 100
1438 ms 205848 KB
#include "rainbow.h"
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

const int maxsz = 2e7;

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

struct aint
{
    set<int> data[200002];
    int roots[200002];
    void add(int x, int y)
    {
        data[x].insert(y);
    }
    void build()
    {
        for(int i = 1; i <= 200000; ++i)
        {
            roots[i+1] = roots[i];
            for(set<int> ::iterator it = data[i].begin(); it != data[i].end(); ++it)
                update(*it, roots[i+1]);
        }
    }
    void update(int pos, int &node, int l = 1, int r = 200000)
    {
        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, 200000) - query(l2, r2, roots[l1], 1, 200000);
    }
    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 mxL, mnL = (1<<20), mxC, mnC = (1<<20);

void add_river(int L, int C)
{
    mxL = max(mxL, L);
    mxC = max(mxC, C);
    mnL = min(mnL, L);
    mnC = min(mnC, C);
    vertices.add(L, C);
    vertices.add(L + 1, C);
    vertices.add(L, C + 1);
    vertices.add(L + 1, C + 1);
    edges_horiz.add(L, C);
    edges_horiz.add(L + 1, C);
    edges_vert.add(L, C);
    edges_vert.add(L, C + 1);
    rivers.add(L, C);
}
void init(int R, int C, int sr, int sc, int M, char *S)
{
    add_river(sr, sc);
    for(int i = 0; i < M; ++i)
    {
        sr += (S[i] == 'S');
        sr -= (S[i] == 'N');
        sc += (S[i] == 'E');
        sc -= (S[i] == 'W');
        add_river(sr, 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;
    if(ar >= mnL || br <= mxL || ac >= mnC || bc <= mxC)
        C = 1;
    else
        C = 2;
    return E - V + C - R;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 41464 KB Output is correct
2 Correct 49 ms 42488 KB Output is correct
3 Correct 47 ms 41336 KB Output is correct
4 Correct 47 ms 41592 KB Output is correct
5 Correct 51 ms 42616 KB Output is correct
6 Correct 44 ms 41080 KB Output is correct
7 Correct 44 ms 41080 KB Output is correct
8 Correct 46 ms 41084 KB Output is correct
9 Correct 45 ms 41208 KB Output is correct
10 Correct 44 ms 41080 KB Output is correct
11 Correct 48 ms 41592 KB Output is correct
12 Correct 48 ms 42096 KB Output is correct
13 Correct 60 ms 43128 KB Output is correct
14 Correct 51 ms 43640 KB Output is correct
15 Correct 43 ms 41064 KB Output is correct
16 Correct 44 ms 41080 KB Output is correct
17 Correct 44 ms 41080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 41080 KB Output is correct
2 Correct 44 ms 41080 KB Output is correct
3 Correct 757 ms 140148 KB Output is correct
4 Correct 1083 ms 204536 KB Output is correct
5 Correct 1016 ms 203392 KB Output is correct
6 Correct 873 ms 166716 KB Output is correct
7 Correct 990 ms 164612 KB Output is correct
8 Correct 364 ms 44972 KB Output is correct
9 Correct 1114 ms 204720 KB Output is correct
10 Correct 1061 ms 203288 KB Output is correct
11 Correct 904 ms 167032 KB Output is correct
12 Correct 579 ms 193428 KB Output is correct
13 Correct 553 ms 204504 KB Output is correct
14 Correct 581 ms 203256 KB Output is correct
15 Correct 513 ms 166844 KB Output is correct
16 Correct 834 ms 157656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41064 KB Output is correct
2 Correct 555 ms 201088 KB Output is correct
3 Correct 275 ms 198600 KB Output is correct
4 Correct 305 ms 201152 KB Output is correct
5 Correct 282 ms 159828 KB Output is correct
6 Correct 137 ms 71164 KB Output is correct
7 Correct 242 ms 100984 KB Output is correct
8 Correct 413 ms 183908 KB Output is correct
9 Correct 392 ms 167988 KB Output is correct
10 Correct 155 ms 72824 KB Output is correct
11 Correct 279 ms 119644 KB Output is correct
12 Correct 534 ms 201100 KB Output is correct
13 Correct 273 ms 198572 KB Output is correct
14 Correct 301 ms 201080 KB Output is correct
15 Correct 277 ms 159864 KB Output is correct
16 Correct 134 ms 65176 KB Output is correct
17 Correct 225 ms 100984 KB Output is correct
18 Correct 427 ms 201208 KB Output is correct
19 Correct 412 ms 202188 KB Output is correct
20 Correct 391 ms 202108 KB Output is correct
21 Correct 421 ms 184032 KB Output is correct
22 Correct 422 ms 167620 KB Output is correct
23 Correct 154 ms 72824 KB Output is correct
24 Correct 282 ms 119492 KB Output is correct
25 Correct 530 ms 201148 KB Output is correct
26 Correct 271 ms 198512 KB Output is correct
27 Correct 304 ms 201208 KB Output is correct
28 Correct 281 ms 159864 KB Output is correct
29 Correct 131 ms 65212 KB Output is correct
30 Correct 271 ms 100972 KB Output is correct
31 Correct 414 ms 201176 KB Output is correct
32 Correct 387 ms 202232 KB Output is correct
33 Correct 389 ms 202240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 41464 KB Output is correct
2 Correct 49 ms 42488 KB Output is correct
3 Correct 47 ms 41336 KB Output is correct
4 Correct 47 ms 41592 KB Output is correct
5 Correct 51 ms 42616 KB Output is correct
6 Correct 44 ms 41080 KB Output is correct
7 Correct 44 ms 41080 KB Output is correct
8 Correct 46 ms 41084 KB Output is correct
9 Correct 45 ms 41208 KB Output is correct
10 Correct 44 ms 41080 KB Output is correct
11 Correct 48 ms 41592 KB Output is correct
12 Correct 48 ms 42096 KB Output is correct
13 Correct 60 ms 43128 KB Output is correct
14 Correct 51 ms 43640 KB Output is correct
15 Correct 43 ms 41064 KB Output is correct
16 Correct 44 ms 41080 KB Output is correct
17 Correct 44 ms 41080 KB Output is correct
18 Correct 940 ms 125668 KB Output is correct
19 Correct 320 ms 48120 KB Output is correct
20 Correct 251 ms 45340 KB Output is correct
21 Correct 273 ms 45816 KB Output is correct
22 Correct 290 ms 46584 KB Output is correct
23 Correct 323 ms 47988 KB Output is correct
24 Correct 259 ms 45668 KB Output is correct
25 Correct 288 ms 46300 KB Output is correct
26 Correct 293 ms 46852 KB Output is correct
27 Correct 564 ms 109848 KB Output is correct
28 Correct 439 ms 76144 KB Output is correct
29 Correct 561 ms 104320 KB Output is correct
30 Correct 896 ms 204840 KB Output is correct
31 Correct 49 ms 41208 KB Output is correct
32 Correct 935 ms 110808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 41464 KB Output is correct
2 Correct 49 ms 42488 KB Output is correct
3 Correct 47 ms 41336 KB Output is correct
4 Correct 47 ms 41592 KB Output is correct
5 Correct 51 ms 42616 KB Output is correct
6 Correct 44 ms 41080 KB Output is correct
7 Correct 44 ms 41080 KB Output is correct
8 Correct 46 ms 41084 KB Output is correct
9 Correct 45 ms 41208 KB Output is correct
10 Correct 44 ms 41080 KB Output is correct
11 Correct 48 ms 41592 KB Output is correct
12 Correct 48 ms 42096 KB Output is correct
13 Correct 60 ms 43128 KB Output is correct
14 Correct 51 ms 43640 KB Output is correct
15 Correct 43 ms 41064 KB Output is correct
16 Correct 44 ms 41080 KB Output is correct
17 Correct 44 ms 41080 KB Output is correct
18 Correct 940 ms 125668 KB Output is correct
19 Correct 320 ms 48120 KB Output is correct
20 Correct 251 ms 45340 KB Output is correct
21 Correct 273 ms 45816 KB Output is correct
22 Correct 290 ms 46584 KB Output is correct
23 Correct 323 ms 47988 KB Output is correct
24 Correct 259 ms 45668 KB Output is correct
25 Correct 288 ms 46300 KB Output is correct
26 Correct 293 ms 46852 KB Output is correct
27 Correct 564 ms 109848 KB Output is correct
28 Correct 439 ms 76144 KB Output is correct
29 Correct 561 ms 104320 KB Output is correct
30 Correct 896 ms 204840 KB Output is correct
31 Correct 49 ms 41208 KB Output is correct
32 Correct 935 ms 110808 KB Output is correct
33 Correct 555 ms 201088 KB Output is correct
34 Correct 275 ms 198600 KB Output is correct
35 Correct 305 ms 201152 KB Output is correct
36 Correct 282 ms 159828 KB Output is correct
37 Correct 137 ms 71164 KB Output is correct
38 Correct 242 ms 100984 KB Output is correct
39 Correct 413 ms 183908 KB Output is correct
40 Correct 392 ms 167988 KB Output is correct
41 Correct 155 ms 72824 KB Output is correct
42 Correct 279 ms 119644 KB Output is correct
43 Correct 534 ms 201100 KB Output is correct
44 Correct 273 ms 198572 KB Output is correct
45 Correct 301 ms 201080 KB Output is correct
46 Correct 277 ms 159864 KB Output is correct
47 Correct 134 ms 65176 KB Output is correct
48 Correct 225 ms 100984 KB Output is correct
49 Correct 427 ms 201208 KB Output is correct
50 Correct 412 ms 202188 KB Output is correct
51 Correct 391 ms 202108 KB Output is correct
52 Correct 421 ms 184032 KB Output is correct
53 Correct 422 ms 167620 KB Output is correct
54 Correct 154 ms 72824 KB Output is correct
55 Correct 282 ms 119492 KB Output is correct
56 Correct 530 ms 201148 KB Output is correct
57 Correct 271 ms 198512 KB Output is correct
58 Correct 304 ms 201208 KB Output is correct
59 Correct 281 ms 159864 KB Output is correct
60 Correct 131 ms 65212 KB Output is correct
61 Correct 271 ms 100972 KB Output is correct
62 Correct 414 ms 201176 KB Output is correct
63 Correct 387 ms 202232 KB Output is correct
64 Correct 389 ms 202240 KB Output is correct
65 Correct 1438 ms 187468 KB Output is correct
66 Correct 1374 ms 171488 KB Output is correct
67 Correct 585 ms 76380 KB Output is correct
68 Correct 696 ms 123144 KB Output is correct
69 Correct 1058 ms 204920 KB Output is correct
70 Correct 737 ms 202252 KB Output is correct
71 Correct 787 ms 204800 KB Output is correct
72 Correct 741 ms 163656 KB Output is correct
73 Correct 492 ms 68600 KB Output is correct
74 Correct 583 ms 104592 KB Output is correct
75 Correct 768 ms 204868 KB Output is correct
76 Correct 1060 ms 205848 KB Output is correct
77 Correct 808 ms 205704 KB Output is correct
78 Correct 757 ms 140148 KB Output is correct
79 Correct 1083 ms 204536 KB Output is correct
80 Correct 1016 ms 203392 KB Output is correct
81 Correct 873 ms 166716 KB Output is correct
82 Correct 990 ms 164612 KB Output is correct
83 Correct 364 ms 44972 KB Output is correct
84 Correct 1114 ms 204720 KB Output is correct
85 Correct 1061 ms 203288 KB Output is correct
86 Correct 904 ms 167032 KB Output is correct
87 Correct 579 ms 193428 KB Output is correct
88 Correct 553 ms 204504 KB Output is correct
89 Correct 581 ms 203256 KB Output is correct
90 Correct 513 ms 166844 KB Output is correct
91 Correct 834 ms 157656 KB Output is correct