답안 #911180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
911180 2024-01-18T14:45:33 Z lighton 무지개나라 (APIO17_rainbow) C++17
100 / 100
810 ms 272956 KB
#include "rainbow.h"
#include <bits/stdc++.h>
#define forf(i,a,b) for(int i = a; i<=b; i++)
using namespace std;
typedef long long ll;
int minr,maxr,minc,maxc;
struct Node{
    int v,l,r;
} def = {0,0,0};
struct ST{
    int row,col;
    vector<set<int> > S;
    vector<int> T;
    vector<int> root = {0};
    vector<Node> node = {def};
    void update(int now, int prv, int s, int e, int f, int x){
        if(s==e){node[now].v = node[prv].v+x; return;}
        int m = s+e>>1;
        if(f<=m){
            node[now].l = node.size(); node.push_back(def);
            node[now].r = node[prv].r;
            update(node[now].l,node[prv].l,s,m,f,x);
        }
        else{
            node[now].r = node.size(); node.push_back(def);
            node[now].l = node[prv].l;
            update(node[now].r,node[prv].r,m+1,e,f,x);
        }
        node[now].v = node[node[now].l].v + node[node[now].r].v;
    }
    int query(int now , int prv, int s, int e,int l ,int r){
        if(l<=s && e<=r) return node[now].v-node[prv].v;
        if(r<s || l>e) return 0;
        int m = s+e>>1;
        return query(node[now].l,node[prv].l,s,m,l,r)+query(node[now].r,node[prv].r,m+1,e,l,r);
    }

    void init(int R, int C){
        row = R+1;
        col = C+1;
        S.resize(row+1);
        T.resize(row+1);
    }
    void add(int R, int C){
        if(S[R].find(C) == S[R].end()) S[R].insert(C);
    }
    void process(){
        int now = 0;
        forf(i,1,row){
            for(int j : S[i]){
                now++;
                root.push_back(node.size());
                node.push_back(def);
                update(root[now],root[now-1],1,col,j,1);
            }
            T[i] = now;
        }
    }
    int query(int r1, int c1, int r2, int c2){
        int now = T[r2];
        int prv = T[r1-1];
        return query(root[now],root[prv],1,col,c1,c2);
    }
} F,V,Ex,Ey;

void mark(int row, int col){
    F.add(row,col);
    V.add(row,col); V.add(row+1,col); V.add(row,col+1); V.add(row+1,col+1);
    Ex.add(row,col);Ex.add(row+1,col);
    Ey.add(row,col); Ey.add(row,col+1);
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    int r,c;
    r=R;c=C;
    F.init(r,c);V.init(r,c);Ex.init(r,c);Ey.init(r,c);

    int row = sr, col =sc;
    minr = row; maxr = row; minc = col; maxc = col;
    mark(row,col);
    forf(i,0,M-1){
        if(S[i] == 'N') row--;
        if(S[i] == 'S') row++;
        if(S[i] == 'E') col++;
        if(S[i] == 'W') col--;
        mark(row,col);
        minr = min(minr,row); maxr = max(maxr,row);
        minc = min(minc,col); maxc = max(maxc,col);
    }

    F.process();V.process();Ex.process();Ey.process();
}

int colour(int ar, int ac, int br, int bc) {
    int f = F.query(ar,ac,br,bc);
    int v = V.query(ar+1,ac+1,br,bc);
    int ex = Ex.query(ar+1,ac,br,bc);
    int ey = Ey.query(ar,ac+1,br,bc);
    int p = 0;
    if(ar<minr && br>maxr && ac<minc && bc>maxc) p = 1;
    return 1-v+ex+ey-f+p;
}

Compilation message

rainbow.cpp: In member function 'void ST::update(int, int, int, int, int, int)':
rainbow.cpp:18:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |         int m = s+e>>1;
      |                 ~^~
rainbow.cpp: In member function 'int ST::query(int, int, int, int, int, int)':
rainbow.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |         int m = s+e>>1;
      |                 ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 3 ms 1364 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 4 ms 1012 KB Output is correct
13 Correct 3 ms 1596 KB Output is correct
14 Correct 5 ms 1880 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 421 ms 137016 KB Output is correct
4 Correct 627 ms 193432 KB Output is correct
5 Correct 647 ms 190288 KB Output is correct
6 Correct 582 ms 154968 KB Output is correct
7 Correct 638 ms 155172 KB Output is correct
8 Correct 151 ms 1108 KB Output is correct
9 Correct 692 ms 194036 KB Output is correct
10 Correct 736 ms 188972 KB Output is correct
11 Correct 699 ms 157604 KB Output is correct
12 Correct 520 ms 185420 KB Output is correct
13 Correct 509 ms 193024 KB Output is correct
14 Correct 533 ms 190640 KB Output is correct
15 Correct 503 ms 156772 KB Output is correct
16 Correct 550 ms 152416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 463 ms 234876 KB Output is correct
3 Correct 229 ms 267604 KB Output is correct
4 Correct 277 ms 255736 KB Output is correct
5 Correct 243 ms 226596 KB Output is correct
6 Correct 111 ms 86372 KB Output is correct
7 Correct 217 ms 132116 KB Output is correct
8 Correct 359 ms 162132 KB Output is correct
9 Correct 341 ms 147088 KB Output is correct
10 Correct 101 ms 52704 KB Output is correct
11 Correct 201 ms 118864 KB Output is correct
12 Correct 480 ms 232336 KB Output is correct
13 Correct 245 ms 268328 KB Output is correct
14 Correct 296 ms 257432 KB Output is correct
15 Correct 247 ms 227772 KB Output is correct
16 Correct 97 ms 70876 KB Output is correct
17 Correct 200 ms 128692 KB Output is correct
18 Correct 393 ms 257700 KB Output is correct
19 Correct 365 ms 258512 KB Output is correct
20 Correct 349 ms 257448 KB Output is correct
21 Correct 388 ms 162120 KB Output is correct
22 Correct 343 ms 145940 KB Output is correct
23 Correct 92 ms 53448 KB Output is correct
24 Correct 207 ms 121024 KB Output is correct
25 Correct 462 ms 233088 KB Output is correct
26 Correct 215 ms 265624 KB Output is correct
27 Correct 276 ms 256812 KB Output is correct
28 Correct 234 ms 227672 KB Output is correct
29 Correct 91 ms 71264 KB Output is correct
30 Correct 186 ms 129880 KB Output is correct
31 Correct 366 ms 257244 KB Output is correct
32 Correct 333 ms 258220 KB Output is correct
33 Correct 331 ms 259244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 3 ms 1364 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 4 ms 1012 KB Output is correct
13 Correct 3 ms 1596 KB Output is correct
14 Correct 5 ms 1880 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 484 ms 91072 KB Output is correct
19 Correct 107 ms 3956 KB Output is correct
20 Correct 82 ms 1676 KB Output is correct
21 Correct 86 ms 2044 KB Output is correct
22 Correct 92 ms 2352 KB Output is correct
23 Correct 105 ms 3900 KB Output is correct
24 Correct 78 ms 1864 KB Output is correct
25 Correct 86 ms 2324 KB Output is correct
26 Correct 92 ms 2636 KB Output is correct
27 Correct 287 ms 61244 KB Output is correct
28 Correct 186 ms 34500 KB Output is correct
29 Correct 280 ms 57228 KB Output is correct
30 Correct 519 ms 150820 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 308 ms 63664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 3 ms 1364 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 4 ms 1012 KB Output is correct
13 Correct 3 ms 1596 KB Output is correct
14 Correct 5 ms 1880 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 484 ms 91072 KB Output is correct
19 Correct 107 ms 3956 KB Output is correct
20 Correct 82 ms 1676 KB Output is correct
21 Correct 86 ms 2044 KB Output is correct
22 Correct 92 ms 2352 KB Output is correct
23 Correct 105 ms 3900 KB Output is correct
24 Correct 78 ms 1864 KB Output is correct
25 Correct 86 ms 2324 KB Output is correct
26 Correct 92 ms 2636 KB Output is correct
27 Correct 287 ms 61244 KB Output is correct
28 Correct 186 ms 34500 KB Output is correct
29 Correct 280 ms 57228 KB Output is correct
30 Correct 519 ms 150820 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 308 ms 63664 KB Output is correct
33 Correct 463 ms 234876 KB Output is correct
34 Correct 229 ms 267604 KB Output is correct
35 Correct 277 ms 255736 KB Output is correct
36 Correct 243 ms 226596 KB Output is correct
37 Correct 111 ms 86372 KB Output is correct
38 Correct 217 ms 132116 KB Output is correct
39 Correct 359 ms 162132 KB Output is correct
40 Correct 341 ms 147088 KB Output is correct
41 Correct 101 ms 52704 KB Output is correct
42 Correct 201 ms 118864 KB Output is correct
43 Correct 480 ms 232336 KB Output is correct
44 Correct 245 ms 268328 KB Output is correct
45 Correct 296 ms 257432 KB Output is correct
46 Correct 247 ms 227772 KB Output is correct
47 Correct 97 ms 70876 KB Output is correct
48 Correct 200 ms 128692 KB Output is correct
49 Correct 393 ms 257700 KB Output is correct
50 Correct 365 ms 258512 KB Output is correct
51 Correct 349 ms 257448 KB Output is correct
52 Correct 388 ms 162120 KB Output is correct
53 Correct 343 ms 145940 KB Output is correct
54 Correct 92 ms 53448 KB Output is correct
55 Correct 207 ms 121024 KB Output is correct
56 Correct 462 ms 233088 KB Output is correct
57 Correct 215 ms 265624 KB Output is correct
58 Correct 276 ms 256812 KB Output is correct
59 Correct 234 ms 227672 KB Output is correct
60 Correct 91 ms 71264 KB Output is correct
61 Correct 186 ms 129880 KB Output is correct
62 Correct 366 ms 257244 KB Output is correct
63 Correct 333 ms 258220 KB Output is correct
64 Correct 331 ms 259244 KB Output is correct
65 Correct 421 ms 137016 KB Output is correct
66 Correct 627 ms 193432 KB Output is correct
67 Correct 647 ms 190288 KB Output is correct
68 Correct 582 ms 154968 KB Output is correct
69 Correct 638 ms 155172 KB Output is correct
70 Correct 151 ms 1108 KB Output is correct
71 Correct 692 ms 194036 KB Output is correct
72 Correct 736 ms 188972 KB Output is correct
73 Correct 699 ms 157604 KB Output is correct
74 Correct 520 ms 185420 KB Output is correct
75 Correct 509 ms 193024 KB Output is correct
76 Correct 533 ms 190640 KB Output is correct
77 Correct 503 ms 156772 KB Output is correct
78 Correct 550 ms 152416 KB Output is correct
79 Correct 810 ms 165424 KB Output is correct
80 Correct 723 ms 149696 KB Output is correct
81 Correct 212 ms 55752 KB Output is correct
82 Correct 374 ms 122908 KB Output is correct
83 Correct 719 ms 235268 KB Output is correct
84 Correct 501 ms 272956 KB Output is correct
85 Correct 497 ms 259936 KB Output is correct
86 Correct 415 ms 230828 KB Output is correct
87 Correct 257 ms 71520 KB Output is correct
88 Correct 335 ms 133104 KB Output is correct
89 Correct 517 ms 259268 KB Output is correct
90 Correct 592 ms 263344 KB Output is correct
91 Correct 577 ms 262488 KB Output is correct