Submission #1255919

#TimeUsernameProblemLanguageResultExecution timeMemory
1255919thdh__Crossing (JOI21_crossing)C++20
100 / 100
376 ms30272 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define eb emplace_back #define pu push #define ins insert #define fi first #define se second #define all(a) a.begin(),a.end() #define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fu(x,a,b) for (auto x=a;x<=b;x++) #define fd(x,a,b) for (auto x=a;x>=b;x--) #define int ll using namespace std; //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); /* Competitive Programming notes that I need to study & fix my dumbass self: 1. Coding: - Always be sure to check the memory of arrays (maybe use vectors), for loops - Always try to maximize the memory if possible, even if you are going for subtasks - Do not exploit #define int long long, it will kill you 2. Stress: - Always try generating big testcases and try if they run 3. Time management: - Don't overcommit or undercommit, always spend a certain amount of time to think a problem, don't just look at it and say I'm fucked - Do not spend too much time coding brute-force solutions, they should be easily-codable solutions that don't take up too much time Time management schedule: Offline / LAH days (4 problems - 3h): 15' thinking of solution / idea 1. no idea: skip 2. yes idea: continue thinking for <= 15' + implementing: <= 20' + brute-force: <= 5' + test generator: <= 5' I hate offline because I am dumb */ typedef pair<int, int> ii; const int N = 2e5+5; const int B = 750; const int base = 31; const int mod = 1e9+7; const int inf = 1e18; using cd = complex<double>; const long double PI = acos(-1); int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} string merge(string a, string b) { string c; for (int i = 0; i < a.size(); i++) { if (a[i] == b[i]) c += a[i]; else { if (a[i] != 'J' && b[i] != 'J') c += 'J'; else if (a[i] != 'I' && b[i] != 'I') c += 'I'; else c += 'O'; } } return c; } int h[N], p[N]; int pref[4][N]; int getid(char c) { if (c == 'J') return 1; else if (c == 'O') return 2; else return 3; } void precalc() { p[0] = 1; for (int i = 1; i < N; i++) p[i] = p[i-1] * base % mod; for (int i = 1; i <= 3; i++) { for (int j = 1; j < N; j++) pref[i][j] = (pref[i][j-1] * base % mod + i) % mod; } } int gethash(string s) { int n = s.size(); s = " " + s; for (int i = 1; i <= n; i++) h[i] = (h[i-1] * base % mod + getid(s[i])) % mod; return h[n]; } int n,q; string a,b,c,t; map<int, int> check; int st[4*N], lazy[4*N]; void build(int id, int l, int r) { if (l == r) { st[id] = getid(t[l]); return; } int mid = l+r>>1; build(id*2, l, mid); build(id*2+1, mid+1, r); st[id] = (st[id*2] * p[r-mid] % mod + st[id*2+1]) % mod; } void push(int id, int l, int r) { int mid = l+r>>1; if (!lazy[id]) return; st[id*2] = pref[lazy[id]][mid-l+1], st[id*2+1] = pref[lazy[id]][r-mid]; lazy[id*2] = lazy[id*2+1] = lazy[id]; lazy[id] = 0; } void update(int id, int l, int r, int u, int v, int val) { if (l > v || r < u) return; if (u <= l && r <= v) { st[id] = pref[val][r-l+1]; lazy[id] = val; return; } int mid = l+r>>1; push(id, l, r); update(id*2, l, mid, u, v, val); update(id*2+1, mid+1, r, u, v, val); st[id] = (st[id*2] * p[r-mid] % mod + st[id*2+1]) % mod; } void solve() { precalc(); cin>>n>>a>>b>>c; check[gethash(a)] = check[gethash(b)] = check[gethash(c)] = check[gethash(merge(a,b))] = check[gethash(merge(b,c))] = check[gethash(merge(c,a))] = check[gethash(merge(a, merge(b,c)))] = check[gethash(merge(b, merge(a,c)))] = check[gethash(merge(c, merge(a,b)))] = 1; cin>>q>>t; t = ' ' + t; build(1,1,n); if (check[st[1]]) cout<<"Yes"<<endl; else cout<<"No"<<endl; while (q--) { int l,r; char c; cin>>l>>r>>c; update(1,1,n,l,r,getid(c)); if (check[st[1]]) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } /* Go through the mistakes you usually make and revise your code, for god's sake... */ signed main() { bruh //freopen("input.inp","r",stdin); //freopen("output.inp","w",stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...