답안 #771098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771098 2023-07-02T12:42:28 Z gagik_2007 Crossing (JOI21_crossing) C++17
100 / 100
510 ms 19372 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=2e5+7;
ll n,m,k;
vector<string>b;
string s1,s2,s3,tt;
char vs[3]={'J', 'O', 'I'};
int vls[500];
const ll B=7;
ll powB[N];
ll powBsum[N];
ll t[4*N];
ll lazy[8*N];
vector<ll>hashes;

ll str_hash(const string& s) {
    ll ans=0;
    ll cur=1;
    for(char c:s){
        ans+=vls[c]*cur;
        ans%=MOD;
        cur*=B;
        cur%=MOD;
    }
    return ans;
}

void push(int v, int tl, int tr) {
    if(lazy[v]!=0){
        lazy[v]--;
        t[v]=lazy[v]*powB[tl]*powBsum[tr-tl];
        t[v]%=MOD;
        lazy[v]++;
        lazy[2*v]=lazy[v];
        lazy[2*v+1]=lazy[v];
        lazy[v]=0;
    }
}

void build(int v, int tl, int tr) {
    if(tl==tr){
        t[v]=vls[tt[tl]]*powB[tl];
        t[v]%=MOD;
    }
    else{
        int tm=(tl+tr)/2;
        build(2*v,tl,tm);
        build(2*v+1,tm+1,tr);
        t[v]=t[2*v]+t[2*v+1];
        t[v]%=MOD;
    }
}

void update(int v, int tl, int tr, int l, int r, char c) {
    push(v,tl,tr);
    if(l>r)return;
    if(tl==l&&tr==r){
        lazy[v]=vls[c]+1;
        push(v,tl,tr);
    }
    else{
        push(v,tl,tr);
        int tm=(tl+tr)/2;
        update(2*v,tl,tm,l,min(r,tm),c);
        update(2*v+1,tm+1,tr,max(l,tm+1),r,c);
        t[v]=t[2*v]+t[2*v+1];
        t[v]%=MOD;
        push(v,tl,tr);
    }
}

string cross(const string& a, const string& b) {
    string c;
    for(int i=0;i<a.size();i++){
        if(a[i]==b[i]){
            c+=a[i];
        }
        else {
            c+=vs[3-vls[a[i]]-vls[b[i]]];
        }
    }
    return c;
}

bool compare(){
    for(ll h:hashes){
        if(h==t[1])return true;
    }
    return false;
}

void precalc() {
    vls['J']=0;
    vls['O']=1;
    vls['I']=2;
    powB[0]=1;
    powBsum[0]=1;
    for(int i=1;i<N;i++){
        powB[i]=powB[i-1]*B;
        powB[i]%=MOD;
        powBsum[i]=powBsum[i-1]+powB[i];
        powBsum[i]%=MOD;
    }
}

int main() {
    precalc();
    cin>>n;
    cin>>s1>>s2>>s3;
    b.push_back(s1);
    b.push_back(s2);
    b.push_back(s3);
    b.push_back(cross(s1,s2));
    b.push_back(cross(s2,s3));
    b.push_back(cross(s1,s3));
    b.push_back(cross(b[3],b[4]));
    b.push_back(cross(b[3],b[5]));
    b.push_back(cross(b[4],b[5]));
    for(string& s:b){
        hashes.push_back(str_hash(s));
    }
    cin>>m;
    cin>>tt;
    build(1,0,n-1);
    if(compare()){
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    for(int i=0;i<m;i++){
        int l,r;
        char c;
        cin>>l>>r>>c;
        l--,r--;
        update(1,0,n-1,l,r,c);
        // for(int i=0;i<100;i++)cout<<t[i]<<" ";cout<<endl;
        // for(int i=0;i<100;i++)cout<<lazy[i]<<" ";cout<<endl;
        if(compare()){
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }
}

Compilation message

Main.cpp: In function 'll str_hash(const string&)':
Main.cpp:29:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   29 |         ans+=vls[c]*cur;
      |                  ^
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:51:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   51 |         t[v]=vls[tt[tl]]*powB[tl];
      |                        ^
Main.cpp: In function 'void update(int, int, int, int, int, char)':
Main.cpp:67:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |         lazy[v]=vls[c]+1;
      |                     ^
Main.cpp: In function 'std::string cross(const string&, const string&)':
Main.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
Main.cpp:88:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   88 |             c+=vs[3-vls[a[i]]-vls[b[i]]];
      |                             ^
Main.cpp:88:39: warning: array subscript has type 'char' [-Wchar-subscripts]
   88 |             c+=vs[3-vls[a[i]]-vls[b[i]]];
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 3916 KB Output is correct
2 Correct 307 ms 3984 KB Output is correct
3 Correct 313 ms 4044 KB Output is correct
4 Correct 296 ms 3936 KB Output is correct
5 Correct 287 ms 3972 KB Output is correct
6 Correct 281 ms 3884 KB Output is correct
7 Correct 294 ms 4024 KB Output is correct
8 Correct 300 ms 4252 KB Output is correct
9 Correct 299 ms 3968 KB Output is correct
10 Correct 301 ms 4136 KB Output is correct
11 Correct 299 ms 3972 KB Output is correct
12 Correct 298 ms 3916 KB Output is correct
13 Correct 301 ms 3992 KB Output is correct
14 Correct 299 ms 4020 KB Output is correct
15 Correct 302 ms 4228 KB Output is correct
16 Correct 299 ms 4020 KB Output is correct
17 Correct 304 ms 4044 KB Output is correct
18 Correct 299 ms 4056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 3916 KB Output is correct
2 Correct 307 ms 3984 KB Output is correct
3 Correct 313 ms 4044 KB Output is correct
4 Correct 296 ms 3936 KB Output is correct
5 Correct 287 ms 3972 KB Output is correct
6 Correct 281 ms 3884 KB Output is correct
7 Correct 294 ms 4024 KB Output is correct
8 Correct 300 ms 4252 KB Output is correct
9 Correct 299 ms 3968 KB Output is correct
10 Correct 301 ms 4136 KB Output is correct
11 Correct 299 ms 3972 KB Output is correct
12 Correct 298 ms 3916 KB Output is correct
13 Correct 301 ms 3992 KB Output is correct
14 Correct 299 ms 4020 KB Output is correct
15 Correct 302 ms 4228 KB Output is correct
16 Correct 299 ms 4020 KB Output is correct
17 Correct 304 ms 4044 KB Output is correct
18 Correct 299 ms 4056 KB Output is correct
19 Correct 492 ms 19104 KB Output is correct
20 Correct 471 ms 12540 KB Output is correct
21 Correct 404 ms 18728 KB Output is correct
22 Correct 392 ms 18552 KB Output is correct
23 Correct 348 ms 4920 KB Output is correct
24 Correct 348 ms 4944 KB Output is correct
25 Correct 423 ms 18920 KB Output is correct
26 Correct 440 ms 19056 KB Output is correct
27 Correct 447 ms 18676 KB Output is correct
28 Correct 450 ms 19004 KB Output is correct
29 Correct 447 ms 18604 KB Output is correct
30 Correct 360 ms 4920 KB Output is correct
31 Correct 442 ms 18772 KB Output is correct
32 Correct 423 ms 18696 KB Output is correct
33 Correct 351 ms 4952 KB Output is correct
34 Correct 444 ms 18952 KB Output is correct
35 Correct 400 ms 18440 KB Output is correct
36 Correct 352 ms 4940 KB Output is correct
37 Correct 362 ms 4940 KB Output is correct
38 Correct 441 ms 12548 KB Output is correct
39 Correct 398 ms 10840 KB Output is correct
40 Correct 405 ms 12040 KB Output is correct
41 Correct 510 ms 19372 KB Output is correct
42 Correct 308 ms 10936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 3916 KB Output is correct
2 Correct 307 ms 3984 KB Output is correct
3 Correct 313 ms 4044 KB Output is correct
4 Correct 296 ms 3936 KB Output is correct
5 Correct 287 ms 3972 KB Output is correct
6 Correct 281 ms 3884 KB Output is correct
7 Correct 294 ms 4024 KB Output is correct
8 Correct 300 ms 4252 KB Output is correct
9 Correct 299 ms 3968 KB Output is correct
10 Correct 301 ms 4136 KB Output is correct
11 Correct 299 ms 3972 KB Output is correct
12 Correct 298 ms 3916 KB Output is correct
13 Correct 301 ms 3992 KB Output is correct
14 Correct 299 ms 4020 KB Output is correct
15 Correct 302 ms 4228 KB Output is correct
16 Correct 299 ms 4020 KB Output is correct
17 Correct 304 ms 4044 KB Output is correct
18 Correct 299 ms 4056 KB Output is correct
19 Correct 299 ms 4104 KB Output is correct
20 Correct 303 ms 4028 KB Output is correct
21 Correct 300 ms 3992 KB Output is correct
22 Correct 270 ms 3880 KB Output is correct
23 Correct 303 ms 4032 KB Output is correct
24 Correct 295 ms 3920 KB Output is correct
25 Correct 300 ms 3920 KB Output is correct
26 Correct 285 ms 4000 KB Output is correct
27 Correct 307 ms 3928 KB Output is correct
28 Correct 283 ms 4020 KB Output is correct
29 Correct 318 ms 3916 KB Output is correct
30 Correct 285 ms 3996 KB Output is correct
31 Correct 299 ms 3936 KB Output is correct
32 Correct 298 ms 4008 KB Output is correct
33 Correct 299 ms 3944 KB Output is correct
34 Correct 279 ms 3916 KB Output is correct
35 Correct 307 ms 4020 KB Output is correct
36 Correct 299 ms 3960 KB Output is correct
37 Correct 300 ms 4032 KB Output is correct
38 Correct 303 ms 4008 KB Output is correct
39 Correct 301 ms 3916 KB Output is correct
40 Correct 302 ms 3968 KB Output is correct
41 Correct 296 ms 3988 KB Output is correct
42 Correct 305 ms 4024 KB Output is correct
43 Correct 292 ms 3916 KB Output is correct
44 Correct 305 ms 4020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 280 ms 3916 KB Output is correct
2 Correct 307 ms 3984 KB Output is correct
3 Correct 313 ms 4044 KB Output is correct
4 Correct 296 ms 3936 KB Output is correct
5 Correct 287 ms 3972 KB Output is correct
6 Correct 281 ms 3884 KB Output is correct
7 Correct 294 ms 4024 KB Output is correct
8 Correct 300 ms 4252 KB Output is correct
9 Correct 299 ms 3968 KB Output is correct
10 Correct 301 ms 4136 KB Output is correct
11 Correct 299 ms 3972 KB Output is correct
12 Correct 298 ms 3916 KB Output is correct
13 Correct 301 ms 3992 KB Output is correct
14 Correct 299 ms 4020 KB Output is correct
15 Correct 302 ms 4228 KB Output is correct
16 Correct 299 ms 4020 KB Output is correct
17 Correct 304 ms 4044 KB Output is correct
18 Correct 299 ms 4056 KB Output is correct
19 Correct 492 ms 19104 KB Output is correct
20 Correct 471 ms 12540 KB Output is correct
21 Correct 404 ms 18728 KB Output is correct
22 Correct 392 ms 18552 KB Output is correct
23 Correct 348 ms 4920 KB Output is correct
24 Correct 348 ms 4944 KB Output is correct
25 Correct 423 ms 18920 KB Output is correct
26 Correct 440 ms 19056 KB Output is correct
27 Correct 447 ms 18676 KB Output is correct
28 Correct 450 ms 19004 KB Output is correct
29 Correct 447 ms 18604 KB Output is correct
30 Correct 360 ms 4920 KB Output is correct
31 Correct 442 ms 18772 KB Output is correct
32 Correct 423 ms 18696 KB Output is correct
33 Correct 351 ms 4952 KB Output is correct
34 Correct 444 ms 18952 KB Output is correct
35 Correct 400 ms 18440 KB Output is correct
36 Correct 352 ms 4940 KB Output is correct
37 Correct 362 ms 4940 KB Output is correct
38 Correct 441 ms 12548 KB Output is correct
39 Correct 398 ms 10840 KB Output is correct
40 Correct 405 ms 12040 KB Output is correct
41 Correct 510 ms 19372 KB Output is correct
42 Correct 308 ms 10936 KB Output is correct
43 Correct 299 ms 4104 KB Output is correct
44 Correct 303 ms 4028 KB Output is correct
45 Correct 300 ms 3992 KB Output is correct
46 Correct 270 ms 3880 KB Output is correct
47 Correct 303 ms 4032 KB Output is correct
48 Correct 295 ms 3920 KB Output is correct
49 Correct 300 ms 3920 KB Output is correct
50 Correct 285 ms 4000 KB Output is correct
51 Correct 307 ms 3928 KB Output is correct
52 Correct 283 ms 4020 KB Output is correct
53 Correct 318 ms 3916 KB Output is correct
54 Correct 285 ms 3996 KB Output is correct
55 Correct 299 ms 3936 KB Output is correct
56 Correct 298 ms 4008 KB Output is correct
57 Correct 299 ms 3944 KB Output is correct
58 Correct 279 ms 3916 KB Output is correct
59 Correct 307 ms 4020 KB Output is correct
60 Correct 299 ms 3960 KB Output is correct
61 Correct 300 ms 4032 KB Output is correct
62 Correct 303 ms 4008 KB Output is correct
63 Correct 301 ms 3916 KB Output is correct
64 Correct 302 ms 3968 KB Output is correct
65 Correct 296 ms 3988 KB Output is correct
66 Correct 305 ms 4024 KB Output is correct
67 Correct 292 ms 3916 KB Output is correct
68 Correct 305 ms 4020 KB Output is correct
69 Correct 427 ms 18448 KB Output is correct
70 Correct 484 ms 12552 KB Output is correct
71 Correct 350 ms 4936 KB Output is correct
72 Correct 354 ms 4968 KB Output is correct
73 Correct 358 ms 4940 KB Output is correct
74 Correct 404 ms 18548 KB Output is correct
75 Correct 354 ms 4940 KB Output is correct
76 Correct 442 ms 19116 KB Output is correct
77 Correct 409 ms 18536 KB Output is correct
78 Correct 352 ms 4928 KB Output is correct
79 Correct 348 ms 4956 KB Output is correct
80 Correct 382 ms 18216 KB Output is correct
81 Correct 350 ms 4940 KB Output is correct
82 Correct 460 ms 19012 KB Output is correct
83 Correct 417 ms 18828 KB Output is correct
84 Correct 348 ms 4980 KB Output is correct
85 Correct 356 ms 4884 KB Output is correct
86 Correct 409 ms 18372 KB Output is correct
87 Correct 456 ms 19028 KB Output is correct
88 Correct 371 ms 4936 KB Output is correct
89 Correct 422 ms 18748 KB Output is correct
90 Correct 454 ms 18972 KB Output is correct
91 Correct 352 ms 4940 KB Output is correct
92 Correct 396 ms 18412 KB Output is correct
93 Correct 356 ms 4972 KB Output is correct
94 Correct 360 ms 4940 KB Output is correct
95 Correct 352 ms 4944 KB Output is correct
96 Correct 446 ms 12608 KB Output is correct
97 Correct 389 ms 10812 KB Output is correct
98 Correct 416 ms 12076 KB Output is correct
99 Correct 509 ms 19140 KB Output is correct
100 Correct 314 ms 10956 KB Output is correct