답안 #218329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218329 2020-04-02T02:01:59 Z anonymous 무지개나라 (APIO17_rainbow) C++14
100 / 100
1170 ms 169724 KB
#include "rainbow.h"
#include <set>
#include <utility>
#include <iostream>
#define MAXN 200005
using namespace std;
 
class PersistentSegtree {
    int ST[MAXN*40][3], R[MAXN*2], X[MAXN*2];
    int V=1, P=1;
    int upd(int ind, int l, int r, int cur) {
        if (l > ind || ind > r) {return(cur);}
        if (l == r) {
            ST[V][0] = ST[cur][0] + 1, V++;
            return(V-1);
        } else {
            int mid = (l + r) >> 1, at = V;
            V++;
            ST[at][1] = upd(ind, l, mid, ST[cur][1]);
            ST[at][2] = upd(ind, mid+1, r, ST[cur][2]);
            ST[at][0] = ST[ST[at][1]][0] + ST[ST[at][2]][0];
            return(at);
        }
    }
    int ask(int lo, int hi, int l, int r, int cur) {
        if (l > hi || r < lo || cur == 0) {return(0);}
        else if (lo <= l && hi >= r) {return(ST[cur][0]);}
        else {
            int mid = (l + r) >> 1;
            return(ask(lo, hi, l, mid, ST[cur][1])+
                   ask(lo, hi, mid+1, r, ST[cur][2]));
        }
    }
public:
    void put(int x, int y) {
        X[P] = x;
        R[P] = upd(y, 1, MAXN, R[P-1]);
        P++;
    }
    int lb(int x) {
        int lo = 0, hi = P;
        while (lo + 1 != hi) {
            int mid = (lo + hi) >> 1;
            if (X[mid] > x) {hi = mid;}
            else {lo = mid;}
        }
        return(lo);
    }
    int ask(int xlo, int ylo, int xhi, int yhi) {
        if (xlo > xhi || ylo > yhi) {return(0);}
        int ql = lb(xlo-1), qr = lb(xhi);
        return(ask(ylo, yhi, 1, MAXN, R[qr])-
               ask(ylo, yhi, 1, MAXN, R[ql]));
    }
} rT, vT, hT, VT;
int R,C;
set<pair<int,int> > rS, vS, hS, VS;
 
void init(int r, int c, int sr, int sc, int M, char *S) {
    R = r, C = c;
    int x = sr, y = sc; //cur
    for (int i=0; i<=M; i++) {
        rS.insert({x, y}); //river
        vS.insert({x,y}); //lines
        vS.insert({x,y+1});
        hS.insert({x,y});
        hS.insert({x+1,y});
        VS.insert({x,y}); //vertex
        VS.insert({x+1,y});
        VS.insert({x,y+1});
        VS.insert({x+1,y+1});
        if (i == M) {break;}
        switch(S[i]) {
            case 'N':
                x--;
                break;
            case 'S':
                x++;
                break;
            case 'W':
                y--;
                break;
            case 'E':
                y++;
                break;
        }
    }
    for (auto p: rS) {
        rT.put(p.first,p.second);
    }
    for (auto p: vS) {
        vT.put(p.first,p.second);
    }
    for (auto p: hS) {
        hT.put(p.first,p.second);
    }
    for (auto p: VS) {
        VT.put(p.first,p.second);
    }
}
 
int colour(int ar, int ac, int br, int bc) {
    int V = VT.ask(ar+1, ac+1, br, bc); 
    int Fr = rT.ask(ar, ac, br, bc);
    int E = hT.ask(ar+1, ac, br, bc) + vT.ask(ar, ac+1, br, bc);
    int ans = E - V - Fr + 1;
    if (V == VS.size()) {ans+=1;}
    return(ans);
}

Compilation message

rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:107:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (V == VS.size()) {ans+=1;}
         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 10 ms 1792 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 8 ms 896 KB Output is correct
5 Correct 11 ms 2048 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 9 ms 1536 KB Output is correct
13 Correct 11 ms 2560 KB Output is correct
14 Correct 13 ms 3072 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 424 ms 99596 KB Output is correct
4 Correct 633 ms 166008 KB Output is correct
5 Correct 662 ms 164856 KB Output is correct
6 Correct 533 ms 127096 KB Output is correct
7 Correct 649 ms 124920 KB Output is correct
8 Correct 102 ms 1528 KB Output is correct
9 Correct 672 ms 165880 KB Output is correct
10 Correct 685 ms 164728 KB Output is correct
11 Correct 600 ms 127120 KB Output is correct
12 Correct 441 ms 154488 KB Output is correct
13 Correct 455 ms 166084 KB Output is correct
14 Correct 482 ms 164604 KB Output is correct
15 Correct 453 ms 127224 KB Output is correct
16 Correct 474 ms 117848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 412 ms 165368 KB Output is correct
3 Correct 365 ms 162680 KB Output is correct
4 Correct 382 ms 165240 KB Output is correct
5 Correct 296 ms 122744 KB Output is correct
6 Correct 127 ms 31352 KB Output is correct
7 Correct 221 ms 62048 KB Output is correct
8 Correct 379 ms 147548 KB Output is correct
9 Correct 363 ms 130936 KB Output is correct
10 Correct 111 ms 33016 KB Output is correct
11 Correct 237 ms 81200 KB Output is correct
12 Correct 411 ms 165112 KB Output is correct
13 Correct 361 ms 162680 KB Output is correct
14 Correct 378 ms 165240 KB Output is correct
15 Correct 292 ms 122748 KB Output is correct
16 Correct 116 ms 25208 KB Output is correct
17 Correct 208 ms 62212 KB Output is correct
18 Correct 353 ms 165228 KB Output is correct
19 Correct 389 ms 166264 KB Output is correct
20 Correct 389 ms 166136 KB Output is correct
21 Correct 387 ms 147376 KB Output is correct
22 Correct 357 ms 130936 KB Output is correct
23 Correct 112 ms 33016 KB Output is correct
24 Correct 236 ms 81312 KB Output is correct
25 Correct 408 ms 165112 KB Output is correct
26 Correct 362 ms 162680 KB Output is correct
27 Correct 376 ms 165112 KB Output is correct
28 Correct 290 ms 122744 KB Output is correct
29 Correct 114 ms 25212 KB Output is correct
30 Correct 202 ms 62072 KB Output is correct
31 Correct 354 ms 165240 KB Output is correct
32 Correct 389 ms 166140 KB Output is correct
33 Correct 392 ms 166136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 10 ms 1792 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 8 ms 896 KB Output is correct
5 Correct 11 ms 2048 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 9 ms 1536 KB Output is correct
13 Correct 11 ms 2560 KB Output is correct
14 Correct 13 ms 3072 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 1048 ms 84856 KB Output is correct
19 Correct 312 ms 5240 KB Output is correct
20 Correct 249 ms 2168 KB Output is correct
21 Correct 277 ms 2808 KB Output is correct
22 Correct 287 ms 3576 KB Output is correct
23 Correct 312 ms 5108 KB Output is correct
24 Correct 257 ms 2808 KB Output is correct
25 Correct 277 ms 3320 KB Output is correct
26 Correct 300 ms 4020 KB Output is correct
27 Correct 465 ms 68728 KB Output is correct
28 Correct 347 ms 33912 KB Output is correct
29 Correct 436 ms 62840 KB Output is correct
30 Correct 809 ms 166268 KB Output is correct
31 Correct 9 ms 640 KB Output is correct
32 Correct 782 ms 69624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 768 KB Output is correct
2 Correct 10 ms 1792 KB Output is correct
3 Correct 7 ms 768 KB Output is correct
4 Correct 8 ms 896 KB Output is correct
5 Correct 11 ms 2048 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 8 ms 1024 KB Output is correct
12 Correct 9 ms 1536 KB Output is correct
13 Correct 11 ms 2560 KB Output is correct
14 Correct 13 ms 3072 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 1048 ms 84856 KB Output is correct
19 Correct 312 ms 5240 KB Output is correct
20 Correct 249 ms 2168 KB Output is correct
21 Correct 277 ms 2808 KB Output is correct
22 Correct 287 ms 3576 KB Output is correct
23 Correct 312 ms 5108 KB Output is correct
24 Correct 257 ms 2808 KB Output is correct
25 Correct 277 ms 3320 KB Output is correct
26 Correct 300 ms 4020 KB Output is correct
27 Correct 465 ms 68728 KB Output is correct
28 Correct 347 ms 33912 KB Output is correct
29 Correct 436 ms 62840 KB Output is correct
30 Correct 809 ms 166268 KB Output is correct
31 Correct 9 ms 640 KB Output is correct
32 Correct 782 ms 69624 KB Output is correct
33 Correct 412 ms 165368 KB Output is correct
34 Correct 365 ms 162680 KB Output is correct
35 Correct 382 ms 165240 KB Output is correct
36 Correct 296 ms 122744 KB Output is correct
37 Correct 127 ms 31352 KB Output is correct
38 Correct 221 ms 62048 KB Output is correct
39 Correct 379 ms 147548 KB Output is correct
40 Correct 363 ms 130936 KB Output is correct
41 Correct 111 ms 33016 KB Output is correct
42 Correct 237 ms 81200 KB Output is correct
43 Correct 411 ms 165112 KB Output is correct
44 Correct 361 ms 162680 KB Output is correct
45 Correct 378 ms 165240 KB Output is correct
46 Correct 292 ms 122748 KB Output is correct
47 Correct 116 ms 25208 KB Output is correct
48 Correct 208 ms 62212 KB Output is correct
49 Correct 353 ms 165228 KB Output is correct
50 Correct 389 ms 166264 KB Output is correct
51 Correct 389 ms 166136 KB Output is correct
52 Correct 387 ms 147376 KB Output is correct
53 Correct 357 ms 130936 KB Output is correct
54 Correct 112 ms 33016 KB Output is correct
55 Correct 236 ms 81312 KB Output is correct
56 Correct 408 ms 165112 KB Output is correct
57 Correct 362 ms 162680 KB Output is correct
58 Correct 376 ms 165112 KB Output is correct
59 Correct 290 ms 122744 KB Output is correct
60 Correct 114 ms 25212 KB Output is correct
61 Correct 202 ms 62072 KB Output is correct
62 Correct 354 ms 165240 KB Output is correct
63 Correct 389 ms 166140 KB Output is correct
64 Correct 392 ms 166136 KB Output is correct
65 Correct 1154 ms 148472 KB Output is correct
66 Correct 1170 ms 131960 KB Output is correct
67 Correct 447 ms 34168 KB Output is correct
68 Correct 530 ms 82296 KB Output is correct
69 Correct 703 ms 166264 KB Output is correct
70 Correct 589 ms 166136 KB Output is correct
71 Correct 608 ms 168824 KB Output is correct
72 Correct 496 ms 126528 KB Output is correct
73 Correct 226 ms 28772 KB Output is correct
74 Correct 339 ms 65652 KB Output is correct
75 Correct 492 ms 168696 KB Output is correct
76 Correct 710 ms 169720 KB Output is correct
77 Correct 691 ms 169724 KB Output is correct
78 Correct 424 ms 99596 KB Output is correct
79 Correct 633 ms 166008 KB Output is correct
80 Correct 662 ms 164856 KB Output is correct
81 Correct 533 ms 127096 KB Output is correct
82 Correct 649 ms 124920 KB Output is correct
83 Correct 102 ms 1528 KB Output is correct
84 Correct 672 ms 165880 KB Output is correct
85 Correct 685 ms 164728 KB Output is correct
86 Correct 600 ms 127120 KB Output is correct
87 Correct 441 ms 154488 KB Output is correct
88 Correct 455 ms 166084 KB Output is correct
89 Correct 482 ms 164604 KB Output is correct
90 Correct 453 ms 127224 KB Output is correct
91 Correct 474 ms 117848 KB Output is correct