結果
問題 | No.2901 Logical Sum of Substring |
ユーザー | vjudge1 |
提出日時 | 2024-10-19 15:41:17 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,893 bytes |
コンパイル時間 | 3,079 ms |
コンパイル使用メモリ | 247,500 KB |
実行使用メモリ | 20,332 KB |
最終ジャッジ日時 | 2024-10-19 15:41:53 |
合計ジャッジ時間 | 18,313 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
ソースコード
#include <bits/stdc++.h> #define _1 (__int128)1 using namespace std; using ll = long long; void FileIO (const string s) { freopen(string(s + ".in").c_str(), "r", stdin); freopen(string(s + ".out").c_str(), "w", stdout); } const int N = 2e5 + 10, K = 20, INF = 1e9; struct SegTree { int pre[K], suf[K], p[K], s[K], pc, sc, ans, len; } tr[N * 4], ans; int n, k, a[N], q, op, x, y; SegTree Merge (SegTree x, SegTree y) { if (!x.len) return y; if (!y.len) return x; SegTree ret; ret.pc = ret.sc = 0, ret.ans = min(x.ans, y.ans), ret.len = x.len + y.len; for (int i = 1; i <= x.pc; i++) ret.pre[++ret.pc] = x.pre[i], ret.p[ret.pc] = x.p[i]; for (int i = 1; i <= y.pc; i++) if (y.pre[i] | ret.pre[ret.pc] != ret.pre[ret.pc]) ret.pre[ret.pc + 1] = (y.pre[i] | ret.pre[ret.pc]), ret.p[ret.pc + 1] = y.p[i] + x.len, ret.pc++; for (int i = 1; i <= y.sc; i++) ret.suf[++ret.sc] = y.suf[i], ret.s[ret.sc] = y.s[i]; for (int i = 1; i <= x.sc; i++) if (x.suf[i] | ret.suf[ret.sc] != ret.suf[ret.sc]) ret.suf[ret.sc + 1] = (x.suf[i] | ret.suf[ret.sc]), ret.s[ret.sc + 1] = x.s[i] + y.len, ret.sc++; for (int i = 1; i <= x.sc; i++) for (int j = 1; j <= y.pc; j++) if ((x.suf[i] | y.pre[i]) == (1 << k) - 1) ret.ans = min(ret.ans, (x.s[i] + y.p[i])); return ret; } void pushup (int id) { tr[id] = Merge(tr[id * 2], tr[id * 2 + 1]); } void build (int id, int l, int r) { if (l == r) { tr[id].len = 1; tr[id].pc = tr[id].sc = 0, tr[id].ans = INF; tr[id].pre[++tr[id].pc] = a[l], tr[id].p[tr[id].pc] = 1; tr[id].suf[++tr[id].sc] = a[l], tr[id].s[tr[id].sc] = 1; if (a[l] == (1 << k) - 1) tr[id].ans = 1; return ; } int mid = (l + r) >> 1; build(id * 2, l, mid), build(id * 2 + 1, mid + 1, r); pushup(id); } void modify (int id, int l, int r, int x, int y) { if (l == r) { tr[id].pc = tr[id].sc = 0, tr[id].ans = INF; tr[id].pre[++tr[id].pc] = y, tr[id].p[tr[id].pc] = 1; tr[id].suf[++tr[id].sc] = y, tr[id].s[tr[id].sc] = 1; if (y == (1 << k) - 1) tr[id].ans = 1; return ; } int mid = (l + r) >> 1; if (mid >= x) modify(id * 2, l, mid, x, y); else modify(id * 2 + 1, mid + 1, r, x, y); pushup(id); } void Query (int id, int l, int r, int x, int y) { if (l >= x && r <= y) { ans = Merge(ans, tr[id]); return ; } if (l > y || r < x) return ; int mid = (l + r) >> 1; Query(id * 2, l, mid, x, y), Query(id * 2 + 1, mid + 1, r, x, y); } signed main () { ios::sync_with_stdio(0), cin.tie(0); // FileIO(""); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; build(1, 1, n); for (cin >> q; q--; ) { cin >> op >> x >> y; if (op == 1) modify(1, 1, n, x, y); else { ans.len = 0; Query(1, 1, n, x, y); cout << (ans.ans == INF ? -1 : ans.ans) << '\n'; } } return 0; } /* 3 2 1 2 3 3 2 1 3 1 2 1 2 1 2 */