Submission #847526

#TimeUsernameProblemLanguageResultExecution timeMemory
847526Mr_PhCrossing (JOI21_crossing)C++14
100 / 100
2456 ms42940 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; for(int i=0; i<a.sz; i++) { if(a[i]==b[i]) ans+=a[i]; else { set<char>st; st.insert('J'); st.insert('O'); st.insert('I'); st.erase(a[i]); st.erase(b[i]); ans+=*st.begin(); } } return ans; } int n; string a,b; vector<int>prfo; vector<int>prfi; vector<int>prfj; 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]==b[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; set<string>st; st.insert(s1); st.insert(s2); st.insert(s3); while(true) { int x=st.sz; for(auto i:st) for(auto j:st) st.insert(cross(i,j)); if(x==st.sz) break; } int q; cin>>q; string t; 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(5*n); prfj.resize(5*n); prfo.resize(5*n); for(auto i:st) { a=i; b=t; 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:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0; i<a.sz; i++)
      |                   ^
Main.cpp: In member function 'void segtree::build(long long int, long long int, long long int)':
Main.cpp:82:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             if(lx>=a.sz)vals[x]=0;
      |                  ^
Main.cpp: In function 'void solve()':
Main.cpp:138:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         if(x==st.sz)
      |             ^
Main.cpp:160:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |         for(int j=0;j<a.sz;j++)
      |                      ^
Main.cpp:171:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |         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...