voidsolve(){ int n; cin >> n; rep(a, 1, 6) { rep(b, a + 1, 6) { int c = n - a - b; if (c <= 0 || a % 3 == 0 || b % 3 == 0 || c % 3 == 0) { continue; } if (a == b || b == c || a == c) { continue; } cout << "YES\n"; cout << a << " " << b << " " << c << "\n"; return; } } cout << "NO\n"; }
voidsolve(){ string s; cin >> s; ll pos; cin >> pos; --pos; int n = sz(s); vi L(n), R(n); rep(i, n) { L[i] = i - 1; R[i] = i + 1; } vi vis(n, 0); auto del = [&](int x) { vis[x] = 1; int l = L[x]; int r = R[x]; if (0 <= l && l < n) R[l] = r; if (0 <= r && r < n) L[r] = l; }; int j = 0, c = 0; while (pos > n - 1 - c) { while (R[j] < n && s[j] <= s[R[j]]) { j = R[j]; } pos -= n - c; c += 1; del(j); if (L[j] != -1) j = L[j]; else j = R[j]; } int h = j; while (L[h] != -1) { h = L[h]; } while (pos--) { h = R[h]; } cout << s[h]; }
constint P = 998244353; intpower(int x, int y){ int r = 1; while (y) { if (y % 2 == 1) { r = 1ll * r * x % P; } x = 1ll * x * x % P; y /= 2; } return r; } intinv(int x){ returnpower(x, P - 2); } voidsolve(){ int n, q; cin >> n >> q; string s; cin >> s; int ans = 1; for (int i = 1; i < n; i++) { if (s[i] == '?') { ans = 1ll * ans * i % P; } } auto print = [&]() { if (s[0] == '?') { cout << 0 << "\n"; } else { cout << ans << "\n"; } }; print(); while (q--) { int x; char c; cin >> x >> c; x -= 1; if (x && s[x] == '?') { ans = 1ll * ans * inv(x) % P; } s[x] = c; if (x && s[x] == '?') { ans = 1ll * ans * x % P; } print(); } }