結果
問題 | No.1675 Strange Minimum Query |
ユーザー | Manuel1024 |
提出日時 | 2022-09-05 23:33:40 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 380 ms / 2,000 ms |
コード長 | 3,898 bytes |
コンパイル時間 | 992 ms |
コンパイル使用メモリ | 81,460 KB |
実行使用メモリ | 10,008 KB |
最終ジャッジ日時 | 2023-08-13 07:30:33 |
合計ジャッジ時間 | 18,640 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,512 KB |
testcase_02 | AC | 2 ms
4,384 KB |
testcase_03 | AC | 274 ms
6,732 KB |
testcase_04 | AC | 245 ms
7,220 KB |
testcase_05 | AC | 19 ms
5,204 KB |
testcase_06 | AC | 327 ms
7,208 KB |
testcase_07 | AC | 352 ms
8,584 KB |
testcase_08 | AC | 1 ms
4,384 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 136 ms
7,520 KB |
testcase_11 | AC | 35 ms
6,348 KB |
testcase_12 | AC | 150 ms
7,576 KB |
testcase_13 | AC | 269 ms
9,896 KB |
testcase_14 | AC | 324 ms
9,852 KB |
testcase_15 | AC | 290 ms
9,968 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 54 ms
4,500 KB |
testcase_18 | AC | 79 ms
4,680 KB |
testcase_19 | AC | 101 ms
6,996 KB |
testcase_20 | AC | 244 ms
8,644 KB |
testcase_21 | AC | 211 ms
8,196 KB |
testcase_22 | AC | 279 ms
8,852 KB |
testcase_23 | AC | 233 ms
6,524 KB |
testcase_24 | AC | 202 ms
6,784 KB |
testcase_25 | AC | 150 ms
5,484 KB |
testcase_26 | AC | 70 ms
5,188 KB |
testcase_27 | AC | 186 ms
7,872 KB |
testcase_28 | AC | 94 ms
6,960 KB |
testcase_29 | AC | 64 ms
6,604 KB |
testcase_30 | AC | 71 ms
5,140 KB |
testcase_31 | AC | 301 ms
8,196 KB |
testcase_32 | AC | 380 ms
9,868 KB |
testcase_33 | AC | 373 ms
9,904 KB |
testcase_34 | AC | 379 ms
10,008 KB |
testcase_35 | AC | 375 ms
9,852 KB |
testcase_36 | AC | 375 ms
9,860 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using P = pair<int, int>; const int INF = 1 << 30; template< class S, S (*op)(S, S), S(*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F(*id)()> class LazySegTree{ private: int n; int h; vector<S> data; vector<F> lazy; void all_apply(int ind, F f){ data[ind] = mapping(f, data[ind]); if(ind < n) lazy[ind] = composition(f, lazy[ind]); } void push(int ind){ all_apply(ind<<1|0, lazy[ind]); all_apply(ind<<1|1, lazy[ind]); lazy[ind] = id(); } void update(int ind){ data[ind] = op(data[ind<<1|0], data[ind<<1|1]); } public: LazySegTree(int sz){ n = 1; h = 1; while(n < sz){ n <<= 1; h++; } data = vector<S>(n*2, e()); lazy = vector<F>(n, id()); } void set(int ind, S x){ ind += n; for(int lg = h-1; lg > 0; lg--) push(ind>>lg); data[ind] = x; for(int lg = 1; lg < h; lg++) update(ind>>lg); } S get(int ind){ ind += n; for(int lg = h-1; lg > 0; lg--) push(ind>>lg); return data[ind]; } S query(int l, int r){ l += n; r += n; S lres = e(), rres = e(); for(int lg = h-1; lg > 0; lg--){ if(((l>>lg)<<lg) != l) push(l>>lg); if(((r>>lg)<<lg) != r) push((r-1)>>lg); } while(l < r){ if(l&1){ lres = op(lres, data[l]); l++; } if(r&1){ r--; rres = op(data[r], rres); } l >>= 1; r >>= 1; } return op(lres, rres); } void apply(int ind, F f){ ind += n; for(int lg = h-1; lg > 0; lg--) push(ind>>lg); data[ind] = mapping(f, data[ind]); for(int lg = 1; lg < h; lg++) update(ind>>lg); } void apply(int l, int r, F f){ l += n; r += n; for(int lg = h-1; lg > 0; lg--){ if(((l>>lg)<<lg) != l) push(l>>lg); if(((r>>lg)<<lg) != r) push((r-1)>>lg); } int l2 = l, r2 = r; while(l2 < r2){ if(l2&1){ all_apply(l2, f); l2++; } if(r2&1){ r2--; all_apply(r2, f); } l2 >>= 1; r2 >>= 1; } for(int lg = 1; lg < h; lg++){ // data[ind>>lg] = op(data[(ind>>lg)<<1|0], data[(ind>>lg)<<1|1]); if(((l>>lg)<<lg) != l) update(l>>lg); if(((r>>lg)<<lg) != r) update((r-1)>>lg); } } }; int op(int x, int y){ return min(x, y); } int e(){ return INF; } int mapping(int f, int s){ return (f == INF) ? s : f; } int composition(int f, int g){ return (f == INF) ? g : f; } int id(){ return INF; } int main(){ int n, q; cin >> n >> q; vector<int> l(q), r(q), b(q); for(int i = 0; i < q; i++){ cin >> l[i] >> r[i] >> b[i]; l[i]--; r[i]--; } vector<P> mem(q); for(int i = 0; i < q; i++){ mem[i].first = b[i]; mem[i].second = i; } sort(mem.begin(), mem.end()); LazySegTree<int, op, e, int, mapping, composition, id> st(n); st.apply(0, n, 1000000000); for(int i = 0; i < q; i++){ st.apply(l[mem[i].second], r[mem[i].second]+1, mem[i].first); } // for(int i = 0; i < n; i++) cerr << st.get(i) << " "; // cerr << endl; bool isok = true; for(int i = 0; i < q; i++){ if(st.query(l[i], r[i]+1) != b[i]) isok = false; } if(!isok){ cout << -1 << endl; }else{ for(int i = 0; i < n; i++){ if(i != 0) cout << " "; cout << st.get(i); } cout << endl; } return 0; }