Submission #202259

# Submission time Handle Problem Language Result Execution time Memory
202259 2020-02-14T15:40:38 Z stefanbalaz2 Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
1323 ms 203772 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
const int maxseg=9*1e5*25;
int tree[maxseg],lc[maxseg],rc[maxseg];
int cnt=1,minr,maxr,minc,maxc;
struct segtree{

    int root[maxn+10];
    set<int>ind[maxn+10];

    void add(int x,int y){
        ind[x].insert(y);
    }

    void build(){

        for(int i=1;i<=maxn;i++){
            root[i]=root[i-1];
            for(set<int>::iterator it=ind[i].begin();it!=ind[i].end();it++)update(root[i],1,maxn,*it);
        }
    }

    void update(int &x,int l,int r,int id){

        tree[cnt]=tree[x]+1;
        lc[cnt]=lc[x];
        rc[cnt]=rc[x];
        x=cnt++;

        if(l==r)return;

        int mid=(l+r)/2;
        if(id<=mid)update(lc[x],l,mid,id);
        else update(rc[x],mid+1,r,id);
    }

    int query(int u,int d,int l,int r){
        return query(root[d],1,maxn,l,r)-query(root[u-1],1,maxn,l,r);
    }
    int query(int x,int l,int r,int ll,int rr){
        if(l>rr || r<ll)return 0;
        if(l>=ll && r<=rr)return tree[x];
        int mid=(l+r)/2;
        return query(lc[x],l,mid,ll,rr)+query(rc[x],mid+1,r,ll,rr);
    }

}river,horiz_edges,vert_edges,vert;
void add_river(int x,int y){

    vert.add(x,y);
    vert.add(x,y+1);
    vert.add(x+1,y);
    vert.add(x+1,y+1);

    horiz_edges.add(x,y);
    horiz_edges.add(x+1,y);

    vert_edges.add(x,y);
    vert_edges.add(x,y+1);

    river.add(x,y);
}
void init(int R, int C, int sr, int sc, int M, char *S) {

    add_river(sr,sc);
    minr=maxr=sr;
    minc=maxc=sc;
    for(int i=0;i<M;i++){

        if(S[i]=='N')sr--;
        if(S[i]=='S')sr++;
        if(S[i]=='E')sc++;
        if(S[i]=='W')sc--;

        add_river(sr,sc);

        minr=min(minr,sr);
        maxr=max(maxr,sr);
        minc=min(minc,sc);
        maxc=max(maxc,sc);
    }

    river.build();
    horiz_edges.build();
    vert_edges.build();
    vert.build();

}

int colour(int ar, int ac, int br, int bc) {

    /// F = E - N + C - R

    int E = horiz_edges.query(ar+1,br,ac,bc) + vert_edges.query(ar,br,ac+1,bc);
    int N = vert.query(ar+1,br,ac+1,bc);
    int C = ((minr>ar && minc>ac && maxr<br && maxc<bc)?2:1);
    int R = river.query(ar,br,ac,bc);

    return E-N+C-R;
}
# Verdict Execution time Memory Grader output
1 Correct 36 ms 41336 KB Output is correct
2 Correct 38 ms 42488 KB Output is correct
3 Correct 36 ms 41464 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 38 ms 42616 KB Output is correct
6 Correct 33 ms 41080 KB Output is correct
7 Correct 34 ms 41080 KB Output is correct
8 Correct 33 ms 41080 KB Output is correct
9 Correct 33 ms 41084 KB Output is correct
10 Correct 34 ms 41080 KB Output is correct
11 Correct 37 ms 41592 KB Output is correct
12 Correct 36 ms 42104 KB Output is correct
13 Correct 38 ms 43128 KB Output is correct
14 Correct 39 ms 43640 KB Output is correct
15 Correct 33 ms 41080 KB Output is correct
16 Correct 33 ms 41080 KB Output is correct
17 Correct 34 ms 41056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 41080 KB Output is correct
2 Correct 34 ms 41056 KB Output is correct
3 Correct 675 ms 139512 KB Output is correct
4 Correct 943 ms 203772 KB Output is correct
5 Correct 954 ms 202652 KB Output is correct
6 Correct 834 ms 166156 KB Output is correct
7 Correct 908 ms 163984 KB Output is correct
8 Correct 377 ms 44024 KB Output is correct
9 Correct 988 ms 203768 KB Output is correct
10 Correct 994 ms 202416 KB Output is correct
11 Correct 870 ms 166008 KB Output is correct
12 Correct 443 ms 192232 KB Output is correct
13 Correct 489 ms 203512 KB Output is correct
14 Correct 499 ms 202336 KB Output is correct
15 Correct 479 ms 165932 KB Output is correct
16 Correct 771 ms 156792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 41080 KB Output is correct
2 Correct 389 ms 201084 KB Output is correct
3 Correct 197 ms 198620 KB Output is correct
4 Correct 212 ms 201080 KB Output is correct
5 Correct 199 ms 159864 KB Output is correct
6 Correct 124 ms 71288 KB Output is correct
7 Correct 189 ms 100984 KB Output is correct
8 Correct 344 ms 183800 KB Output is correct
9 Correct 319 ms 167928 KB Output is correct
10 Correct 119 ms 72696 KB Output is correct
11 Correct 198 ms 119544 KB Output is correct
12 Correct 397 ms 201080 KB Output is correct
13 Correct 195 ms 198520 KB Output is correct
14 Correct 221 ms 201140 KB Output is correct
15 Correct 199 ms 159864 KB Output is correct
16 Correct 110 ms 65144 KB Output is correct
17 Correct 180 ms 101240 KB Output is correct
18 Correct 294 ms 201164 KB Output is correct
19 Correct 278 ms 202104 KB Output is correct
20 Correct 292 ms 202104 KB Output is correct
21 Correct 343 ms 183928 KB Output is correct
22 Correct 334 ms 167892 KB Output is correct
23 Correct 119 ms 72696 KB Output is correct
24 Correct 198 ms 119544 KB Output is correct
25 Correct 383 ms 201136 KB Output is correct
26 Correct 186 ms 198520 KB Output is correct
27 Correct 220 ms 201208 KB Output is correct
28 Correct 199 ms 159864 KB Output is correct
29 Correct 113 ms 65144 KB Output is correct
30 Correct 172 ms 100984 KB Output is correct
31 Correct 297 ms 201136 KB Output is correct
32 Correct 292 ms 202232 KB Output is correct
33 Correct 278 ms 202104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 41336 KB Output is correct
2 Correct 38 ms 42488 KB Output is correct
3 Correct 36 ms 41464 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 38 ms 42616 KB Output is correct
6 Correct 33 ms 41080 KB Output is correct
7 Correct 34 ms 41080 KB Output is correct
8 Correct 33 ms 41080 KB Output is correct
9 Correct 33 ms 41084 KB Output is correct
10 Correct 34 ms 41080 KB Output is correct
11 Correct 37 ms 41592 KB Output is correct
12 Correct 36 ms 42104 KB Output is correct
13 Correct 38 ms 43128 KB Output is correct
14 Correct 39 ms 43640 KB Output is correct
15 Correct 33 ms 41080 KB Output is correct
16 Correct 33 ms 41080 KB Output is correct
17 Correct 34 ms 41056 KB Output is correct
18 Correct 923 ms 124324 KB Output is correct
19 Correct 297 ms 47096 KB Output is correct
20 Correct 239 ms 44024 KB Output is correct
21 Correct 246 ms 44664 KB Output is correct
22 Correct 266 ms 45444 KB Output is correct
23 Correct 290 ms 47096 KB Output is correct
24 Correct 234 ms 44536 KB Output is correct
25 Correct 252 ms 45176 KB Output is correct
26 Correct 261 ms 45816 KB Output is correct
27 Correct 494 ms 108640 KB Output is correct
28 Correct 409 ms 74744 KB Output is correct
29 Correct 507 ms 103032 KB Output is correct
30 Correct 729 ms 203048 KB Output is correct
31 Correct 38 ms 41208 KB Output is correct
32 Correct 755 ms 109304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 41336 KB Output is correct
2 Correct 38 ms 42488 KB Output is correct
3 Correct 36 ms 41464 KB Output is correct
4 Correct 36 ms 41464 KB Output is correct
5 Correct 38 ms 42616 KB Output is correct
6 Correct 33 ms 41080 KB Output is correct
7 Correct 34 ms 41080 KB Output is correct
8 Correct 33 ms 41080 KB Output is correct
9 Correct 33 ms 41084 KB Output is correct
10 Correct 34 ms 41080 KB Output is correct
11 Correct 37 ms 41592 KB Output is correct
12 Correct 36 ms 42104 KB Output is correct
13 Correct 38 ms 43128 KB Output is correct
14 Correct 39 ms 43640 KB Output is correct
15 Correct 33 ms 41080 KB Output is correct
16 Correct 33 ms 41080 KB Output is correct
17 Correct 34 ms 41056 KB Output is correct
18 Correct 923 ms 124324 KB Output is correct
19 Correct 297 ms 47096 KB Output is correct
20 Correct 239 ms 44024 KB Output is correct
21 Correct 246 ms 44664 KB Output is correct
22 Correct 266 ms 45444 KB Output is correct
23 Correct 290 ms 47096 KB Output is correct
24 Correct 234 ms 44536 KB Output is correct
25 Correct 252 ms 45176 KB Output is correct
26 Correct 261 ms 45816 KB Output is correct
27 Correct 494 ms 108640 KB Output is correct
28 Correct 409 ms 74744 KB Output is correct
29 Correct 507 ms 103032 KB Output is correct
30 Correct 729 ms 203048 KB Output is correct
31 Correct 38 ms 41208 KB Output is correct
32 Correct 755 ms 109304 KB Output is correct
33 Correct 389 ms 201084 KB Output is correct
34 Correct 197 ms 198620 KB Output is correct
35 Correct 212 ms 201080 KB Output is correct
36 Correct 199 ms 159864 KB Output is correct
37 Correct 124 ms 71288 KB Output is correct
38 Correct 189 ms 100984 KB Output is correct
39 Correct 344 ms 183800 KB Output is correct
40 Correct 319 ms 167928 KB Output is correct
41 Correct 119 ms 72696 KB Output is correct
42 Correct 198 ms 119544 KB Output is correct
43 Correct 397 ms 201080 KB Output is correct
44 Correct 195 ms 198520 KB Output is correct
45 Correct 221 ms 201140 KB Output is correct
46 Correct 199 ms 159864 KB Output is correct
47 Correct 110 ms 65144 KB Output is correct
48 Correct 180 ms 101240 KB Output is correct
49 Correct 294 ms 201164 KB Output is correct
50 Correct 278 ms 202104 KB Output is correct
51 Correct 292 ms 202104 KB Output is correct
52 Correct 343 ms 183928 KB Output is correct
53 Correct 334 ms 167892 KB Output is correct
54 Correct 119 ms 72696 KB Output is correct
55 Correct 198 ms 119544 KB Output is correct
56 Correct 383 ms 201136 KB Output is correct
57 Correct 186 ms 198520 KB Output is correct
58 Correct 220 ms 201208 KB Output is correct
59 Correct 199 ms 159864 KB Output is correct
60 Correct 113 ms 65144 KB Output is correct
61 Correct 172 ms 100984 KB Output is correct
62 Correct 297 ms 201136 KB Output is correct
63 Correct 292 ms 202232 KB Output is correct
64 Correct 278 ms 202104 KB Output is correct
65 Correct 1323 ms 185848 KB Output is correct
66 Correct 1293 ms 169836 KB Output is correct
67 Correct 546 ms 74872 KB Output is correct
68 Correct 630 ms 121592 KB Output is correct
69 Correct 889 ms 202924 KB Output is correct
70 Correct 631 ms 200228 KB Output is correct
71 Correct 665 ms 202872 KB Output is correct
72 Correct 614 ms 161400 KB Output is correct
73 Correct 450 ms 66680 KB Output is correct
74 Correct 525 ms 102552 KB Output is correct
75 Correct 637 ms 202648 KB Output is correct
76 Correct 841 ms 203640 KB Output is correct
77 Correct 694 ms 203512 KB Output is correct
78 Correct 675 ms 139512 KB Output is correct
79 Correct 943 ms 203772 KB Output is correct
80 Correct 954 ms 202652 KB Output is correct
81 Correct 834 ms 166156 KB Output is correct
82 Correct 908 ms 163984 KB Output is correct
83 Correct 377 ms 44024 KB Output is correct
84 Correct 988 ms 203768 KB Output is correct
85 Correct 994 ms 202416 KB Output is correct
86 Correct 870 ms 166008 KB Output is correct
87 Correct 443 ms 192232 KB Output is correct
88 Correct 489 ms 203512 KB Output is correct
89 Correct 499 ms 202336 KB Output is correct
90 Correct 479 ms 165932 KB Output is correct
91 Correct 771 ms 156792 KB Output is correct