Submission #704962

# Submission time Handle Problem Language Result Execution time Memory
704962 2023-03-03T07:20:22 Z MtSaka Crossing (JOI21_crossing) C++17
100 / 100
4097 ms 103832 KB
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rrep(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;i--)
using ll=long long;
using namespace std;
using ull=unsigned long long;
int get_id(char c){
  if(c=='J')return 0;
  if(c=='O')return 1;
  return 2;
}
char from_id(int a){
  if(a==0)return 'J';
  if(a==1)return 'O';
  return 'I';
}
vector<string>v;
vector sum(3,vector(9,vector<ll>()));
struct segment_tree{
  private:
  int n,id,sz,lg;
  vector<ll>seg;
  vector<int>lazy;
  void eval(int k,int l,int r){
    if(lazy[k]!=-1){
      seg[k]=sum[lazy[k]][id][min(n,r)]-sum[lazy[k]][id][l];
      if(r-l>1)lazy[k<<1]=lazy[k],lazy[k<<1|1]=lazy[k];
    }
    lazy[k]=-1;
  }
  void update(int i){
    seg[i]=seg[i<<1]+seg[i<<1|1];
  }
  public:
  segment_tree()=default;
  segment_tree(string s,int id):n(s.size()),id(id){
    sz=1,lg=0;
    while(sz<n)sz<<=1,lg++;
    seg.resize(sz<<1);
    rep(i,0,n){
      seg[i+sz]=(s[i]!=v[id][i]);
    }
    rrep(i,1,sz)update(i);
    lazy.assign(sz<<1,-1);
  }
  void apply(int l,int r,int a,int id=1,int l1=0,int r1=-1){
    if(r1<0)r1=sz;
    eval(id,l1,r1);
    if(r<=l1||r1<=l)return;
    if(l<=l1&&r1<=r){
      lazy[id]=a;
      eval(id,l1,r1);
    }
    else{
      apply(l,r,a,id<<1,l1,(l1+r1)>>1);
      apply(l,r,a,id<<1|1,(l1+r1)>>1,r1);
      update(id);
    }
  }
  int all_prod()const{return seg[1];}
};
string f(string a,string b){
  assert(a.size()==b.size());
  string ans(a.size(),'1');
  rep(i,0,a.size()){
    if(get_id(a[i])==get_id(b[i]))ans[i]=a[i];
    else ans[i]=from_id(3^get_id(a[i])^get_id(b[i]));
  }
  return ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  string a,b,c;cin>>a>>b>>c;
  v.emplace_back(a);
  v.emplace_back(b);
  v.emplace_back(c);
  //cerr<<a<<" "<<b<<" "<<c<<endl;
  string ab=f(a,b),bc=f(b,c),ac=f(a,c),abbc=f(ab,bc),abac=f(ab,ac),bcac=f(bc,ac);
  v.emplace_back(ab);
  v.emplace_back(bc);
  v.emplace_back(ac);
  v.emplace_back(abbc);
  v.emplace_back(abac);
  v.emplace_back(bcac);
  rep(i,0,9){
    rep(j,0,3)sum[j][i].resize(n+1);
    rep(j,0,n){
      rep(k,0,3)if(get_id(v[i][j])!=k)sum[k][i][j+1]=1;
    }
    rep(j,0,n){
      sum[0][i][j+1]+=sum[0][i][j];
      sum[1][i][j+1]+=sum[1][i][j];
      sum[2][i][j+1]+=sum[2][i][j];
    }
  }
  int q;cin>>q;
  string t;cin>>t;
  vector<segment_tree>seg(9);
  auto calc=[&]()->bool {
    rep(i,0,9)if(seg[i].all_prod()==0)return true;
    return false;
  };
  rep(i,0,9)seg[i]=segment_tree(t,i);
  if(calc()){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  rep(i,0,q){
    int l,r;char c;
    cin>>l>>r>>c;
    l--;
    rep(j,0,9)seg[j].apply(l,r,get_id(c));
    //cerr<<seg.all_prod()<<endl;
    if(calc()){
      cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 558 ms 896 KB Output is correct
2 Correct 581 ms 872 KB Output is correct
3 Correct 658 ms 908 KB Output is correct
4 Correct 653 ms 852 KB Output is correct
5 Correct 537 ms 852 KB Output is correct
6 Correct 507 ms 896 KB Output is correct
7 Correct 516 ms 836 KB Output is correct
8 Correct 563 ms 1040 KB Output is correct
9 Correct 528 ms 940 KB Output is correct
10 Correct 553 ms 912 KB Output is correct
11 Correct 538 ms 888 KB Output is correct
12 Correct 524 ms 1040 KB Output is correct
13 Correct 535 ms 904 KB Output is correct
14 Correct 534 ms 920 KB Output is correct
15 Correct 570 ms 848 KB Output is correct
16 Correct 544 ms 848 KB Output is correct
17 Correct 550 ms 960 KB Output is correct
18 Correct 662 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 896 KB Output is correct
2 Correct 581 ms 872 KB Output is correct
3 Correct 658 ms 908 KB Output is correct
4 Correct 653 ms 852 KB Output is correct
5 Correct 537 ms 852 KB Output is correct
6 Correct 507 ms 896 KB Output is correct
7 Correct 516 ms 836 KB Output is correct
8 Correct 563 ms 1040 KB Output is correct
9 Correct 528 ms 940 KB Output is correct
10 Correct 553 ms 912 KB Output is correct
11 Correct 538 ms 888 KB Output is correct
12 Correct 524 ms 1040 KB Output is correct
13 Correct 535 ms 904 KB Output is correct
14 Correct 534 ms 920 KB Output is correct
15 Correct 570 ms 848 KB Output is correct
16 Correct 544 ms 848 KB Output is correct
17 Correct 550 ms 960 KB Output is correct
18 Correct 662 ms 944 KB Output is correct
19 Correct 4097 ms 102752 KB Output is correct
20 Correct 3273 ms 102816 KB Output is correct
21 Correct 1826 ms 100084 KB Output is correct
22 Correct 1809 ms 95592 KB Output is correct
23 Correct 864 ms 6836 KB Output is correct
24 Correct 1051 ms 6792 KB Output is correct
25 Correct 1858 ms 102796 KB Output is correct
26 Correct 2020 ms 102788 KB Output is correct
27 Correct 3079 ms 102744 KB Output is correct
28 Correct 2833 ms 102772 KB Output is correct
29 Correct 2767 ms 101504 KB Output is correct
30 Correct 1283 ms 6920 KB Output is correct
31 Correct 2707 ms 102892 KB Output is correct
32 Correct 2571 ms 98980 KB Output is correct
33 Correct 974 ms 6816 KB Output is correct
34 Correct 3138 ms 102908 KB Output is correct
35 Correct 1916 ms 90988 KB Output is correct
36 Correct 1071 ms 6944 KB Output is correct
37 Correct 1127 ms 6848 KB Output is correct
38 Correct 3339 ms 102912 KB Output is correct
39 Correct 989 ms 102912 KB Output is correct
40 Correct 2019 ms 59212 KB Output is correct
41 Correct 3896 ms 102912 KB Output is correct
42 Correct 800 ms 102976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 896 KB Output is correct
2 Correct 581 ms 872 KB Output is correct
3 Correct 658 ms 908 KB Output is correct
4 Correct 653 ms 852 KB Output is correct
5 Correct 537 ms 852 KB Output is correct
6 Correct 507 ms 896 KB Output is correct
7 Correct 516 ms 836 KB Output is correct
8 Correct 563 ms 1040 KB Output is correct
9 Correct 528 ms 940 KB Output is correct
10 Correct 553 ms 912 KB Output is correct
11 Correct 538 ms 888 KB Output is correct
12 Correct 524 ms 1040 KB Output is correct
13 Correct 535 ms 904 KB Output is correct
14 Correct 534 ms 920 KB Output is correct
15 Correct 570 ms 848 KB Output is correct
16 Correct 544 ms 848 KB Output is correct
17 Correct 550 ms 960 KB Output is correct
18 Correct 662 ms 944 KB Output is correct
19 Correct 599 ms 896 KB Output is correct
20 Correct 715 ms 928 KB Output is correct
21 Correct 669 ms 936 KB Output is correct
22 Correct 504 ms 884 KB Output is correct
23 Correct 598 ms 936 KB Output is correct
24 Correct 574 ms 848 KB Output is correct
25 Correct 556 ms 944 KB Output is correct
26 Correct 615 ms 888 KB Output is correct
27 Correct 598 ms 944 KB Output is correct
28 Correct 507 ms 860 KB Output is correct
29 Correct 571 ms 1040 KB Output is correct
30 Correct 542 ms 892 KB Output is correct
31 Correct 618 ms 908 KB Output is correct
32 Correct 606 ms 904 KB Output is correct
33 Correct 549 ms 904 KB Output is correct
34 Correct 513 ms 900 KB Output is correct
35 Correct 544 ms 956 KB Output is correct
36 Correct 558 ms 1048 KB Output is correct
37 Correct 575 ms 960 KB Output is correct
38 Correct 584 ms 868 KB Output is correct
39 Correct 585 ms 912 KB Output is correct
40 Correct 572 ms 864 KB Output is correct
41 Correct 569 ms 860 KB Output is correct
42 Correct 556 ms 856 KB Output is correct
43 Correct 560 ms 896 KB Output is correct
44 Correct 545 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 558 ms 896 KB Output is correct
2 Correct 581 ms 872 KB Output is correct
3 Correct 658 ms 908 KB Output is correct
4 Correct 653 ms 852 KB Output is correct
5 Correct 537 ms 852 KB Output is correct
6 Correct 507 ms 896 KB Output is correct
7 Correct 516 ms 836 KB Output is correct
8 Correct 563 ms 1040 KB Output is correct
9 Correct 528 ms 940 KB Output is correct
10 Correct 553 ms 912 KB Output is correct
11 Correct 538 ms 888 KB Output is correct
12 Correct 524 ms 1040 KB Output is correct
13 Correct 535 ms 904 KB Output is correct
14 Correct 534 ms 920 KB Output is correct
15 Correct 570 ms 848 KB Output is correct
16 Correct 544 ms 848 KB Output is correct
17 Correct 550 ms 960 KB Output is correct
18 Correct 662 ms 944 KB Output is correct
19 Correct 4097 ms 102752 KB Output is correct
20 Correct 3273 ms 102816 KB Output is correct
21 Correct 1826 ms 100084 KB Output is correct
22 Correct 1809 ms 95592 KB Output is correct
23 Correct 864 ms 6836 KB Output is correct
24 Correct 1051 ms 6792 KB Output is correct
25 Correct 1858 ms 102796 KB Output is correct
26 Correct 2020 ms 102788 KB Output is correct
27 Correct 3079 ms 102744 KB Output is correct
28 Correct 2833 ms 102772 KB Output is correct
29 Correct 2767 ms 101504 KB Output is correct
30 Correct 1283 ms 6920 KB Output is correct
31 Correct 2707 ms 102892 KB Output is correct
32 Correct 2571 ms 98980 KB Output is correct
33 Correct 974 ms 6816 KB Output is correct
34 Correct 3138 ms 102908 KB Output is correct
35 Correct 1916 ms 90988 KB Output is correct
36 Correct 1071 ms 6944 KB Output is correct
37 Correct 1127 ms 6848 KB Output is correct
38 Correct 3339 ms 102912 KB Output is correct
39 Correct 989 ms 102912 KB Output is correct
40 Correct 2019 ms 59212 KB Output is correct
41 Correct 3896 ms 102912 KB Output is correct
42 Correct 800 ms 102976 KB Output is correct
43 Correct 599 ms 896 KB Output is correct
44 Correct 715 ms 928 KB Output is correct
45 Correct 669 ms 936 KB Output is correct
46 Correct 504 ms 884 KB Output is correct
47 Correct 598 ms 936 KB Output is correct
48 Correct 574 ms 848 KB Output is correct
49 Correct 556 ms 944 KB Output is correct
50 Correct 615 ms 888 KB Output is correct
51 Correct 598 ms 944 KB Output is correct
52 Correct 507 ms 860 KB Output is correct
53 Correct 571 ms 1040 KB Output is correct
54 Correct 542 ms 892 KB Output is correct
55 Correct 618 ms 908 KB Output is correct
56 Correct 606 ms 904 KB Output is correct
57 Correct 549 ms 904 KB Output is correct
58 Correct 513 ms 900 KB Output is correct
59 Correct 544 ms 956 KB Output is correct
60 Correct 558 ms 1048 KB Output is correct
61 Correct 575 ms 960 KB Output is correct
62 Correct 584 ms 868 KB Output is correct
63 Correct 585 ms 912 KB Output is correct
64 Correct 572 ms 864 KB Output is correct
65 Correct 569 ms 860 KB Output is correct
66 Correct 556 ms 856 KB Output is correct
67 Correct 560 ms 896 KB Output is correct
68 Correct 545 ms 868 KB Output is correct
69 Correct 3546 ms 95100 KB Output is correct
70 Correct 3432 ms 102912 KB Output is correct
71 Correct 1252 ms 7484 KB Output is correct
72 Correct 1008 ms 7472 KB Output is correct
73 Correct 1194 ms 7480 KB Output is correct
74 Correct 2183 ms 95560 KB Output is correct
75 Correct 1008 ms 7248 KB Output is correct
76 Correct 2313 ms 103320 KB Output is correct
77 Correct 2203 ms 96020 KB Output is correct
78 Correct 1123 ms 7528 KB Output is correct
79 Correct 1128 ms 7800 KB Output is correct
80 Correct 2028 ms 90188 KB Output is correct
81 Correct 1113 ms 7412 KB Output is correct
82 Correct 2434 ms 103776 KB Output is correct
83 Correct 2384 ms 101024 KB Output is correct
84 Correct 894 ms 7768 KB Output is correct
85 Correct 849 ms 7692 KB Output is correct
86 Correct 2551 ms 92652 KB Output is correct
87 Correct 2428 ms 103832 KB Output is correct
88 Correct 931 ms 7740 KB Output is correct
89 Correct 2119 ms 98072 KB Output is correct
90 Correct 2261 ms 103260 KB Output is correct
91 Correct 884 ms 6900 KB Output is correct
92 Correct 1723 ms 91300 KB Output is correct
93 Correct 855 ms 7012 KB Output is correct
94 Correct 946 ms 6920 KB Output is correct
95 Correct 828 ms 6956 KB Output is correct
96 Correct 2794 ms 103096 KB Output is correct
97 Correct 856 ms 102988 KB Output is correct
98 Correct 1774 ms 59568 KB Output is correct
99 Correct 3455 ms 103096 KB Output is correct
100 Correct 717 ms 102984 KB Output is correct