結果
問題 | No.2992 Range ABCD String Query |
ユーザー | tassei903 |
提出日時 | 2024-12-17 01:20:58 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 662 ms / 6,000 ms |
コード長 | 4,255 bytes |
コンパイル時間 | 4,127 ms |
コンパイル使用メモリ | 282,576 KB |
実行使用メモリ | 74,332 KB |
最終ジャッジ日時 | 2024-12-17 01:21:26 |
合計ジャッジ時間 | 25,660 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 209 ms
6,820 KB |
testcase_01 | AC | 208 ms
6,820 KB |
testcase_02 | AC | 256 ms
6,816 KB |
testcase_03 | AC | 220 ms
6,816 KB |
testcase_04 | AC | 240 ms
6,816 KB |
testcase_05 | AC | 214 ms
6,820 KB |
testcase_06 | AC | 231 ms
6,816 KB |
testcase_07 | AC | 178 ms
6,816 KB |
testcase_08 | AC | 270 ms
6,820 KB |
testcase_09 | AC | 206 ms
6,820 KB |
testcase_10 | AC | 598 ms
72,208 KB |
testcase_11 | AC | 592 ms
71,052 KB |
testcase_12 | AC | 556 ms
71,252 KB |
testcase_13 | AC | 594 ms
68,776 KB |
testcase_14 | AC | 514 ms
67,640 KB |
testcase_15 | AC | 521 ms
68,152 KB |
testcase_16 | AC | 549 ms
40,968 KB |
testcase_17 | AC | 542 ms
73,736 KB |
testcase_18 | AC | 578 ms
67,704 KB |
testcase_19 | AC | 556 ms
74,056 KB |
testcase_20 | AC | 412 ms
74,152 KB |
testcase_21 | AC | 477 ms
74,152 KB |
testcase_22 | AC | 424 ms
74,228 KB |
testcase_23 | AC | 405 ms
74,264 KB |
testcase_24 | AC | 442 ms
74,276 KB |
testcase_25 | AC | 393 ms
74,264 KB |
testcase_26 | AC | 415 ms
74,288 KB |
testcase_27 | AC | 415 ms
74,216 KB |
testcase_28 | AC | 394 ms
74,228 KB |
testcase_29 | AC | 389 ms
74,228 KB |
testcase_30 | AC | 621 ms
74,332 KB |
testcase_31 | AC | 573 ms
74,220 KB |
testcase_32 | AC | 612 ms
74,296 KB |
testcase_33 | AC | 576 ms
74,296 KB |
testcase_34 | AC | 636 ms
74,264 KB |
testcase_35 | AC | 636 ms
74,156 KB |
testcase_36 | AC | 662 ms
74,148 KB |
testcase_37 | AC | 165 ms
6,816 KB |
testcase_38 | AC | 191 ms
6,816 KB |
testcase_39 | AC | 179 ms
6,816 KB |
testcase_40 | AC | 176 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define ov4(a, b, c, d, name, ...) name #define rep3(i, a, b, c) for (int i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaaa, n) #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for(int i = (a)-1; i >= (b); i--) #define fore(e, v) for (auto&& e : v) #define lb(v, x) (lower_bound(all(v), x)- begin(v)); #define eb emplace_back using ll = long long; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = double; template<class T, class S> bool chmin(T& a, const S& b) {return a > b ? a = b, 1 : 0; } template<class T, class S> bool chmax(T& a, const S& b) {return a < b ? a = b, 1 : 0; } vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; const int INF = 1e9 + 100; const ll linf = 1e18 + 100; int clamp(int l, int r, int x) {return min(max(l, x), r);} template<class S, S (*op)(S, S), S (*e)()> struct segtree { segtree(int n) : segtree(vector<S>(n, e())) {} segtree(const vector<S>& v) : n(sz(v)) { s = bit_ceil(unsigned(n)); log = countr_zero(unsigned(s)); d = vector<S>(2 * s, e()); rep(i, n) d[s + i] = v[i]; per(i, s, 1) update(i); } void set(int p, S x) { d[p += s] = x; rep(i, 1, log + 1) update(p >> i); } S prod(int l, int r) const { S sml = e(), smr = e(); l += s, r += s; while(l < r) { if(l & 1) sml = op(sml, d[l++]); if(r & 1) smr = op(d[--r], smr); l >>= 1, r >>= 1; } return op(sml, smr); } S all_prod() const { return d[1]; } template<typename F> int max_right(int l, F f) const { if(l == n) return n; l += s; S sm = e(); do { while(~l & 1) l >>= 1; if(!f(op(sm, d[l]))) { while(l < s) { l <<= 1; if(f(op(sm, d[l]))) sm = op(sm, d[l++]); } return l - s; } sm = op(sm, d[l++]); } while((l & -l) != l); return n; } template<typename F> int min_left(int r, F f) const { if(!r) return 0; r += s; S sm = e(); do { r--; while(r > 1 and r & 1) r >>= 1; if(!f(op(d[r], sm))) { while(r < s) { r = (2 * r + 1); if(f(op(d[r], sm))) sm = op(d[r--], sm); } return r + 1 - s; } sm = op(d[r], sm); } while((r & -r) != r); return 0; } private: int n, s, log; vector<S> d; void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); } }; const int iinf = 1e9 + 100; using S = array<int, 25>; const int m = 4; int idx(int l, int r){ return l * (m + 1) + r; } void print(S x) { rep(l, m+1) { rep(r, l+1, m+1) cout << x[idx(l, r)] << " "; cout << endl; } } S e() { return S{}; } S op(S x, S y) { S z = e(); rep(l, m)rep(r, l+1, m+1)z[idx(l, r)] = iinf; rep(l, m+1)rep(r, l+1, m+1)rep(k, l, r) { chmin(z[idx(l, r)], x[idx(l, k+1)] + y[idx(k, r)]); } return z; } void solve() { int n, q;cin >> n >> q; string s;cin >> s; auto item = [&](int x) -> S { S z = e(); rep(l, m)rep(r, l+1, m+1)z[idx(l, r)] = iinf; rep(l, m)rep(r, l+1, m+1) { if (x < l) z[idx(l, r)] = 1; else if (x >= r) z[idx(l, r)] = 1; else z[idx(l, r)] = 0; } return z; }; vector<S> v(n); rep(i, n) v[i] = item(s[i] - 'A'); segtree<S, op, e> st(v); rep(q) { int t;cin >> t; if (t == 1) { int x;cin >> x;x--; char c;cin >> c; st.set(x, item(c - 'A')); } else { int l, r;cin >> l >> r; l--; // print(st.prod(l, r)); cout << st.prod(l, r)[idx(0, m)] << endl; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); // int T;cin >> T; int T = 1; while (T--) { solve(); } }