답안 #972824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972824 2024-05-01T08:34:41 Z bachhoangxuan 무지개나라 (APIO17_rainbow) C++17
100 / 100
684 ms 96468 KB
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int maxn = 2e5+5;

int R,C;

struct BIT{
    vector<int> com[maxn],pre[maxn];
    BIT(){}
    void update(int x,int y){
        for(int i=x;i<=R;i+=(i&(-i))) com[i].push_back(y);
    }
    void build(int x){
        sort(com[x].begin(),com[x].end());
        vector<int> cur=com[x];com[x].clear();
        for(int y:cur){
            if(com[x].empty() || com[x].back()!=y){
                com[x].push_back(y);
                pre[x].push_back(1);
            }
            else pre[x].back()++;
        }
        for(int i=1;i<(int)com[x].size();i++) pre[x][i]+=pre[x][i-1];
    }
    void init(vector<pii> &A){
        sort(A.begin(),A.end());
        A.erase(unique(A.begin(),A.end()),A.end());
        for(auto [x,y]:A) update(x,y);
        for(int i=1;i<=R;i++) build(i);
    }
    int query(int x,int y){
        int res=0;
        for(int i=x;i>=1;i-=(i&(-i))){
            int pos=upper_bound(com[i].begin(),com[i].end(),y)-com[i].begin()-1;
            res+=(pos<0?0:pre[i][pos]);
        }
        return res;
    }
    int get(int sx,int sy,int tx,int ty){
        return query(tx,ty)-query(tx,sy-1)-query(sx-1,ty)+query(sx-1,sy-1);
    }
}g,p,cc,rw;

void init(int _R, int _C, int x, int y, int M, char *S) {
    vector<pii> row,col,G,P;
    R=_R+1;C=_C+1;
    for(int i=0;i<=M;i++){
        G.push_back({x,y});
        for(int a=0;a<=1;a++) for(int b=0;b<=1;b++){
            P.push_back({x+a,y+b});
            if(!b) row.push_back({x+a,y+b});
            if(!a) col.push_back({x+a,y+b});
        }
        //cout << x << ' ' << y << '\n';
        if(i==M) break;
        if(S[i]=='N') x--;
        else if(S[i]=='S') x++;
        else if(S[i]=='W') y--;
        else y++;
    }
    g.init(G);p.init(P);
    rw.init(row);cc.init(col);
}

int colour(int ar, int ac, int br, int bc) {
    int V=p.get(ar+1,ac+1,br,bc);
    int E=rw.get(ar+1,ac,br,bc)+cc.get(ar,ac+1,br,bc);
    int total=g.get(ar,ac,br,bc),mid=0;
    if(ar+2<=br && ac+2<=bc) mid=g.get(ar+1,ac+1,br-1,bc-1);
    int CC=1;
    if(V>=1 && total==mid) CC++;
    //cout << E << ' ' << V << ' ' << CC << ' ' << total << '\n';
    return E-V+CC-total;
 }

# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 37976 KB Output is correct
2 Correct 13 ms 38312 KB Output is correct
3 Correct 10 ms 37980 KB Output is correct
4 Correct 11 ms 37980 KB Output is correct
5 Correct 13 ms 38332 KB Output is correct
6 Correct 11 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 10 ms 37980 KB Output is correct
11 Correct 11 ms 37980 KB Output is correct
12 Correct 12 ms 38236 KB Output is correct
13 Correct 13 ms 38232 KB Output is correct
14 Correct 13 ms 38492 KB Output is correct
15 Correct 9 ms 37980 KB Output is correct
16 Correct 9 ms 37976 KB Output is correct
17 Correct 9 ms 37992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37976 KB Output is correct
2 Correct 9 ms 37992 KB Output is correct
3 Correct 166 ms 48744 KB Output is correct
4 Correct 236 ms 54708 KB Output is correct
5 Correct 258 ms 54568 KB Output is correct
6 Correct 207 ms 52380 KB Output is correct
7 Correct 230 ms 52284 KB Output is correct
8 Correct 93 ms 47496 KB Output is correct
9 Correct 231 ms 54496 KB Output is correct
10 Correct 231 ms 54420 KB Output is correct
11 Correct 207 ms 52404 KB Output is correct
12 Correct 157 ms 53700 KB Output is correct
13 Correct 157 ms 54388 KB Output is correct
14 Correct 154 ms 54452 KB Output is correct
15 Correct 158 ms 52332 KB Output is correct
16 Correct 194 ms 52192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37980 KB Output is correct
2 Correct 355 ms 89600 KB Output is correct
3 Correct 179 ms 89016 KB Output is correct
4 Correct 194 ms 94228 KB Output is correct
5 Correct 188 ms 78520 KB Output is correct
6 Correct 107 ms 52664 KB Output is correct
7 Correct 135 ms 57228 KB Output is correct
8 Correct 107 ms 55224 KB Output is correct
9 Correct 119 ms 54968 KB Output is correct
10 Correct 57 ms 43972 KB Output is correct
11 Correct 102 ms 51824 KB Output is correct
12 Correct 358 ms 89636 KB Output is correct
13 Correct 172 ms 88812 KB Output is correct
14 Correct 191 ms 94092 KB Output is correct
15 Correct 188 ms 78520 KB Output is correct
16 Correct 107 ms 51896 KB Output is correct
17 Correct 158 ms 59528 KB Output is correct
18 Correct 354 ms 89104 KB Output is correct
19 Correct 263 ms 89268 KB Output is correct
20 Correct 314 ms 95612 KB Output is correct
21 Correct 108 ms 54704 KB Output is correct
22 Correct 120 ms 54708 KB Output is correct
23 Correct 58 ms 43968 KB Output is correct
24 Correct 102 ms 51932 KB Output is correct
25 Correct 352 ms 89788 KB Output is correct
26 Correct 172 ms 88836 KB Output is correct
27 Correct 186 ms 94080 KB Output is correct
28 Correct 190 ms 78776 KB Output is correct
29 Correct 107 ms 51384 KB Output is correct
30 Correct 161 ms 59776 KB Output is correct
31 Correct 347 ms 90036 KB Output is correct
32 Correct 263 ms 89268 KB Output is correct
33 Correct 309 ms 96468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 37976 KB Output is correct
2 Correct 13 ms 38312 KB Output is correct
3 Correct 10 ms 37980 KB Output is correct
4 Correct 11 ms 37980 KB Output is correct
5 Correct 13 ms 38332 KB Output is correct
6 Correct 11 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 10 ms 37980 KB Output is correct
11 Correct 11 ms 37980 KB Output is correct
12 Correct 12 ms 38236 KB Output is correct
13 Correct 13 ms 38232 KB Output is correct
14 Correct 13 ms 38492 KB Output is correct
15 Correct 9 ms 37980 KB Output is correct
16 Correct 9 ms 37976 KB Output is correct
17 Correct 9 ms 37992 KB Output is correct
18 Correct 505 ms 55572 KB Output is correct
19 Correct 219 ms 41964 KB Output is correct
20 Correct 157 ms 41512 KB Output is correct
21 Correct 176 ms 41584 KB Output is correct
22 Correct 194 ms 41840 KB Output is correct
23 Correct 211 ms 41780 KB Output is correct
24 Correct 185 ms 41560 KB Output is correct
25 Correct 213 ms 41964 KB Output is correct
26 Correct 203 ms 41948 KB Output is correct
27 Correct 269 ms 52764 KB Output is correct
28 Correct 256 ms 50472 KB Output is correct
29 Correct 258 ms 52304 KB Output is correct
30 Correct 421 ms 67180 KB Output is correct
31 Correct 11 ms 37980 KB Output is correct
32 Correct 446 ms 54256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 37976 KB Output is correct
2 Correct 13 ms 38312 KB Output is correct
3 Correct 10 ms 37980 KB Output is correct
4 Correct 11 ms 37980 KB Output is correct
5 Correct 13 ms 38332 KB Output is correct
6 Correct 11 ms 37980 KB Output is correct
7 Correct 9 ms 37980 KB Output is correct
8 Correct 9 ms 37980 KB Output is correct
9 Correct 9 ms 37980 KB Output is correct
10 Correct 10 ms 37980 KB Output is correct
11 Correct 11 ms 37980 KB Output is correct
12 Correct 12 ms 38236 KB Output is correct
13 Correct 13 ms 38232 KB Output is correct
14 Correct 13 ms 38492 KB Output is correct
15 Correct 9 ms 37980 KB Output is correct
16 Correct 9 ms 37976 KB Output is correct
17 Correct 9 ms 37992 KB Output is correct
18 Correct 505 ms 55572 KB Output is correct
19 Correct 219 ms 41964 KB Output is correct
20 Correct 157 ms 41512 KB Output is correct
21 Correct 176 ms 41584 KB Output is correct
22 Correct 194 ms 41840 KB Output is correct
23 Correct 211 ms 41780 KB Output is correct
24 Correct 185 ms 41560 KB Output is correct
25 Correct 213 ms 41964 KB Output is correct
26 Correct 203 ms 41948 KB Output is correct
27 Correct 269 ms 52764 KB Output is correct
28 Correct 256 ms 50472 KB Output is correct
29 Correct 258 ms 52304 KB Output is correct
30 Correct 421 ms 67180 KB Output is correct
31 Correct 11 ms 37980 KB Output is correct
32 Correct 446 ms 54256 KB Output is correct
33 Correct 355 ms 89600 KB Output is correct
34 Correct 179 ms 89016 KB Output is correct
35 Correct 194 ms 94228 KB Output is correct
36 Correct 188 ms 78520 KB Output is correct
37 Correct 107 ms 52664 KB Output is correct
38 Correct 135 ms 57228 KB Output is correct
39 Correct 107 ms 55224 KB Output is correct
40 Correct 119 ms 54968 KB Output is correct
41 Correct 57 ms 43972 KB Output is correct
42 Correct 102 ms 51824 KB Output is correct
43 Correct 358 ms 89636 KB Output is correct
44 Correct 172 ms 88812 KB Output is correct
45 Correct 191 ms 94092 KB Output is correct
46 Correct 188 ms 78520 KB Output is correct
47 Correct 107 ms 51896 KB Output is correct
48 Correct 158 ms 59528 KB Output is correct
49 Correct 354 ms 89104 KB Output is correct
50 Correct 263 ms 89268 KB Output is correct
51 Correct 314 ms 95612 KB Output is correct
52 Correct 108 ms 54704 KB Output is correct
53 Correct 120 ms 54708 KB Output is correct
54 Correct 58 ms 43968 KB Output is correct
55 Correct 102 ms 51932 KB Output is correct
56 Correct 352 ms 89788 KB Output is correct
57 Correct 172 ms 88836 KB Output is correct
58 Correct 186 ms 94080 KB Output is correct
59 Correct 190 ms 78776 KB Output is correct
60 Correct 107 ms 51384 KB Output is correct
61 Correct 161 ms 59776 KB Output is correct
62 Correct 347 ms 90036 KB Output is correct
63 Correct 263 ms 89268 KB Output is correct
64 Correct 309 ms 96468 KB Output is correct
65 Correct 166 ms 48744 KB Output is correct
66 Correct 236 ms 54708 KB Output is correct
67 Correct 258 ms 54568 KB Output is correct
68 Correct 207 ms 52380 KB Output is correct
69 Correct 230 ms 52284 KB Output is correct
70 Correct 93 ms 47496 KB Output is correct
71 Correct 231 ms 54496 KB Output is correct
72 Correct 231 ms 54420 KB Output is correct
73 Correct 207 ms 52404 KB Output is correct
74 Correct 157 ms 53700 KB Output is correct
75 Correct 157 ms 54388 KB Output is correct
76 Correct 154 ms 54452 KB Output is correct
77 Correct 158 ms 52332 KB Output is correct
78 Correct 194 ms 52192 KB Output is correct
79 Correct 492 ms 55588 KB Output is correct
80 Correct 568 ms 55216 KB Output is correct
81 Correct 309 ms 45772 KB Output is correct
82 Correct 357 ms 52272 KB Output is correct
83 Correct 684 ms 89208 KB Output is correct
84 Correct 498 ms 89488 KB Output is correct
85 Correct 519 ms 94604 KB Output is correct
86 Correct 454 ms 79352 KB Output is correct
87 Correct 278 ms 51332 KB Output is correct
88 Correct 326 ms 59708 KB Output is correct
89 Correct 537 ms 89516 KB Output is correct
90 Correct 611 ms 89548 KB Output is correct
91 Correct 538 ms 96368 KB Output is correct