답안 #704698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704698 2023-03-02T16:26:44 Z safaricola Crossing (JOI21_crossing) C++17
100 / 100
4409 ms 203112 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define f first
#define s second
typedef pair<ll ,ll> ii;
string s[4];
char ch;
int n, a[10][200010],pre[10][4][200010],q,t,x,y;
int f(int x, int y){
    return (6-x-y)%3;
}
struct node{
    int s,e,m,v,lazy,id;
    node *l, *r;
    node(int S,int E,int ID){
        s=S,e=E,m=(s+e)/2;
        id=ID;v=0;lazy=-1;
        if(s==e)return;
        l= new node(s,m,id);
        r= new node(m+1,e,id);
    }
    void prop(){
        if(lazy==-1)return;
        v=pre[id][lazy][e]- (s==0 ? 0: pre[id][lazy][s-1]);
        if(s!=e){
            l->lazy=lazy;
            r->lazy=lazy;
        }
        lazy=-1;
    }
    void upd(int S,int E,int V){
        if(s==S&&e==E)lazy=V;
        else{
            prop();
            if(E<=m)l->upd(S,E,V);
            else if(S>m)r->upd(S,E,V);
            else{
                l->upd(S,m,V);
                r->upd(m+1,E,V);
            }
            l->prop();r->prop();
            v=l->v+r->v;
        }
    }
    int sum(int S,int E){
        prop();
        if(s==S&&e==E)return v;
        if(E<=m)return l->sum(S,E);
        else if(S>m)return r->sum(S,E);
        else return l->sum(S,m)+r->sum(m+1,E);
    }

}*root[10];
int main(){
    cin>>n>>s[0]>>s[1]>>s[2]>>q>>s[3];
    rep(i,3)rep(j,n){
        if(s[i][j]=='J')a[i][j]=0;
        else if(s[i][j]=='O')a[i][j]=1;
        else a[i][j]=2;
    }
    rep(i,n)a[3][i]=f(a[0][i],a[1][i]);
    rep(i,n)a[4][i]=f(a[2][i],a[1][i]);
    rep(i,n)a[5][i]=f(a[0][i],a[2][i]);
    rep(i,n)a[6][i]=f(a[3][i],a[4][i]);
    rep(i,n)a[7][i]=f(a[5][i],a[4][i]);
    rep(i,n)a[8][i]=f(a[3][i],a[5][i]);
    //rep(i,9){rep(j,n)cout<<a[i][j];cout<<endl;}
    rep(i,9)rep(j,3)rep(k,n){
        pre[i][j][k]=(k==0 ? 0: pre[i][j][k-1])+(j==a[i][k]);
    }
    //rep(i,9)rep(j,3){cout<<i<<j<<": ";rep(k,n)cout<<pre[i][j][k];cout<<endl;}
    
    rep(i,9)root[i] = new node(0,n,i);
    rep(i,9)rep(j,n){
        if(s[3][j]=='J')t=0;
        else if(s[3][j]=='O')t=1;
        else t=2;
        root[i]->upd(j,j,t);
    }
    bool flag=true;
    rep(i,9)if(root[i]-> sum(0,n)==n){
        flag=false;
        cout<<"Yes\n";
        break;
    }
    if(flag)cout<<"No\n";
    while(q--){
        cin>>x>>y>>ch;x--;y--;
        if(ch=='J')t=0;
        else if(ch=='O')t=1;
        else t=2;
        rep(i,9){
            root[i]-> upd(x,y,t);
        }
        bool flag=true;
        rep(i,9)if(root[i]->sum(0,n)==n){
            flag=false;
            cout<<"Yes\n";
            break;
        }
        if(flag)cout<<"No\n";
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 1228 KB Output is correct
2 Correct 570 ms 2632 KB Output is correct
3 Correct 659 ms 2708 KB Output is correct
4 Correct 491 ms 2696 KB Output is correct
5 Correct 476 ms 2588 KB Output is correct
6 Correct 485 ms 2512 KB Output is correct
7 Correct 515 ms 2668 KB Output is correct
8 Correct 516 ms 2628 KB Output is correct
9 Correct 532 ms 2796 KB Output is correct
10 Correct 533 ms 2776 KB Output is correct
11 Correct 515 ms 2812 KB Output is correct
12 Correct 518 ms 2692 KB Output is correct
13 Correct 514 ms 2724 KB Output is correct
14 Correct 533 ms 2652 KB Output is correct
15 Correct 517 ms 2716 KB Output is correct
16 Correct 523 ms 2624 KB Output is correct
17 Correct 515 ms 2664 KB Output is correct
18 Correct 648 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 1228 KB Output is correct
2 Correct 570 ms 2632 KB Output is correct
3 Correct 659 ms 2708 KB Output is correct
4 Correct 491 ms 2696 KB Output is correct
5 Correct 476 ms 2588 KB Output is correct
6 Correct 485 ms 2512 KB Output is correct
7 Correct 515 ms 2668 KB Output is correct
8 Correct 516 ms 2628 KB Output is correct
9 Correct 532 ms 2796 KB Output is correct
10 Correct 533 ms 2776 KB Output is correct
11 Correct 515 ms 2812 KB Output is correct
12 Correct 518 ms 2692 KB Output is correct
13 Correct 514 ms 2724 KB Output is correct
14 Correct 533 ms 2652 KB Output is correct
15 Correct 517 ms 2716 KB Output is correct
16 Correct 523 ms 2624 KB Output is correct
17 Correct 515 ms 2664 KB Output is correct
18 Correct 648 ms 2640 KB Output is correct
19 Correct 4086 ms 202868 KB Output is correct
20 Correct 3844 ms 202528 KB Output is correct
21 Correct 2609 ms 190832 KB Output is correct
22 Correct 2498 ms 171528 KB Output is correct
23 Correct 1087 ms 13640 KB Output is correct
24 Correct 1124 ms 13540 KB Output is correct
25 Correct 2704 ms 202652 KB Output is correct
26 Correct 2738 ms 202716 KB Output is correct
27 Correct 3339 ms 202588 KB Output is correct
28 Correct 3397 ms 202832 KB Output is correct
29 Correct 3127 ms 197288 KB Output is correct
30 Correct 1240 ms 13720 KB Output is correct
31 Correct 3275 ms 202708 KB Output is correct
32 Correct 3017 ms 185300 KB Output is correct
33 Correct 1086 ms 13512 KB Output is correct
34 Correct 3263 ms 202684 KB Output is correct
35 Correct 2320 ms 151868 KB Output is correct
36 Correct 1055 ms 13516 KB Output is correct
37 Correct 1047 ms 13480 KB Output is correct
38 Correct 3151 ms 202424 KB Output is correct
39 Correct 1123 ms 202632 KB Output is correct
40 Correct 2580 ms 134312 KB Output is correct
41 Correct 4280 ms 203112 KB Output is correct
42 Correct 1419 ms 202272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 1228 KB Output is correct
2 Correct 570 ms 2632 KB Output is correct
3 Correct 659 ms 2708 KB Output is correct
4 Correct 491 ms 2696 KB Output is correct
5 Correct 476 ms 2588 KB Output is correct
6 Correct 485 ms 2512 KB Output is correct
7 Correct 515 ms 2668 KB Output is correct
8 Correct 516 ms 2628 KB Output is correct
9 Correct 532 ms 2796 KB Output is correct
10 Correct 533 ms 2776 KB Output is correct
11 Correct 515 ms 2812 KB Output is correct
12 Correct 518 ms 2692 KB Output is correct
13 Correct 514 ms 2724 KB Output is correct
14 Correct 533 ms 2652 KB Output is correct
15 Correct 517 ms 2716 KB Output is correct
16 Correct 523 ms 2624 KB Output is correct
17 Correct 515 ms 2664 KB Output is correct
18 Correct 648 ms 2640 KB Output is correct
19 Correct 550 ms 2744 KB Output is correct
20 Correct 638 ms 2524 KB Output is correct
21 Correct 509 ms 2636 KB Output is correct
22 Correct 444 ms 2764 KB Output is correct
23 Correct 501 ms 2660 KB Output is correct
24 Correct 487 ms 2560 KB Output is correct
25 Correct 515 ms 2868 KB Output is correct
26 Correct 475 ms 2508 KB Output is correct
27 Correct 502 ms 2764 KB Output is correct
28 Correct 461 ms 2448 KB Output is correct
29 Correct 503 ms 2716 KB Output is correct
30 Correct 450 ms 2564 KB Output is correct
31 Correct 507 ms 2804 KB Output is correct
32 Correct 491 ms 2660 KB Output is correct
33 Correct 512 ms 2884 KB Output is correct
34 Correct 458 ms 2668 KB Output is correct
35 Correct 518 ms 2684 KB Output is correct
36 Correct 525 ms 2712 KB Output is correct
37 Correct 506 ms 2668 KB Output is correct
38 Correct 505 ms 2640 KB Output is correct
39 Correct 512 ms 2704 KB Output is correct
40 Correct 511 ms 2668 KB Output is correct
41 Correct 506 ms 2636 KB Output is correct
42 Correct 506 ms 2640 KB Output is correct
43 Correct 492 ms 2612 KB Output is correct
44 Correct 500 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 501 ms 1228 KB Output is correct
2 Correct 570 ms 2632 KB Output is correct
3 Correct 659 ms 2708 KB Output is correct
4 Correct 491 ms 2696 KB Output is correct
5 Correct 476 ms 2588 KB Output is correct
6 Correct 485 ms 2512 KB Output is correct
7 Correct 515 ms 2668 KB Output is correct
8 Correct 516 ms 2628 KB Output is correct
9 Correct 532 ms 2796 KB Output is correct
10 Correct 533 ms 2776 KB Output is correct
11 Correct 515 ms 2812 KB Output is correct
12 Correct 518 ms 2692 KB Output is correct
13 Correct 514 ms 2724 KB Output is correct
14 Correct 533 ms 2652 KB Output is correct
15 Correct 517 ms 2716 KB Output is correct
16 Correct 523 ms 2624 KB Output is correct
17 Correct 515 ms 2664 KB Output is correct
18 Correct 648 ms 2640 KB Output is correct
19 Correct 4086 ms 202868 KB Output is correct
20 Correct 3844 ms 202528 KB Output is correct
21 Correct 2609 ms 190832 KB Output is correct
22 Correct 2498 ms 171528 KB Output is correct
23 Correct 1087 ms 13640 KB Output is correct
24 Correct 1124 ms 13540 KB Output is correct
25 Correct 2704 ms 202652 KB Output is correct
26 Correct 2738 ms 202716 KB Output is correct
27 Correct 3339 ms 202588 KB Output is correct
28 Correct 3397 ms 202832 KB Output is correct
29 Correct 3127 ms 197288 KB Output is correct
30 Correct 1240 ms 13720 KB Output is correct
31 Correct 3275 ms 202708 KB Output is correct
32 Correct 3017 ms 185300 KB Output is correct
33 Correct 1086 ms 13512 KB Output is correct
34 Correct 3263 ms 202684 KB Output is correct
35 Correct 2320 ms 151868 KB Output is correct
36 Correct 1055 ms 13516 KB Output is correct
37 Correct 1047 ms 13480 KB Output is correct
38 Correct 3151 ms 202424 KB Output is correct
39 Correct 1123 ms 202632 KB Output is correct
40 Correct 2580 ms 134312 KB Output is correct
41 Correct 4280 ms 203112 KB Output is correct
42 Correct 1419 ms 202272 KB Output is correct
43 Correct 550 ms 2744 KB Output is correct
44 Correct 638 ms 2524 KB Output is correct
45 Correct 509 ms 2636 KB Output is correct
46 Correct 444 ms 2764 KB Output is correct
47 Correct 501 ms 2660 KB Output is correct
48 Correct 487 ms 2560 KB Output is correct
49 Correct 515 ms 2868 KB Output is correct
50 Correct 475 ms 2508 KB Output is correct
51 Correct 502 ms 2764 KB Output is correct
52 Correct 461 ms 2448 KB Output is correct
53 Correct 503 ms 2716 KB Output is correct
54 Correct 450 ms 2564 KB Output is correct
55 Correct 507 ms 2804 KB Output is correct
56 Correct 491 ms 2660 KB Output is correct
57 Correct 512 ms 2884 KB Output is correct
58 Correct 458 ms 2668 KB Output is correct
59 Correct 518 ms 2684 KB Output is correct
60 Correct 525 ms 2712 KB Output is correct
61 Correct 506 ms 2668 KB Output is correct
62 Correct 505 ms 2640 KB Output is correct
63 Correct 512 ms 2704 KB Output is correct
64 Correct 511 ms 2668 KB Output is correct
65 Correct 506 ms 2636 KB Output is correct
66 Correct 506 ms 2640 KB Output is correct
67 Correct 492 ms 2612 KB Output is correct
68 Correct 500 ms 2624 KB Output is correct
69 Correct 3601 ms 170004 KB Output is correct
70 Correct 3586 ms 202500 KB Output is correct
71 Correct 1141 ms 13644 KB Output is correct
72 Correct 1096 ms 13688 KB Output is correct
73 Correct 1070 ms 13828 KB Output is correct
74 Correct 2380 ms 169460 KB Output is correct
75 Correct 1040 ms 13468 KB Output is correct
76 Correct 2704 ms 202656 KB Output is correct
77 Correct 2552 ms 169824 KB Output is correct
78 Correct 1076 ms 13508 KB Output is correct
79 Correct 1128 ms 13824 KB Output is correct
80 Correct 2369 ms 145140 KB Output is correct
81 Correct 1030 ms 13392 KB Output is correct
82 Correct 2720 ms 202772 KB Output is correct
83 Correct 2648 ms 190756 KB Output is correct
84 Correct 1133 ms 13412 KB Output is correct
85 Correct 1083 ms 13296 KB Output is correct
86 Correct 3116 ms 154924 KB Output is correct
87 Correct 3451 ms 202684 KB Output is correct
88 Correct 1164 ms 13816 KB Output is correct
89 Correct 2941 ms 179052 KB Output is correct
90 Correct 3178 ms 202964 KB Output is correct
91 Correct 1118 ms 13388 KB Output is correct
92 Correct 2317 ms 152372 KB Output is correct
93 Correct 1054 ms 13388 KB Output is correct
94 Correct 1052 ms 13320 KB Output is correct
95 Correct 1061 ms 13516 KB Output is correct
96 Correct 3143 ms 202672 KB Output is correct
97 Correct 1132 ms 202672 KB Output is correct
98 Correct 2608 ms 134204 KB Output is correct
99 Correct 4409 ms 202916 KB Output is correct
100 Correct 1378 ms 202124 KB Output is correct