Submission #847532

#TimeUsernameProblemLanguageResultExecution timeMemory
847532Mr_PhCrossing (JOI21_crossing)C++17
100 / 100
1388 ms17300 KiB
///Never gonna give you up. #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; typedef long long int lli; typedef unsigned long long ull; using namespace std; using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; const ll mod=(ll)1e9+7; const ll mod1=998244353; ///the defines :) #define endl '\n' #define vi vector<int> #define vll vector<ll> #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i]; #define all(arr) arr.begin(),arr.end() #define allr(arr) arr.rbegin(),arr.rend() #define sz size() //#define int long long string cross(string a,string b) { string ans; ans.resize(a.sz); for(int i=0; i<a.sz; i++) { if(a[i]==b[i]) ans[i]=a[i]; else { string o="JOI"; for(int j=0;j<o.sz;j++) { if(o[j]==a[i]||o[j]==b[i])continue; ans[i]=o[j]; } } } return ans; } int n; string a,b; set<string>st; vector<int>prfo; vector<int>prfi; vector<int>prfj; string t; struct segtree { vi vals; int siz=1; vector<char>lazy; void init(int n) { while(siz<n) siz*=2; vals.resize(2*siz); lazy.resize(2*siz); } void check(int l,int r,int x) { //cout<<l<<" "<<r<<" "<<lazy[x]<<" "<<vals[x]<<endl; if(lazy[x]!='-') { int p=0; if(lazy[x]=='O')p=prfo[r]-(l==0?0:prfo[l-1]); if(lazy[x]=='I')p=prfi[r]-(l==0?0:prfi[l-1]); if(lazy[x]=='J')p=prfj[r]-(l==0?0:prfj[l-1]); if(l!=r){ lazy[2*x+1]=lazy[x]; lazy[2*x+2]=lazy[x]; } vals[x]=p; lazy[x]='-'; } } void build(int x,int lx,int rx) { lazy[x]='-'; if(lx==rx) { if(lx>=a.sz)vals[x]=0; else vals[x]=(a[lx]==t[lx]); return; } int mid=(lx+rx+1)/2; build(2*x+1,lx,mid-1); build(2*x+2,mid,rx); vals[x]=vals[2*x+1]+vals[2*x+2]; } void build() { build(0,0,siz-1); } void updrange(int l,int r,char v,int x,int lx,int rx) { check(lx,rx,x); if(lx>r||rx<l)return; //cout<<lx<<" "<<rx<<" "<<x<<endl; if(rx<=r&&lx>=l) { int p=0; if(v=='O')p=prfo[rx]-(lx==0?0:prfo[lx-1]); if(v=='I')p=prfi[rx]-(lx==0?0:prfi[lx-1]); if(v=='J')p=prfj[rx]-(lx==0?0:prfj[lx-1]); vals[x]=p; if(lx!=rx)lazy[2*x+1]=v,lazy[2*x+2]=v,lazy[x]='-'; return; } int mid=(lx+rx+1)/2; updrange(l,r,v,2*x+1,lx,mid-1); updrange(l,r,v,2*x+2,mid,rx); vals[x]=vals[2*x+1]+vals[2*x+2]; } void updrange(int l,int r,char x) { updrange(l,r,x,0,0,siz-1); } }; void preprocess() {} void solve() { cin>>n; string s1,s2,s3; cin>>s1>>s2>>s3; st.insert(s1); st.insert(s2); st.insert(s3); while(true) { int x=st.sz; for(auto i:st) for(auto j:st){ if(i!=j) st.insert(cross(i,j)); } if(x==st.sz) break; } int q; cin>>q; cin>>t; if(st.find(t)!=st.end())cout<<"Yes"<<endl; else cout<<"No"<<endl; vector<pair<pair<int,int>,char>>arr(q); for(int i=0;i<q;i++)cin>>arr[i].first.first>>arr[i].first.second>>arr[i].second; vi ans(q); segtree sg; sg.init(n); prfi.resize(3*n); prfj.resize(3*n); prfo.resize(3*n); for(auto i:st) { a=i; int sumo=0,sumi=0,sumj=0; for(int j=0;j<a.sz;j++) { sumo+=(a[j]=='O'); sumi+=(a[j]=='I'); sumj+=(a[j]=='J'); prfo[j]=sumo; prfi[j]=sumi; prfj[j]=sumj; } // cout<<sumo<<" "<<sumi<<" "<<sumj<<endl; sg.build(); for(int j=0;j<arr.sz;j++) { sg.updrange(arr[j].first.first-1,arr[j].first.second-1,arr[j].second); // cout<<sg.vals[0]<<" "<<j<<" amsdiomas"<<endl; if(sg.vals[0]==n)ans[j]=1; } } for(auto i:ans) { if(i==1)cout<<"Yes"<<endl; else cout<<"No"<<endl; } } signed main() { // freopen("div7.in","r",stdin); //freopen("div7.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); preprocess(); //bla(); int t=1; //cin>>t; while(t--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0; i<a.sz; i++)
      |                   ^
Main.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             for(int j=0;j<o.sz;j++)
      |                          ^
Main.cpp: In member function 'void segtree::build(int, int, int)':
Main.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             if(lx>=a.sz)vals[x]=0;
      |                  ^
Main.cpp: In function 'void solve()':
Main.cpp:141:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |         if(x==st.sz)
      |             ^
Main.cpp:161:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |         for(int j=0;j<a.sz;j++)
      |                      ^
Main.cpp:172:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |         for(int j=0;j<arr.sz;j++)
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...