結果
問題 | No.2697 Range LIS Query |
ユーザー | srjywrdnprkt |
提出日時 | 2024-03-22 23:16:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5,175 ms / 10,000 ms |
コード長 | 3,998 bytes |
コンパイル時間 | 2,391 ms |
コンパイル使用メモリ | 225,252 KB |
実行使用メモリ | 100,492 KB |
最終ジャッジ日時 | 2024-09-30 12:31:58 |
合計ジャッジ時間 | 47,191 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 79 ms
6,820 KB |
testcase_04 | AC | 77 ms
6,816 KB |
testcase_05 | AC | 80 ms
6,820 KB |
testcase_06 | AC | 3,901 ms
100,448 KB |
testcase_07 | AC | 3,942 ms
100,428 KB |
testcase_08 | AC | 3,903 ms
100,492 KB |
testcase_09 | AC | 1,930 ms
100,332 KB |
testcase_10 | AC | 1,932 ms
100,480 KB |
testcase_11 | AC | 1,970 ms
100,408 KB |
testcase_12 | AC | 2,672 ms
96,832 KB |
testcase_13 | AC | 2,987 ms
91,740 KB |
testcase_14 | AC | 4,131 ms
92,320 KB |
testcase_15 | AC | 5,175 ms
100,436 KB |
testcase_16 | AC | 5,129 ms
100,448 KB |
testcase_17 | AC | 5,138 ms
100,424 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()>struct LazySegTree { private: vector<S> seg; vector<F> lazy; int N = 1; void eval (int idx, int bitl, int bitr){ if (lazy[idx] != id()){ seg[idx] = mapping(lazy[idx], seg[idx]); if (bitl != bitr){ lazy[2*idx+1] = composition(lazy[idx], lazy[2*idx+1]); lazy[2*idx+2] = composition(lazy[idx], lazy[2*idx+2]); } lazy[idx] = id(); } } void _set (int l, int r, F val, int idx, int bitl, int bitr){ eval(idx, bitl, bitr); if (r < bitl || l > bitr) return; if (l <= bitl && bitr <= r){ lazy[idx] = composition(lazy[idx], val); eval(idx, bitl, bitr); } else{ int bitm = (bitl+bitr)/2; _set(l, r, val, idx*2+1, bitl, bitm); _set(l, r, val, idx*2+2, bitm+1, bitr); seg[idx] = op(seg[idx*2+1], seg[idx*2+2]); } } S _prod (int l, int r, int idx, int bitl, int bitr) { if (r < bitl || l > bitr) return e(); eval(idx, bitl, bitr); if (l <= bitl && bitr <= r) return seg[idx]; int bitm = (bitl+bitr)/2; return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr)); } public: LazySegTree (int n) : LazySegTree(vector<S>(n, e())) {} LazySegTree (const vector<S> &v){ int n = v.size(); while (N < n) N *= 2; seg.resize(N*2-1, e()); lazy.resize(N*2-1, id()); for (int i=0; i<n; i++) seg[i+N-1] = v[i]; for (int i=N-2; i>=0; i--) seg[i] = op(seg[i*2+1], seg[i*2+2]); } //a[i] -> f(a[i]) for l<=i<=r void set (int l, int r, F val){_set(l, r, val, 0, 0, N-1);} //op(a[l], ..., a[r]) S prod (int l, int r) {return _prod(l, r, 0, 0, N-1);} S all_prod() const{return seg[0];} S get (int i) {return prod(i, i);} void show() const{ for (int i=0; i<N*2-1; i++) cout << seg[i] << " "; for (int i=0; i<N*2-1; i++) cout << lazy[i] << " "; } }; using S = pair<int, vector<vector<int>>>; using F = int; F ID = -1; S op(S a, S b){ vector res(4, vector<int>(4, 0)); for (int i=0; i<4; i++){ for (int j=0; j<4; j++){ for (int k=i; k<=j; k++){ res[i][j] = max(res[i][j], a.second[i][k] + b.second[k][j]); } } } return {a.first + b.first, res}; } S e() {return {0, vector(4, vector<int>(4, 0))};} S mapping(F f, S x){ if (f == ID) return x; vector res(4, vector<int>(4, 0)); for (int i=0; i<4; i++){ for (int j=0; j<4; j++){ if (i <= f && f <= j) res[i][j] = x.first; else res[i][j] = 0; } } return {x.first, res}; } F composition(F f, F g){ if (f == ID) return g; else return f; } F id() {return ID;} int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, Q, t, l, r, x, A; cin >> N; vector<S> v(N); for (int i=0; i<N; i++){ cin >> A; A--; vector res(4, vector<int>(4, 0)); for (int j=0; j<4; j++){ for (int k=0; k<4; k++){ if (j <= A && A <= k) res[j][k] = 1; else res[j][k] = 0; } } v[i] = {1, res}; } cin >> Q; LazySegTree<S, op, e, F, mapping, composition, id> tree(v); for (int i=0; i<Q; i++){ cin >> t; if (t == 1){ cin >> l >> r; l--; r--; cout << tree.prod(l, r).second[0][3] << endl; } else{ cin >> l >> r >> x; x--; l--; r--; tree.set(l, r, x); } } return 0; }