Submission #1090072

# Submission time Handle Problem Language Result Execution time Memory
1090072 2024-09-17T17:03:59 Z alexander707070 Land of the Rainbow Gold (APIO17_rainbow) C++14
74 / 100
3000 ms 830624 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include "rainbow.h"

#define MAXN 200007
using namespace std;

const int maxs=2e5+7;

struct ST{
    struct node{
        int l,r;
        int val;
    };

    vector<node> tree;
    int num;

    void init(){
        tree.push_back({0,0,0});
        tree.push_back({0,0,0});
        num=1;
    }

    void addnode(){
        tree.push_back({0,0,0});
        num++;
    }

    void update(int v,int l,int r,int pos){
        if(l==r){
            tree[v].val++;
        }else{
            int tt=(l+r)/2;

            if(tree[v].l==0){
                addnode(); tree[v].l=num;
            }
            if(tree[v].r==0){
                addnode(); tree[v].r=num;
            }

            if(pos<=tt)update(tree[v].l,l,tt,pos);
            else update(tree[v].r,tt+1,r,pos);

            tree[v].val=tree[tree[v].l].val+tree[tree[v].r].val;
        }
    }

    int getsum(int v,int l,int r,int ll,int rr){
        if(ll>rr or v==0)return 0;

        if(l==ll and r==rr){
            return tree[v].val;
        }else{
            int tt=(l+r)/2;
            return getsum(tree[v].l,l,tt,ll,min(tt,rr)) + getsum(tree[v].r,tt+1,r,max(tt+1,ll),rr);
        }
    }
};

struct ST2D{
    struct node{
        ST t;
    };

    node tree[4*MAXN];

    void init(){
        for(int i=1;i<4*MAXN;i++){
            tree[i].t.init();
        }
    }

    void update(int v,int l,int r,int x,int y){
        if(l==r){
            tree[v].t.update(1,1,maxs,y);
        }else{
            int tt=(l+r)/2;

            if(x<=tt)update(2*v,l,tt,x,y);
            else update(2*v+1,tt+1,r,x,y);

            tree[v].t.update(1,1,maxs,y);
        }
    }

    int getsum(int v,int l,int r,int lx,int rx,int ly,int ry){
        if(lx>rx or v==0)return 0;

        if(l==lx and r==rx){
            return tree[v].t.getsum(1,1,maxs,ly,ry);
        }else{
            int tt=(l+r)/2;
            return getsum(2*v,l,tt,lx,min(tt,rx),ly,ry) + getsum(2*v+1,tt+1,r,max(tt+1,lx),rx,ly,ry);
        }
    }

}rivers,vertices,edgesh,edgesv;

int n,m,x,y,minx,miny,maxx,maxy;
map< pair<int,int> , int > ver,eh,ev,riv;

void add(int x,int y){
    if(riv[{x,y}]==0){
        rivers.update(1,1,maxs,x,y);
        riv[{x,y}]=1;
    }

    for(int i=0;i<=1;i++){
        for(int f=0;f<=1;f++){
            if(ver[{x+i,y+f}]==1)continue;

            vertices.update(1,1,maxs,x+i,y+f);
            ver[{x+i,y+f}]=1;
        }
    }

    for(int i=0;i<=0;i++){
        for(int f=0;f<=1;f++){
            if(ev[{x+i,y+f}]==1)continue;

            edgesv.update(1,1,maxs,x+i,y+f);
            ev[{x+i,y+f}]=1;
        }
    }

    for(int i=0;i<=1;i++){
        for(int f=0;f<=0;f++){
            if(eh[{x+i,y+f}]==1)continue;

            edgesh.update(1,1,maxs,x+i,y+f);
            eh[{x+i,y+f}]=1;
        }
    }
}

void init(int R, int C, int sr, int sc, int M, char *S) {
    n=R; m=C;

    x=sr; y=sc;

    rivers.init();
    edgesh.init();
    edgesv.init();
    vertices.init();

    add(x,y);
    minx=maxx=x;
    miny=maxy=y;

    for(int i=0;i<M;i++){
        if(S[i]=='N')x--;
        if(S[i]=='S')x++;
        if(S[i]=='E')y++;
        if(S[i]=='W')y--;
        add(x,y);

        minx=min(minx,x);
        miny=min(miny,y);

        maxx=max(maxx,x);
        maxy=max(maxy,y);
    }
}

int colour(int ar,int ac,int br,int bc){
    int R=rivers.getsum(1,1,maxs,ar,br,ac,bc);
    int V=vertices.getsum(1,1,maxs,ar+1,br,ac+1,bc) + 2*(bc-ac+2) + 2*(br-ar+2) - 4;
    int E=edgesv.getsum(1,1,maxs,ar,br,ac+1,bc) + edgesh.getsum(1,1,maxs,ar+1,br,ac,bc) + 2*(bc-ac+1) + 2*(br-ar+1) ;

    if(minx>ar and maxx<br and miny>ac and maxy<bc)E++;

    return E-V-R+1;
}

/*int main(){
   
    init(6, 4,3, 3, 9,"NWESSWEWS");
    cout<<"bro";

    cout<<colour(2,3, 2, 3)<<"\n";
    cout<<colour(3,2,4,4)<<"\n";
    cout<<colour(5,3,6,4)<<"\n";
    cout<<colour(1,2,5,3)<<"\n";
    cout<<colour(1,1,6,4)<<":\n";


    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 276 ms 201040 KB Output is correct
2 Correct 266 ms 201820 KB Output is correct
3 Correct 266 ms 201392 KB Output is correct
4 Correct 263 ms 201356 KB Output is correct
5 Correct 301 ms 202240 KB Output is correct
6 Correct 229 ms 200732 KB Output is correct
7 Correct 228 ms 200784 KB Output is correct
8 Correct 219 ms 200876 KB Output is correct
9 Correct 228 ms 200784 KB Output is correct
10 Correct 235 ms 200804 KB Output is correct
11 Correct 261 ms 201288 KB Output is correct
12 Correct 271 ms 201576 KB Output is correct
13 Correct 285 ms 202532 KB Output is correct
14 Correct 315 ms 202576 KB Output is correct
15 Correct 232 ms 200784 KB Output is correct
16 Correct 246 ms 200728 KB Output is correct
17 Correct 228 ms 200800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 200728 KB Output is correct
2 Correct 228 ms 200800 KB Output is correct
3 Correct 1517 ms 341432 KB Output is correct
4 Correct 2211 ms 425740 KB Output is correct
5 Correct 2208 ms 413360 KB Output is correct
6 Correct 1956 ms 331888 KB Output is correct
7 Correct 1823 ms 332140 KB Output is correct
8 Correct 288 ms 204372 KB Output is correct
9 Correct 2321 ms 425656 KB Output is correct
10 Correct 2218 ms 413376 KB Output is correct
11 Correct 1775 ms 332036 KB Output is correct
12 Correct 2085 ms 413172 KB Output is correct
13 Correct 2168 ms 425608 KB Output is correct
14 Correct 2189 ms 413216 KB Output is correct
15 Correct 1809 ms 331908 KB Output is correct
16 Correct 1754 ms 361580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 200784 KB Output is correct
2 Correct 2193 ms 422008 KB Output is correct
3 Correct 2060 ms 827224 KB Output is correct
4 Correct 2089 ms 615996 KB Output is correct
5 Correct 1711 ms 570356 KB Output is correct
6 Correct 570 ms 220704 KB Output is correct
7 Correct 864 ms 236452 KB Output is correct
8 Correct 2070 ms 332296 KB Output is correct
9 Correct 1757 ms 312360 KB Output is correct
10 Correct 606 ms 219728 KB Output is correct
11 Correct 1145 ms 310068 KB Output is correct
12 Correct 2147 ms 421976 KB Output is correct
13 Correct 2128 ms 827088 KB Output is correct
14 Correct 2171 ms 616060 KB Output is correct
15 Correct 1586 ms 570292 KB Output is correct
16 Correct 526 ms 216648 KB Output is correct
17 Correct 850 ms 237016 KB Output is correct
18 Correct 1735 ms 280656 KB Output is correct
19 Correct 2214 ms 625332 KB Output is correct
20 Correct 2200 ms 625092 KB Output is correct
21 Correct 1860 ms 332148 KB Output is correct
22 Correct 1727 ms 312296 KB Output is correct
23 Correct 588 ms 219748 KB Output is correct
24 Correct 1158 ms 310160 KB Output is correct
25 Correct 2181 ms 421984 KB Output is correct
26 Correct 2240 ms 827224 KB Output is correct
27 Correct 2089 ms 615988 KB Output is correct
28 Correct 1674 ms 570392 KB Output is correct
29 Correct 492 ms 216656 KB Output is correct
30 Correct 829 ms 237052 KB Output is correct
31 Correct 1782 ms 280660 KB Output is correct
32 Correct 2231 ms 625268 KB Output is correct
33 Correct 2237 ms 624928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 201040 KB Output is correct
2 Correct 266 ms 201820 KB Output is correct
3 Correct 266 ms 201392 KB Output is correct
4 Correct 263 ms 201356 KB Output is correct
5 Correct 301 ms 202240 KB Output is correct
6 Correct 229 ms 200732 KB Output is correct
7 Correct 228 ms 200784 KB Output is correct
8 Correct 219 ms 200876 KB Output is correct
9 Correct 228 ms 200784 KB Output is correct
10 Correct 235 ms 200804 KB Output is correct
11 Correct 261 ms 201288 KB Output is correct
12 Correct 271 ms 201576 KB Output is correct
13 Correct 285 ms 202532 KB Output is correct
14 Correct 315 ms 202576 KB Output is correct
15 Correct 232 ms 200784 KB Output is correct
16 Correct 246 ms 200728 KB Output is correct
17 Correct 228 ms 200800 KB Output is correct
18 Correct 2036 ms 295928 KB Output is correct
19 Correct 534 ms 208488 KB Output is correct
20 Correct 503 ms 205140 KB Output is correct
21 Correct 557 ms 206200 KB Output is correct
22 Correct 608 ms 207756 KB Output is correct
23 Correct 532 ms 208208 KB Output is correct
24 Correct 530 ms 205396 KB Output is correct
25 Correct 593 ms 206676 KB Output is correct
26 Correct 608 ms 208208 KB Output is correct
27 Correct 1198 ms 247980 KB Output is correct
28 Correct 826 ms 225108 KB Output is correct
29 Correct 1158 ms 238428 KB Output is correct
30 Correct 2228 ms 283988 KB Output is correct
31 Correct 228 ms 200884 KB Output is correct
32 Correct 1440 ms 243376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 201040 KB Output is correct
2 Correct 266 ms 201820 KB Output is correct
3 Correct 266 ms 201392 KB Output is correct
4 Correct 263 ms 201356 KB Output is correct
5 Correct 301 ms 202240 KB Output is correct
6 Correct 229 ms 200732 KB Output is correct
7 Correct 228 ms 200784 KB Output is correct
8 Correct 219 ms 200876 KB Output is correct
9 Correct 228 ms 200784 KB Output is correct
10 Correct 235 ms 200804 KB Output is correct
11 Correct 261 ms 201288 KB Output is correct
12 Correct 271 ms 201576 KB Output is correct
13 Correct 285 ms 202532 KB Output is correct
14 Correct 315 ms 202576 KB Output is correct
15 Correct 232 ms 200784 KB Output is correct
16 Correct 246 ms 200728 KB Output is correct
17 Correct 228 ms 200800 KB Output is correct
18 Correct 2036 ms 295928 KB Output is correct
19 Correct 534 ms 208488 KB Output is correct
20 Correct 503 ms 205140 KB Output is correct
21 Correct 557 ms 206200 KB Output is correct
22 Correct 608 ms 207756 KB Output is correct
23 Correct 532 ms 208208 KB Output is correct
24 Correct 530 ms 205396 KB Output is correct
25 Correct 593 ms 206676 KB Output is correct
26 Correct 608 ms 208208 KB Output is correct
27 Correct 1198 ms 247980 KB Output is correct
28 Correct 826 ms 225108 KB Output is correct
29 Correct 1158 ms 238428 KB Output is correct
30 Correct 2228 ms 283988 KB Output is correct
31 Correct 228 ms 200884 KB Output is correct
32 Correct 1440 ms 243376 KB Output is correct
33 Correct 2193 ms 422008 KB Output is correct
34 Correct 2060 ms 827224 KB Output is correct
35 Correct 2089 ms 615996 KB Output is correct
36 Correct 1711 ms 570356 KB Output is correct
37 Correct 570 ms 220704 KB Output is correct
38 Correct 864 ms 236452 KB Output is correct
39 Correct 2070 ms 332296 KB Output is correct
40 Correct 1757 ms 312360 KB Output is correct
41 Correct 606 ms 219728 KB Output is correct
42 Correct 1145 ms 310068 KB Output is correct
43 Correct 2147 ms 421976 KB Output is correct
44 Correct 2128 ms 827088 KB Output is correct
45 Correct 2171 ms 616060 KB Output is correct
46 Correct 1586 ms 570292 KB Output is correct
47 Correct 526 ms 216648 KB Output is correct
48 Correct 850 ms 237016 KB Output is correct
49 Correct 1735 ms 280656 KB Output is correct
50 Correct 2214 ms 625332 KB Output is correct
51 Correct 2200 ms 625092 KB Output is correct
52 Correct 1860 ms 332148 KB Output is correct
53 Correct 1727 ms 312296 KB Output is correct
54 Correct 588 ms 219748 KB Output is correct
55 Correct 1158 ms 310160 KB Output is correct
56 Correct 2181 ms 421984 KB Output is correct
57 Correct 2240 ms 827224 KB Output is correct
58 Correct 2089 ms 615988 KB Output is correct
59 Correct 1674 ms 570392 KB Output is correct
60 Correct 492 ms 216656 KB Output is correct
61 Correct 829 ms 237052 KB Output is correct
62 Correct 1782 ms 280660 KB Output is correct
63 Correct 2231 ms 625268 KB Output is correct
64 Correct 2237 ms 624928 KB Output is correct
65 Correct 1517 ms 341432 KB Output is correct
66 Correct 2211 ms 425740 KB Output is correct
67 Correct 2208 ms 413360 KB Output is correct
68 Correct 1956 ms 331888 KB Output is correct
69 Correct 1823 ms 332140 KB Output is correct
70 Correct 288 ms 204372 KB Output is correct
71 Correct 2321 ms 425656 KB Output is correct
72 Correct 2218 ms 413376 KB Output is correct
73 Correct 1775 ms 332036 KB Output is correct
74 Correct 2085 ms 413172 KB Output is correct
75 Correct 2168 ms 425608 KB Output is correct
76 Correct 2189 ms 413216 KB Output is correct
77 Correct 1809 ms 331908 KB Output is correct
78 Correct 1754 ms 361580 KB Output is correct
79 Correct 2175 ms 335700 KB Output is correct
80 Correct 2116 ms 315776 KB Output is correct
81 Correct 853 ms 223216 KB Output is correct
82 Correct 1522 ms 313632 KB Output is correct
83 Correct 2645 ms 425628 KB Output is correct
84 Correct 2558 ms 830624 KB Output is correct
85 Correct 2554 ms 619664 KB Output is correct
86 Correct 2120 ms 573748 KB Output is correct
87 Correct 966 ms 219988 KB Output is correct
88 Correct 1251 ms 240624 KB Output is correct
89 Correct 2194 ms 284220 KB Output is correct
90 Correct 2826 ms 628832 KB Output is correct
91 Execution timed out 3085 ms 628572 KB Time limit exceeded
92 Halted 0 ms 0 KB -