답안 #545769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545769 2022-04-05T12:18:24 Z zaneyu 무지개나라 (APIO17_rainbow) C++14
100 / 100
1135 ms 205644 KB
#include "rainbow.h"
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("O2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
    return out;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    a%=MOD;
    if(a==0) return 0;
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
struct seg{
    set<int> s[maxn];
    int rt[maxn];
    int seg[20*maxn],lc[20*maxn],rc[20*maxn];
    int cur=2;
    void add(int x,int y){
        s[x].insert(y);
    }
    void build(){
        rt[0]=1;
        REP(i,maxn-1){
            for(auto x:s[i]) upd(rt[i],1,maxn,x);
            rt[i+1]=rt[i];
        }
    }
    void upd(int &idx,int l,int r,int p){
        seg[cur]=seg[idx]+1,lc[cur]=lc[idx],rc[cur]=rc[idx];
        idx=cur++;
        if(l==r){
            return;
        }
        int mid=(l+r)/2;
        if(p<=mid) upd(lc[idx],l,mid,p);
        else upd(rc[idx],mid+1,r,p);
    }
    int query(int l1,int r1,int l2,int r2){
        if(l2>r2) return 0;
        return query(rt[r1],1,maxn,l2,r2)-query(rt[l1-1],1,maxn,l2,r2);
    }
    int query(int idx,int l,int r,int ql,int qr){
        if(r<ql or l>qr) return 0;
        if(ql<=l and r<=qr) return seg[idx];
        int mid=(l+r)/2;
        return query(lc[idx],l,mid,ql,qr)+query(rc[idx],mid+1,r,ql,qr);
    }
}ver,edh,edv,rvrs;
int xmx=0,xmn=INF,ymx=0,ymn=INF;
void add(int x,int y){
    ver.add(x,y),ver.add(x+1,y+1),ver.add(x+1,y),ver.add(x,y+1);
    edh.add(x,y),edh.add(x+1,y);
    edv.add(x,y),edv.add(x,y+1);
    rvrs.add(x,y);
}
void init(int N, int C, int x, int y, int M, char *S) {
    xmx=xmn=x;
    ymx=ymn=y;
    add(x,y);
    REP(i,M){
        if(S[i]=='N') --x;
        else if(S[i]=='S') ++x;
        else if(S[i]=='E') ++y;
        else --y;
        add(x,y);
        MNTO(ymn,y),MXTO(ymx,y),MXTO(xmx,x),MNTO(xmn,x);
    }
    ver.build(),edh.build(),edv.build(),rvrs.build();
}
int colour(int ar, int ac, int br, int bc) {
    int e=edh.query(ar+1,br,ac,bc)+edv.query(ar,br,ac+1,bc);
    int v=ver.query(ar+1,br,ac+1,bc);
    int r=rvrs.query(ar,br,ac,bc);
    int c=2;
    if(ar>=xmn or br<=xmx or ac>=ymn or bc<=ymx) c=1;
    //cout<<e<<' '<<v<<' '<<r<<' '<<c<<'\n';
    return e-v+c-r;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41300 KB Output is correct
2 Correct 25 ms 42412 KB Output is correct
3 Correct 22 ms 41388 KB Output is correct
4 Correct 24 ms 41520 KB Output is correct
5 Correct 25 ms 42668 KB Output is correct
6 Correct 22 ms 41008 KB Output is correct
7 Correct 22 ms 41044 KB Output is correct
8 Correct 26 ms 41060 KB Output is correct
9 Correct 22 ms 41116 KB Output is correct
10 Correct 20 ms 41020 KB Output is correct
11 Correct 23 ms 41556 KB Output is correct
12 Correct 24 ms 42016 KB Output is correct
13 Correct 25 ms 43084 KB Output is correct
14 Correct 29 ms 43668 KB Output is correct
15 Correct 19 ms 41036 KB Output is correct
16 Correct 20 ms 41040 KB Output is correct
17 Correct 26 ms 40996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 41040 KB Output is correct
2 Correct 26 ms 40996 KB Output is correct
3 Correct 575 ms 139904 KB Output is correct
4 Correct 803 ms 204464 KB Output is correct
5 Correct 794 ms 203192 KB Output is correct
6 Correct 684 ms 166860 KB Output is correct
7 Correct 769 ms 164636 KB Output is correct
8 Correct 295 ms 44764 KB Output is correct
9 Correct 783 ms 204484 KB Output is correct
10 Correct 825 ms 203364 KB Output is correct
11 Correct 731 ms 166740 KB Output is correct
12 Correct 460 ms 193236 KB Output is correct
13 Correct 493 ms 204376 KB Output is correct
14 Correct 499 ms 203144 KB Output is correct
15 Correct 493 ms 166896 KB Output is correct
16 Correct 657 ms 157496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 41036 KB Output is correct
2 Correct 366 ms 201204 KB Output is correct
3 Correct 162 ms 198624 KB Output is correct
4 Correct 169 ms 201124 KB Output is correct
5 Correct 162 ms 159884 KB Output is correct
6 Correct 93 ms 71176 KB Output is correct
7 Correct 150 ms 100884 KB Output is correct
8 Correct 287 ms 183900 KB Output is correct
9 Correct 271 ms 167944 KB Output is correct
10 Correct 123 ms 72780 KB Output is correct
11 Correct 162 ms 119536 KB Output is correct
12 Correct 336 ms 201036 KB Output is correct
13 Correct 165 ms 198608 KB Output is correct
14 Correct 174 ms 201180 KB Output is correct
15 Correct 160 ms 159780 KB Output is correct
16 Correct 84 ms 65120 KB Output is correct
17 Correct 143 ms 100964 KB Output is correct
18 Correct 253 ms 201068 KB Output is correct
19 Correct 238 ms 202096 KB Output is correct
20 Correct 255 ms 202060 KB Output is correct
21 Correct 296 ms 183792 KB Output is correct
22 Correct 292 ms 167832 KB Output is correct
23 Correct 97 ms 72792 KB Output is correct
24 Correct 164 ms 119668 KB Output is correct
25 Correct 344 ms 201128 KB Output is correct
26 Correct 175 ms 198500 KB Output is correct
27 Correct 176 ms 201188 KB Output is correct
28 Correct 171 ms 159824 KB Output is correct
29 Correct 103 ms 65100 KB Output is correct
30 Correct 151 ms 100864 KB Output is correct
31 Correct 240 ms 201120 KB Output is correct
32 Correct 233 ms 202180 KB Output is correct
33 Correct 240 ms 202172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41300 KB Output is correct
2 Correct 25 ms 42412 KB Output is correct
3 Correct 22 ms 41388 KB Output is correct
4 Correct 24 ms 41520 KB Output is correct
5 Correct 25 ms 42668 KB Output is correct
6 Correct 22 ms 41008 KB Output is correct
7 Correct 22 ms 41044 KB Output is correct
8 Correct 26 ms 41060 KB Output is correct
9 Correct 22 ms 41116 KB Output is correct
10 Correct 20 ms 41020 KB Output is correct
11 Correct 23 ms 41556 KB Output is correct
12 Correct 24 ms 42016 KB Output is correct
13 Correct 25 ms 43084 KB Output is correct
14 Correct 29 ms 43668 KB Output is correct
15 Correct 19 ms 41036 KB Output is correct
16 Correct 20 ms 41040 KB Output is correct
17 Correct 26 ms 40996 KB Output is correct
18 Correct 730 ms 125284 KB Output is correct
19 Correct 232 ms 48208 KB Output is correct
20 Correct 188 ms 45048 KB Output is correct
21 Correct 218 ms 45812 KB Output is correct
22 Correct 214 ms 46464 KB Output is correct
23 Correct 238 ms 47980 KB Output is correct
24 Correct 242 ms 45528 KB Output is correct
25 Correct 212 ms 46412 KB Output is correct
26 Correct 209 ms 46896 KB Output is correct
27 Correct 421 ms 109932 KB Output is correct
28 Correct 308 ms 75904 KB Output is correct
29 Correct 435 ms 104132 KB Output is correct
30 Correct 599 ms 204492 KB Output is correct
31 Correct 26 ms 41208 KB Output is correct
32 Correct 568 ms 110616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 41300 KB Output is correct
2 Correct 25 ms 42412 KB Output is correct
3 Correct 22 ms 41388 KB Output is correct
4 Correct 24 ms 41520 KB Output is correct
5 Correct 25 ms 42668 KB Output is correct
6 Correct 22 ms 41008 KB Output is correct
7 Correct 22 ms 41044 KB Output is correct
8 Correct 26 ms 41060 KB Output is correct
9 Correct 22 ms 41116 KB Output is correct
10 Correct 20 ms 41020 KB Output is correct
11 Correct 23 ms 41556 KB Output is correct
12 Correct 24 ms 42016 KB Output is correct
13 Correct 25 ms 43084 KB Output is correct
14 Correct 29 ms 43668 KB Output is correct
15 Correct 19 ms 41036 KB Output is correct
16 Correct 20 ms 41040 KB Output is correct
17 Correct 26 ms 40996 KB Output is correct
18 Correct 730 ms 125284 KB Output is correct
19 Correct 232 ms 48208 KB Output is correct
20 Correct 188 ms 45048 KB Output is correct
21 Correct 218 ms 45812 KB Output is correct
22 Correct 214 ms 46464 KB Output is correct
23 Correct 238 ms 47980 KB Output is correct
24 Correct 242 ms 45528 KB Output is correct
25 Correct 212 ms 46412 KB Output is correct
26 Correct 209 ms 46896 KB Output is correct
27 Correct 421 ms 109932 KB Output is correct
28 Correct 308 ms 75904 KB Output is correct
29 Correct 435 ms 104132 KB Output is correct
30 Correct 599 ms 204492 KB Output is correct
31 Correct 26 ms 41208 KB Output is correct
32 Correct 568 ms 110616 KB Output is correct
33 Correct 366 ms 201204 KB Output is correct
34 Correct 162 ms 198624 KB Output is correct
35 Correct 169 ms 201124 KB Output is correct
36 Correct 162 ms 159884 KB Output is correct
37 Correct 93 ms 71176 KB Output is correct
38 Correct 150 ms 100884 KB Output is correct
39 Correct 287 ms 183900 KB Output is correct
40 Correct 271 ms 167944 KB Output is correct
41 Correct 123 ms 72780 KB Output is correct
42 Correct 162 ms 119536 KB Output is correct
43 Correct 336 ms 201036 KB Output is correct
44 Correct 165 ms 198608 KB Output is correct
45 Correct 174 ms 201180 KB Output is correct
46 Correct 160 ms 159780 KB Output is correct
47 Correct 84 ms 65120 KB Output is correct
48 Correct 143 ms 100964 KB Output is correct
49 Correct 253 ms 201068 KB Output is correct
50 Correct 238 ms 202096 KB Output is correct
51 Correct 255 ms 202060 KB Output is correct
52 Correct 296 ms 183792 KB Output is correct
53 Correct 292 ms 167832 KB Output is correct
54 Correct 97 ms 72792 KB Output is correct
55 Correct 164 ms 119668 KB Output is correct
56 Correct 344 ms 201128 KB Output is correct
57 Correct 175 ms 198500 KB Output is correct
58 Correct 176 ms 201188 KB Output is correct
59 Correct 171 ms 159824 KB Output is correct
60 Correct 103 ms 65100 KB Output is correct
61 Correct 151 ms 100864 KB Output is correct
62 Correct 240 ms 201120 KB Output is correct
63 Correct 233 ms 202180 KB Output is correct
64 Correct 240 ms 202172 KB Output is correct
65 Correct 575 ms 139904 KB Output is correct
66 Correct 803 ms 204464 KB Output is correct
67 Correct 794 ms 203192 KB Output is correct
68 Correct 684 ms 166860 KB Output is correct
69 Correct 769 ms 164636 KB Output is correct
70 Correct 295 ms 44764 KB Output is correct
71 Correct 783 ms 204484 KB Output is correct
72 Correct 825 ms 203364 KB Output is correct
73 Correct 731 ms 166740 KB Output is correct
74 Correct 460 ms 193236 KB Output is correct
75 Correct 493 ms 204376 KB Output is correct
76 Correct 499 ms 203144 KB Output is correct
77 Correct 493 ms 166896 KB Output is correct
78 Correct 657 ms 157496 KB Output is correct
79 Correct 1135 ms 187364 KB Output is correct
80 Correct 1008 ms 171188 KB Output is correct
81 Correct 453 ms 76224 KB Output is correct
82 Correct 521 ms 123000 KB Output is correct
83 Correct 759 ms 204616 KB Output is correct
84 Correct 530 ms 202332 KB Output is correct
85 Correct 573 ms 204536 KB Output is correct
86 Correct 529 ms 163380 KB Output is correct
87 Correct 392 ms 68700 KB Output is correct
88 Correct 433 ms 104380 KB Output is correct
89 Correct 531 ms 204704 KB Output is correct
90 Correct 779 ms 205624 KB Output is correct
91 Correct 584 ms 205644 KB Output is correct