Submission #420228

#TimeUsernameProblemLanguageResultExecution timeMemory
420228parsabahramiCrossing (JOI21_crossing)C++17
100 / 100
895 ms10588 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second #define lc id << 1 #define rc lc | 1 const int N = 2e5 + 10, MOD = 1e9 + 7; int seg[N << 2], lz[N << 2], pw[N], ps[N], base = 31, n, q; char S[N], T[N]; string C[3]; set<string> st; string sum(string a, string b) { string ret = a; for (int i = 0; i < SZ(a); i++) if (a[i] == b[i]) ret[i] = a[i]; else ret[i] = 'J' ^ 'O' ^ 'I' ^ a[i] ^ b[i]; return ret; } void bld(int id = 1, int l = 1, int r = n + 1) { if (r - l < 2) { seg[id] = T[l] - 'A' + 1; //printf("%d %d %d\n", l, r, seg[id]); return; } int md = (l + r) >> 1; bld(lc, l, md); bld(rc, md, r); seg[id] = (seg[lc] * 1ll * pw[r - md] % MOD + seg[rc]) % MOD; //printf("%d %d %d\n", l, r, seg[id]); } void shift(int id, int l, int r) { if (!lz[id]) return; seg[id] = 1ll * lz[id] * (ps[r - l - 1] % MOD) % MOD; if (r - l > 1) lz[lc] = lz[id], lz[rc] = lz[id]; lz[id] = 0; } void upd(int ql, int qr, char c, int id = 1, int l = 1, int r = n + 1) { shift(id, l, r); if (qr <= l || r <= ql) return; if (ql <= l && r <= qr) { lz[id] = c - 'A' + 1; return shift(id, l, r); } int md = (l + r) >> 1; upd(ql, qr, c, lc, l, md); upd(ql, qr, c, rc, md, r); seg[id] = (seg[lc] * 1ll * pw[r - md] % MOD + seg[rc]) % MOD; } int main() { pw[0] = ps[0] = 1; for (int i = 1; i < N; i++) { pw[i] = 1ll * pw[i - 1] * base % MOD; ps[i] = (ps[i - 1] + pw[i]) % MOD; } scanf("%d", &n); for (int i : {0, 1, 2}) scanf("%s", S + 1), C[i] = S + 1; st.insert(C[0]), st.insert(C[2]), st.insert(C[1]); for (int i = 1; i <= 100; i++) { int prev = SZ(st); for (string s1 : st) for (string s2 : st) st.insert(sum(s1, s2)); if (SZ(st) == prev) break; } set<int> mp; for (string s : st) { int h = 0; for (char c : s) { h = (1ll * h * base % MOD + (c - 'A' + 1)) % MOD; } mp.insert(h); } scanf("%d%s", &q, T + 1); bld(); printf(mp.find(seg[1]) != mp.end() ? "Yes\n" : "No\n"); for (int i = 1; i <= q; i++) { int l, r; char c; cin >> l >> r >> c; upd(l, r + 1, c); printf(mp.find(seg[1]) != mp.end() ? "Yes\n" : "No\n"); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%s", S + 1), C[i] = S + 1;
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |     scanf("%d%s", &q, T + 1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...