답안 #780756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780756 2023-07-12T12:43:42 Z Rafi22 Crossing (JOI21_crossing) C++14
100 / 100
2470 ms 195656 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

map<vector<int>,bool>odw;

const int N=200007,pot=1<<18;

int a[N][3];
int b[N][9];
int id[300];

struct tree
{
    int seg[2*pot+7],cnt[2*pot+7][3],lzy[2*pot+7];
    tree()
    {
        memset(seg,0,sizeof seg);
        memset(cnt,0,sizeof cnt);
    }
    void push(int v)
    {
        if(lzy[v]!=-1)
        {
            seg[2*v]=cnt[2*v][lzy[v]];
            lzy[2*v]=lzy[v];
            seg[2*v+1]=cnt[2*v+1][lzy[v]];
            lzy[2*v+1]=lzy[v];
        }
        lzy[v]=-1;
    }
    void upd(int v,int a,int b,int l,int r,int x)
    {
        if(a<=l&&b>=r)
        {
            seg[v]=cnt[v][x];
            lzy[v]=x;
            return;
        }
        if(r<a||l>b) return ;
        push(v);
        upd(2*v,a,b,l,(l+r)/2,x);
        upd(2*v+1,a,b,(l+r)/2+1,r,x);
        seg[v]=seg[2*v]+seg[2*v+1];
    }
};


int n;
vector<tree>T;
void get()
{
    bool ans=0;
    for(int j=0;j<9;j++)
    {
        if(T[j].seg[1]==n) ans=1;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector<vector<int>>V;
    V.pb({1,0,0});
    odw[{1,0,0}]=1;
    V.pb({0,1,0});
    odw[{0,1,0}]=1;
    V.pb({0,0,1});
    odw[{0,0,1}]=1;
    for(int i=0;i<sz(V);i++)
    {
        for(int j=0;j<i;j++)
        {
            vector<int>X(3);
            for(int l=0;l<3;l++)
            {
                X[l]=(-V[i][l]-V[j][l]+6)%3;
            }
            if(!odw[X])
            {
                V.pb(X);
                odw[X]=1;
            }
        }
    }
    id['J']=0;
    id['O']=1;
    id['I']=2;
    cin>>n;
    string s;
    for(int j=0;j<3;j++)
    {
        cin>>s;
        for(int i=1;i<=n;i++) a[i][j]=id[s[i-1]];
    }
    for(int j=0;j<9;j++)
    {
        tree X;
        for(int i=1;i<=n;i++)
        {
            for(int l=0;l<3;l++)
            {
                b[i][j]=(b[i][j]+a[i][l]*V[j][l])%3;
            }
            X.cnt[i+pot-1][b[i][j]]=1;
        }
        for(int i=pot-1;i>0;i--)
        {
            for(int j=0;j<3;j++) X.cnt[i][j]=X.cnt[2*i][j]+X.cnt[2*i+1][j];
        }
        for(int i=1;i<2*pot;i++) X.lzy[i]=-1;
        T.pb(X);
    }
    int q;
    cin>>q>>s;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<9;j++) T[j].upd(1,i,i,1,pot,id[s[i-1]]);
    }
    get();
    while(q--)
    {
        int l,r;
        char x;
        cin>>l>>r>>x;
        for(int j=0;j<9;j++) T[j].upd(1,l,r,1,pot,id[x]);
        get();
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:109:48: warning: array subscript has type 'char' [-Wchar-subscripts]
  109 |         for(int i=1;i<=n;i++) a[i][j]=id[s[i-1]];
      |                                                ^
Main.cpp:133:60: warning: array subscript has type 'char' [-Wchar-subscripts]
  133 |         for(int j=0;j<9;j++) T[j].upd(1,i,i,1,pot,id[s[i-1]]);
      |                                                            ^
Main.cpp:141:54: warning: array subscript has type 'char' [-Wchar-subscripts]
  141 |         for(int j=0;j<9;j++) T[j].upd(1,l,r,1,pot,id[x]);
      |                                                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 185048 KB Output is correct
2 Correct 601 ms 185012 KB Output is correct
3 Correct 599 ms 185012 KB Output is correct
4 Correct 518 ms 185016 KB Output is correct
5 Correct 536 ms 185056 KB Output is correct
6 Correct 505 ms 185052 KB Output is correct
7 Correct 536 ms 185028 KB Output is correct
8 Correct 547 ms 184968 KB Output is correct
9 Correct 556 ms 185016 KB Output is correct
10 Correct 536 ms 185072 KB Output is correct
11 Correct 534 ms 185012 KB Output is correct
12 Correct 582 ms 184984 KB Output is correct
13 Correct 564 ms 185020 KB Output is correct
14 Correct 586 ms 185012 KB Output is correct
15 Correct 569 ms 184964 KB Output is correct
16 Correct 540 ms 185032 KB Output is correct
17 Correct 545 ms 185188 KB Output is correct
18 Correct 621 ms 184972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 185048 KB Output is correct
2 Correct 601 ms 185012 KB Output is correct
3 Correct 599 ms 185012 KB Output is correct
4 Correct 518 ms 185016 KB Output is correct
5 Correct 536 ms 185056 KB Output is correct
6 Correct 505 ms 185052 KB Output is correct
7 Correct 536 ms 185028 KB Output is correct
8 Correct 547 ms 184968 KB Output is correct
9 Correct 556 ms 185016 KB Output is correct
10 Correct 536 ms 185072 KB Output is correct
11 Correct 534 ms 185012 KB Output is correct
12 Correct 582 ms 184984 KB Output is correct
13 Correct 564 ms 185020 KB Output is correct
14 Correct 586 ms 185012 KB Output is correct
15 Correct 569 ms 184964 KB Output is correct
16 Correct 540 ms 185032 KB Output is correct
17 Correct 545 ms 185188 KB Output is correct
18 Correct 621 ms 184972 KB Output is correct
19 Correct 2274 ms 195364 KB Output is correct
20 Correct 1881 ms 195524 KB Output is correct
21 Correct 1387 ms 194828 KB Output is correct
22 Correct 1396 ms 193988 KB Output is correct
23 Correct 596 ms 185524 KB Output is correct
24 Correct 643 ms 185508 KB Output is correct
25 Correct 1417 ms 195396 KB Output is correct
26 Correct 1526 ms 195396 KB Output is correct
27 Correct 1786 ms 195444 KB Output is correct
28 Correct 1819 ms 195348 KB Output is correct
29 Correct 1772 ms 195188 KB Output is correct
30 Correct 684 ms 185532 KB Output is correct
31 Correct 1916 ms 195416 KB Output is correct
32 Correct 1683 ms 194628 KB Output is correct
33 Correct 617 ms 185524 KB Output is correct
34 Correct 1775 ms 195392 KB Output is correct
35 Correct 1229 ms 192824 KB Output is correct
36 Correct 621 ms 185544 KB Output is correct
37 Correct 610 ms 185592 KB Output is correct
38 Correct 1447 ms 195396 KB Output is correct
39 Correct 681 ms 195656 KB Output is correct
40 Correct 1269 ms 191936 KB Output is correct
41 Correct 2416 ms 195380 KB Output is correct
42 Correct 603 ms 195396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 185048 KB Output is correct
2 Correct 601 ms 185012 KB Output is correct
3 Correct 599 ms 185012 KB Output is correct
4 Correct 518 ms 185016 KB Output is correct
5 Correct 536 ms 185056 KB Output is correct
6 Correct 505 ms 185052 KB Output is correct
7 Correct 536 ms 185028 KB Output is correct
8 Correct 547 ms 184968 KB Output is correct
9 Correct 556 ms 185016 KB Output is correct
10 Correct 536 ms 185072 KB Output is correct
11 Correct 534 ms 185012 KB Output is correct
12 Correct 582 ms 184984 KB Output is correct
13 Correct 564 ms 185020 KB Output is correct
14 Correct 586 ms 185012 KB Output is correct
15 Correct 569 ms 184964 KB Output is correct
16 Correct 540 ms 185032 KB Output is correct
17 Correct 545 ms 185188 KB Output is correct
18 Correct 621 ms 184972 KB Output is correct
19 Correct 541 ms 185060 KB Output is correct
20 Correct 580 ms 185060 KB Output is correct
21 Correct 530 ms 185028 KB Output is correct
22 Correct 508 ms 185028 KB Output is correct
23 Correct 560 ms 185012 KB Output is correct
24 Correct 532 ms 185116 KB Output is correct
25 Correct 522 ms 184980 KB Output is correct
26 Correct 511 ms 185008 KB Output is correct
27 Correct 523 ms 184952 KB Output is correct
28 Correct 504 ms 185012 KB Output is correct
29 Correct 530 ms 185008 KB Output is correct
30 Correct 501 ms 184984 KB Output is correct
31 Correct 527 ms 184992 KB Output is correct
32 Correct 545 ms 185008 KB Output is correct
33 Correct 516 ms 185016 KB Output is correct
34 Correct 503 ms 185012 KB Output is correct
35 Correct 524 ms 185004 KB Output is correct
36 Correct 541 ms 185032 KB Output is correct
37 Correct 537 ms 185012 KB Output is correct
38 Correct 529 ms 184960 KB Output is correct
39 Correct 529 ms 184980 KB Output is correct
40 Correct 529 ms 184984 KB Output is correct
41 Correct 537 ms 185020 KB Output is correct
42 Correct 539 ms 185016 KB Output is correct
43 Correct 525 ms 185012 KB Output is correct
44 Correct 547 ms 185028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 185048 KB Output is correct
2 Correct 601 ms 185012 KB Output is correct
3 Correct 599 ms 185012 KB Output is correct
4 Correct 518 ms 185016 KB Output is correct
5 Correct 536 ms 185056 KB Output is correct
6 Correct 505 ms 185052 KB Output is correct
7 Correct 536 ms 185028 KB Output is correct
8 Correct 547 ms 184968 KB Output is correct
9 Correct 556 ms 185016 KB Output is correct
10 Correct 536 ms 185072 KB Output is correct
11 Correct 534 ms 185012 KB Output is correct
12 Correct 582 ms 184984 KB Output is correct
13 Correct 564 ms 185020 KB Output is correct
14 Correct 586 ms 185012 KB Output is correct
15 Correct 569 ms 184964 KB Output is correct
16 Correct 540 ms 185032 KB Output is correct
17 Correct 545 ms 185188 KB Output is correct
18 Correct 621 ms 184972 KB Output is correct
19 Correct 2274 ms 195364 KB Output is correct
20 Correct 1881 ms 195524 KB Output is correct
21 Correct 1387 ms 194828 KB Output is correct
22 Correct 1396 ms 193988 KB Output is correct
23 Correct 596 ms 185524 KB Output is correct
24 Correct 643 ms 185508 KB Output is correct
25 Correct 1417 ms 195396 KB Output is correct
26 Correct 1526 ms 195396 KB Output is correct
27 Correct 1786 ms 195444 KB Output is correct
28 Correct 1819 ms 195348 KB Output is correct
29 Correct 1772 ms 195188 KB Output is correct
30 Correct 684 ms 185532 KB Output is correct
31 Correct 1916 ms 195416 KB Output is correct
32 Correct 1683 ms 194628 KB Output is correct
33 Correct 617 ms 185524 KB Output is correct
34 Correct 1775 ms 195392 KB Output is correct
35 Correct 1229 ms 192824 KB Output is correct
36 Correct 621 ms 185544 KB Output is correct
37 Correct 610 ms 185592 KB Output is correct
38 Correct 1447 ms 195396 KB Output is correct
39 Correct 681 ms 195656 KB Output is correct
40 Correct 1269 ms 191936 KB Output is correct
41 Correct 2416 ms 195380 KB Output is correct
42 Correct 603 ms 195396 KB Output is correct
43 Correct 541 ms 185060 KB Output is correct
44 Correct 580 ms 185060 KB Output is correct
45 Correct 530 ms 185028 KB Output is correct
46 Correct 508 ms 185028 KB Output is correct
47 Correct 560 ms 185012 KB Output is correct
48 Correct 532 ms 185116 KB Output is correct
49 Correct 522 ms 184980 KB Output is correct
50 Correct 511 ms 185008 KB Output is correct
51 Correct 523 ms 184952 KB Output is correct
52 Correct 504 ms 185012 KB Output is correct
53 Correct 530 ms 185008 KB Output is correct
54 Correct 501 ms 184984 KB Output is correct
55 Correct 527 ms 184992 KB Output is correct
56 Correct 545 ms 185008 KB Output is correct
57 Correct 516 ms 185016 KB Output is correct
58 Correct 503 ms 185012 KB Output is correct
59 Correct 524 ms 185004 KB Output is correct
60 Correct 541 ms 185032 KB Output is correct
61 Correct 537 ms 185012 KB Output is correct
62 Correct 529 ms 184960 KB Output is correct
63 Correct 529 ms 184980 KB Output is correct
64 Correct 529 ms 184984 KB Output is correct
65 Correct 537 ms 185020 KB Output is correct
66 Correct 539 ms 185016 KB Output is correct
67 Correct 525 ms 185012 KB Output is correct
68 Correct 547 ms 185028 KB Output is correct
69 Correct 1862 ms 193796 KB Output is correct
70 Correct 1642 ms 195396 KB Output is correct
71 Correct 606 ms 185628 KB Output is correct
72 Correct 624 ms 185660 KB Output is correct
73 Correct 604 ms 185592 KB Output is correct
74 Correct 1290 ms 193864 KB Output is correct
75 Correct 626 ms 185588 KB Output is correct
76 Correct 1447 ms 195368 KB Output is correct
77 Correct 1454 ms 193880 KB Output is correct
78 Correct 591 ms 185524 KB Output is correct
79 Correct 616 ms 185524 KB Output is correct
80 Correct 1266 ms 192580 KB Output is correct
81 Correct 611 ms 185632 KB Output is correct
82 Correct 1424 ms 195392 KB Output is correct
83 Correct 1451 ms 194792 KB Output is correct
84 Correct 608 ms 185536 KB Output is correct
85 Correct 608 ms 185524 KB Output is correct
86 Correct 1666 ms 192960 KB Output is correct
87 Correct 1835 ms 195464 KB Output is correct
88 Correct 646 ms 185544 KB Output is correct
89 Correct 1557 ms 194256 KB Output is correct
90 Correct 1696 ms 195396 KB Output is correct
91 Correct 683 ms 185524 KB Output is correct
92 Correct 1330 ms 192888 KB Output is correct
93 Correct 615 ms 185600 KB Output is correct
94 Correct 658 ms 185552 KB Output is correct
95 Correct 667 ms 185596 KB Output is correct
96 Correct 1575 ms 195468 KB Output is correct
97 Correct 714 ms 195432 KB Output is correct
98 Correct 1364 ms 191940 KB Output is correct
99 Correct 2470 ms 195352 KB Output is correct
100 Correct 597 ms 195444 KB Output is correct