結果
問題 | No.1675 Strange Minimum Query |
ユーザー | ぷら |
提出日時 | 2021-09-10 21:36:52 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 422 ms / 2,000 ms |
コード長 | 1,727 bytes |
コンパイル時間 | 3,902 ms |
コンパイル使用メモリ | 216,656 KB |
実行使用メモリ | 17,660 KB |
最終ジャッジ日時 | 2023-09-02 16:15:34 |
合計ジャッジ時間 | 14,771 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 170 ms
6,376 KB |
testcase_04 | AC | 173 ms
9,880 KB |
testcase_05 | AC | 63 ms
10,116 KB |
testcase_06 | AC | 199 ms
7,052 KB |
testcase_07 | AC | 223 ms
9,628 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | AC | 283 ms
13,272 KB |
testcase_11 | AC | 95 ms
12,016 KB |
testcase_12 | AC | 329 ms
14,612 KB |
testcase_13 | AC | 330 ms
17,544 KB |
testcase_14 | AC | 378 ms
17,516 KB |
testcase_15 | AC | 330 ms
17,660 KB |
testcase_16 | AC | 1 ms
4,380 KB |
testcase_17 | AC | 62 ms
6,412 KB |
testcase_18 | AC | 85 ms
6,956 KB |
testcase_19 | AC | 164 ms
14,724 KB |
testcase_20 | AC | 248 ms
13,576 KB |
testcase_21 | AC | 249 ms
15,668 KB |
testcase_22 | AC | 303 ms
16,712 KB |
testcase_23 | AC | 203 ms
8,304 KB |
testcase_24 | AC | 205 ms
11,544 KB |
testcase_25 | AC | 140 ms
7,464 KB |
testcase_26 | AC | 89 ms
8,908 KB |
testcase_27 | AC | 237 ms
15,884 KB |
testcase_28 | AC | 137 ms
12,764 KB |
testcase_29 | AC | 126 ms
14,032 KB |
testcase_30 | AC | 91 ms
9,060 KB |
testcase_31 | AC | 260 ms
10,044 KB |
testcase_32 | AC | 381 ms
17,656 KB |
testcase_33 | AC | 376 ms
17,604 KB |
testcase_34 | AC | 381 ms
17,616 KB |
testcase_35 | AC | 416 ms
17,544 KB |
testcase_36 | AC | 422 ms
17,492 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int inf = 1000000000; template <typename T> struct SegmentTree { int n; vector<T> dat; SegmentTree() {} SegmentTree(int N) { n = 1; while(n < N) { n *= 2; } dat.resize(2*n-1,inf); } void update(int x, T val) { x += (n-1); dat[x] = val; while(x > 0) { x = (x-1)/2; dat[x] = min(dat[2*x+1],dat[2*x+2]); } } T query(int a, int b, int k, int l, int r) { if(r <= a || b <= l) return inf; if(a <= l && r <= b) return dat[k]; T vl = query(a, b, 2*k+1, l, (l+r)/2); T vr = query(a, b, 2*k+2, (l+r)/2, r); return min(vl, vr); } T query(int a,int b) {//[a,b) return query(a,b,0,0,n); } }; int main() { int N,Q; cin >> N >> Q; vector<array<int,3>>tmp(Q); for(int i = 0; i < Q; i++) { cin >> tmp[i][1] >> tmp[i][2] >> tmp[i][0]; tmp[i][1]--; tmp[i][2]--; } sort(tmp.rbegin(),tmp.rend()); set<int>st; for(int i = 0; i < N; i++) { st.insert(i); } vector<int>ans(N,inf); SegmentTree<int>Seg(N); for(int i = 0; i < Q; i++) { while (st.lower_bound(tmp[i][1]) != st.end() && *st.lower_bound(tmp[i][1]) <= tmp[i][2]) { ans[*st.lower_bound(tmp[i][1])] = tmp[i][0]; Seg.update(*st.lower_bound(tmp[i][1]),tmp[i][0]); st.erase(st.lower_bound(tmp[i][1])); } if(Seg.query(tmp[i][1],tmp[i][2]+1) != tmp[i][0]) { cout << -1 << endl; return 0; } } for(int i = 0; i < N; i++) { cout << ans[i] << ((i+1 == N)?"\n":" "); } }