답안 #258601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258601 2020-08-06T08:25:00 Z Mercenary 무지개나라 (APIO17_rainbow) C++14
100 / 100
1134 ms 68952 KB
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair

using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int maxn = 2e5 + 5;

struct BIT{
    vector<int> s[maxn];
    void init(){
        for(int i = maxn - 1 ; i >= 1 ; --i){
            sort(s[i].begin(),s[i].end());
            s[i].erase(unique(s[i].begin(),s[i].end()),s[i].end());
            for(int x = i + (i & -i) ; x < maxn ; x += x & -x){
                for(auto &c : s[i])s[x].pb(c);
            }
        }
        for(int i = 1 ; i < maxn ; ++i)sort(s[i].begin(),s[i].end());
    }
    void add(int x , int y){s[x].pb(y);}
    int query(int l , int r , int L , int R){
        if(L > R || l > r)return 0;
        int res = 0;
        for(int x = l - 1 ; x > 0 ; x &= x - 1){
            res -= upper_bound(s[x].begin(),s[x].end(),R) - lower_bound(s[x].begin(),s[x].end(),L);
        }
        for(int x = r ; x > 0 ; x &= x - 1){
            res += upper_bound(s[x].begin(),s[x].end(),R) - lower_bound(s[x].begin(),s[x].end(),L);
        }
        return res;
    }
}vertical , horizontal , vertices , rivers;

int mx_r, mn_r, mx_c, mn_c;
void add(int x, int y) {
    vertices.add(x, y);
    vertices.add(x + 1, y);
    vertices.add(x, y + 1);
    vertices.add(x + 1, y + 1);
    horizontal.add(x, y);
    horizontal.add(x + 1, y);
    vertical.add(x, y);
    vertical.add(x, y + 1);
    rivers.add(x, y);
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    mx_r = mn_r = sr;
    mx_c = mn_c = sc;
    add(sr,sc);
    for(int i = 0 ; i < M ; ++i){
        if (S[i] == 'N') sr--;
        if (S[i] == 'E') sc++;
        if (S[i] == 'S') sr++;
        if (S[i] == 'W') sc--;
        add(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);
    }
    vertical.init();horizontal.init();vertices.init();rivers.init();

}

int colour(int ar, int ac, int br, int bc) {
    int E = horizontal.query(ar + 1, br, ac, bc) + vertical.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;
}

#ifdef LOCAL

static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}

#endif // LOCAL

# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 19200 KB Output is correct
2 Correct 34 ms 19584 KB Output is correct
3 Correct 31 ms 19320 KB Output is correct
4 Correct 31 ms 19320 KB Output is correct
5 Correct 34 ms 19704 KB Output is correct
6 Correct 33 ms 19200 KB Output is correct
7 Correct 28 ms 19072 KB Output is correct
8 Correct 28 ms 19200 KB Output is correct
9 Correct 28 ms 19200 KB Output is correct
10 Correct 27 ms 19072 KB Output is correct
11 Correct 31 ms 19320 KB Output is correct
12 Correct 33 ms 19448 KB Output is correct
13 Correct 35 ms 19832 KB Output is correct
14 Correct 37 ms 20088 KB Output is correct
15 Correct 29 ms 19072 KB Output is correct
16 Correct 28 ms 19192 KB Output is correct
17 Correct 27 ms 19072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 19192 KB Output is correct
2 Correct 27 ms 19072 KB Output is correct
3 Correct 537 ms 48744 KB Output is correct
4 Correct 784 ms 68952 KB Output is correct
5 Correct 792 ms 68436 KB Output is correct
6 Correct 678 ms 65624 KB Output is correct
7 Correct 661 ms 61900 KB Output is correct
8 Correct 116 ms 27104 KB Output is correct
9 Correct 796 ms 68876 KB Output is correct
10 Correct 771 ms 68440 KB Output is correct
11 Correct 710 ms 65624 KB Output is correct
12 Correct 691 ms 67040 KB Output is correct
13 Correct 672 ms 68824 KB Output is correct
14 Correct 710 ms 68184 KB Output is correct
15 Correct 626 ms 65636 KB Output is correct
16 Correct 590 ms 61528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 19072 KB Output is correct
2 Correct 397 ms 44884 KB Output is correct
3 Correct 193 ms 52076 KB Output is correct
4 Correct 222 ms 51804 KB Output is correct
5 Correct 303 ms 43612 KB Output is correct
6 Correct 103 ms 28408 KB Output is correct
7 Correct 130 ms 30444 KB Output is correct
8 Correct 535 ms 61628 KB Output is correct
9 Correct 468 ms 59204 KB Output is correct
10 Correct 104 ms 26192 KB Output is correct
11 Correct 193 ms 35672 KB Output is correct
12 Correct 401 ms 44880 KB Output is correct
13 Correct 222 ms 52072 KB Output is correct
14 Correct 238 ms 51804 KB Output is correct
15 Correct 217 ms 43484 KB Output is correct
16 Correct 97 ms 27516 KB Output is correct
17 Correct 161 ms 34152 KB Output is correct
18 Correct 387 ms 59196 KB Output is correct
19 Correct 332 ms 49112 KB Output is correct
20 Correct 402 ms 52696 KB Output is correct
21 Correct 524 ms 61620 KB Output is correct
22 Correct 468 ms 59204 KB Output is correct
23 Correct 102 ms 26188 KB Output is correct
24 Correct 195 ms 35812 KB Output is correct
25 Correct 400 ms 44888 KB Output is correct
26 Correct 189 ms 52072 KB Output is correct
27 Correct 209 ms 51616 KB Output is correct
28 Correct 223 ms 43604 KB Output is correct
29 Correct 96 ms 27512 KB Output is correct
30 Correct 162 ms 34260 KB Output is correct
31 Correct 402 ms 59388 KB Output is correct
32 Correct 337 ms 49112 KB Output is correct
33 Correct 410 ms 52696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 19200 KB Output is correct
2 Correct 34 ms 19584 KB Output is correct
3 Correct 31 ms 19320 KB Output is correct
4 Correct 31 ms 19320 KB Output is correct
5 Correct 34 ms 19704 KB Output is correct
6 Correct 33 ms 19200 KB Output is correct
7 Correct 28 ms 19072 KB Output is correct
8 Correct 28 ms 19200 KB Output is correct
9 Correct 28 ms 19200 KB Output is correct
10 Correct 27 ms 19072 KB Output is correct
11 Correct 31 ms 19320 KB Output is correct
12 Correct 33 ms 19448 KB Output is correct
13 Correct 35 ms 19832 KB Output is correct
14 Correct 37 ms 20088 KB Output is correct
15 Correct 29 ms 19072 KB Output is correct
16 Correct 28 ms 19192 KB Output is correct
17 Correct 27 ms 19072 KB Output is correct
18 Correct 1134 ms 43628 KB Output is correct
19 Correct 314 ms 23928 KB Output is correct
20 Correct 243 ms 22908 KB Output is correct
21 Correct 283 ms 23056 KB Output is correct
22 Correct 309 ms 23160 KB Output is correct
23 Correct 305 ms 23932 KB Output is correct
24 Correct 296 ms 23032 KB Output is correct
25 Correct 309 ms 23416 KB Output is correct
26 Correct 324 ms 23416 KB Output is correct
27 Correct 458 ms 40000 KB Output is correct
28 Correct 397 ms 33540 KB Output is correct
29 Correct 458 ms 38372 KB Output is correct
30 Correct 1004 ms 62596 KB Output is correct
31 Correct 35 ms 19304 KB Output is correct
32 Correct 777 ms 41800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 19200 KB Output is correct
2 Correct 34 ms 19584 KB Output is correct
3 Correct 31 ms 19320 KB Output is correct
4 Correct 31 ms 19320 KB Output is correct
5 Correct 34 ms 19704 KB Output is correct
6 Correct 33 ms 19200 KB Output is correct
7 Correct 28 ms 19072 KB Output is correct
8 Correct 28 ms 19200 KB Output is correct
9 Correct 28 ms 19200 KB Output is correct
10 Correct 27 ms 19072 KB Output is correct
11 Correct 31 ms 19320 KB Output is correct
12 Correct 33 ms 19448 KB Output is correct
13 Correct 35 ms 19832 KB Output is correct
14 Correct 37 ms 20088 KB Output is correct
15 Correct 29 ms 19072 KB Output is correct
16 Correct 28 ms 19192 KB Output is correct
17 Correct 27 ms 19072 KB Output is correct
18 Correct 1134 ms 43628 KB Output is correct
19 Correct 314 ms 23928 KB Output is correct
20 Correct 243 ms 22908 KB Output is correct
21 Correct 283 ms 23056 KB Output is correct
22 Correct 309 ms 23160 KB Output is correct
23 Correct 305 ms 23932 KB Output is correct
24 Correct 296 ms 23032 KB Output is correct
25 Correct 309 ms 23416 KB Output is correct
26 Correct 324 ms 23416 KB Output is correct
27 Correct 458 ms 40000 KB Output is correct
28 Correct 397 ms 33540 KB Output is correct
29 Correct 458 ms 38372 KB Output is correct
30 Correct 1004 ms 62596 KB Output is correct
31 Correct 35 ms 19304 KB Output is correct
32 Correct 777 ms 41800 KB Output is correct
33 Correct 397 ms 44884 KB Output is correct
34 Correct 193 ms 52076 KB Output is correct
35 Correct 222 ms 51804 KB Output is correct
36 Correct 303 ms 43612 KB Output is correct
37 Correct 103 ms 28408 KB Output is correct
38 Correct 130 ms 30444 KB Output is correct
39 Correct 535 ms 61628 KB Output is correct
40 Correct 468 ms 59204 KB Output is correct
41 Correct 104 ms 26192 KB Output is correct
42 Correct 193 ms 35672 KB Output is correct
43 Correct 401 ms 44880 KB Output is correct
44 Correct 222 ms 52072 KB Output is correct
45 Correct 238 ms 51804 KB Output is correct
46 Correct 217 ms 43484 KB Output is correct
47 Correct 97 ms 27516 KB Output is correct
48 Correct 161 ms 34152 KB Output is correct
49 Correct 387 ms 59196 KB Output is correct
50 Correct 332 ms 49112 KB Output is correct
51 Correct 402 ms 52696 KB Output is correct
52 Correct 524 ms 61620 KB Output is correct
53 Correct 468 ms 59204 KB Output is correct
54 Correct 102 ms 26188 KB Output is correct
55 Correct 195 ms 35812 KB Output is correct
56 Correct 400 ms 44888 KB Output is correct
57 Correct 189 ms 52072 KB Output is correct
58 Correct 209 ms 51616 KB Output is correct
59 Correct 223 ms 43604 KB Output is correct
60 Correct 96 ms 27512 KB Output is correct
61 Correct 162 ms 34260 KB Output is correct
62 Correct 402 ms 59388 KB Output is correct
63 Correct 337 ms 49112 KB Output is correct
64 Correct 410 ms 52696 KB Output is correct
65 Correct 923 ms 65140 KB Output is correct
66 Correct 916 ms 62792 KB Output is correct
67 Correct 404 ms 29776 KB Output is correct
68 Correct 529 ms 39260 KB Output is correct
69 Correct 694 ms 48360 KB Output is correct
70 Correct 702 ms 55788 KB Output is correct
71 Correct 586 ms 55296 KB Output is correct
72 Correct 572 ms 47196 KB Output is correct
73 Correct 271 ms 31096 KB Output is correct
74 Correct 374 ms 37864 KB Output is correct
75 Correct 638 ms 62712 KB Output is correct
76 Correct 806 ms 52696 KB Output is correct
77 Correct 740 ms 56056 KB Output is correct
78 Correct 537 ms 48744 KB Output is correct
79 Correct 784 ms 68952 KB Output is correct
80 Correct 792 ms 68436 KB Output is correct
81 Correct 678 ms 65624 KB Output is correct
82 Correct 661 ms 61900 KB Output is correct
83 Correct 116 ms 27104 KB Output is correct
84 Correct 796 ms 68876 KB Output is correct
85 Correct 771 ms 68440 KB Output is correct
86 Correct 710 ms 65624 KB Output is correct
87 Correct 691 ms 67040 KB Output is correct
88 Correct 672 ms 68824 KB Output is correct
89 Correct 710 ms 68184 KB Output is correct
90 Correct 626 ms 65636 KB Output is correct
91 Correct 590 ms 61528 KB Output is correct