제출 #1149817

#제출 시각아이디문제언어결과실행 시간메모리
1149817IssaCrossing (JOI21_crossing)C++20
100 / 100
1000 ms63616 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 2e5 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e7 + 100; const ll MOD = 1e9 + 7; const int maxl = 16; const ll P = 31; int n; struct asd{ int f, ok; }; int f(char c){ if(c == 'J') return 0; if(c == 'O') return 1; return 2; } asd ff(asd a, asd b){ if(a.f != b.f) return {-1, a.ok & b.ok}; return {a.f, a.ok & b.ok}; } struct str{ asd d[maxn * 4]; int t[maxn * 4]; string s, s1; void build(int v = 1, int tl = 1, int tr = n){ t[v] = -1; if(tl == tr){ d[v] = {f(s[tl-1]), s[tl-1] == s1[tl-1]}; } else{ int mid = (tl + tr) >> 1; build(v<<1, tl, mid); build(v<<1|1, mid+1, tr); d[v] = ff(d[v<<1], d[v<<1|1]); } } void calc(string S, string T){ s = S; s1 = T; build(); // cout << s << ' ' << s1 << endl; } void pre(int v, int x){ d[v] = {d[v].f, d[v].f == x}; t[v] = x; } void push(int v, int tl, int tr){ if(tl == tr || t[v] == -1) return; pre(v<<1, t[v]); pre(v<<1|1, t[v]); t[v] = -1; } void upd(int l, int r, int x, int v = 1, int tl = 1, int tr = n){ if(tl > r || tr < l) return; if(l <= tl && tr <= r) pre(v, x); else{ push(v, tl, tr); int mid = (tl + tr) >> 1; upd(l, r, x, v<<1, tl, mid); upd(l, r, x, v<<1|1, mid+1, tr); d[v] = ff(d[v<<1], d[v<<1|1]); } } } d[9]; set<string> st; queue<string> q; string get(string a, string b){ string c; for(int i = 0; i < n; i++){ if(a[i] == b[i]) c.push_back(a[i]); else c.push_back(char('J' + 'O' + 'I' - a[i] - b[i])); } return c; } void add(string s){ if(st.count(s)) return; for(string x: st){ string nw = get(x, s); if(st.count(nw)) continue; q.push(nw); } st.insert(s); } void ans(){ for(int i = 0; i < st.size(); i++){ if(d[i].d[1].ok){ cout << "Yes\n"; return; } } cout << "No\n"; } void test(){ cin >> n; string a, b, c; cin >> a >> b >> c; q.push(a); q.push(b); q.push(c); while(q.size()){ string s = q.front(); q.pop(); add(s); } int qr; cin >> qr; string t; cin >> t; int sz = 0; for(string s: st){ d[sz++].calc(s, t); } ans(); while(qr--){ int l, r; char c; cin >> l >> r >> c; bool ok = 0; for(int i = 0; i < sz; i++){ d[i].upd(l, r, f(c)); if(d[i].d[1].ok) ok = 1; } ans(); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); int t = 1; while(t--) test(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...