結果
問題 | No.1675 Strange Minimum Query |
ユーザー | chocorusk |
提出日時 | 2021-09-10 21:53:37 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 307 ms / 2,000 ms |
コード長 | 2,623 bytes |
コンパイル時間 | 3,959 ms |
コンパイル使用メモリ | 198,064 KB |
実行使用メモリ | 16,580 KB |
最終ジャッジ日時 | 2023-09-02 17:03:18 |
合計ジャッジ時間 | 14,211 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 168 ms
7,360 KB |
testcase_04 | AC | 159 ms
9,776 KB |
testcase_05 | AC | 47 ms
9,128 KB |
testcase_06 | AC | 198 ms
7,716 KB |
testcase_07 | AC | 216 ms
9,400 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 3 ms
4,384 KB |
testcase_10 | AC | 179 ms
14,724 KB |
testcase_11 | AC | 66 ms
12,596 KB |
testcase_12 | AC | 207 ms
15,616 KB |
testcase_13 | AC | 257 ms
16,392 KB |
testcase_14 | AC | 290 ms
16,416 KB |
testcase_15 | AC | 262 ms
16,240 KB |
testcase_16 | AC | 2 ms
4,384 KB |
testcase_17 | AC | 47 ms
6,400 KB |
testcase_18 | AC | 63 ms
6,840 KB |
testcase_19 | AC | 117 ms
12,852 KB |
testcase_20 | AC | 187 ms
12,328 KB |
testcase_21 | AC | 183 ms
14,444 KB |
testcase_22 | AC | 228 ms
15,236 KB |
testcase_23 | AC | 164 ms
8,772 KB |
testcase_24 | AC | 158 ms
10,828 KB |
testcase_25 | AC | 108 ms
7,492 KB |
testcase_26 | AC | 66 ms
7,816 KB |
testcase_27 | AC | 170 ms
14,464 KB |
testcase_28 | AC | 95 ms
10,696 KB |
testcase_29 | AC | 87 ms
12,036 KB |
testcase_30 | AC | 62 ms
8,212 KB |
testcase_31 | AC | 204 ms
9,880 KB |
testcase_32 | AC | 291 ms
16,308 KB |
testcase_33 | AC | 285 ms
16,580 KB |
testcase_34 | AC | 285 ms
16,256 KB |
testcase_35 | AC | 302 ms
16,556 KB |
testcase_36 | AC | 307 ms
16,444 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; template<typename Monoid> struct SegmentTree{ using F=function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid e; SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){ sz=1; while(sz<n) sz<<=1; seg.resize(2*sz, e); } SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){ sz=1; while(sz<n) sz<<=1; seg.resize(2*sz, e); for(int i=0; i<n; i++) seg[i+sz]=v[i]; for(int i=sz-1; i>=1; i--){ seg[i]=f(seg[2*i], seg[2*i+1]); } } void update(int k, const Monoid &x){ k+=sz; seg[k]=x; while(k>1){ k>>=1; seg[k]=f(seg[2*k], seg[2*k+1]); } } Monoid query(int a, int b){ a+=sz, b+=sz; Monoid ret=e; for(;a<b; a>>=1, b>>=1){ if(b&1) ret=f(ret, seg[--b]); if(a&1) ret=f(ret, seg[a++]); } return ret; } /*Monoid query(int a, int b){ //演算が非可換のとき a+=sz, b+=sz; Monoid retl=e, retr=e; for(;a<b; a>>=1, b>>=1){ if(b&1) retr=f(seg[--b], retr); if(a&1) retl=f(retl, seg[a++]); } return f(retl, retr); }*/ Monoid operator[](const int &k) const{ return seg[k+sz]; } }; int n, q; set<int> st; int l[200020], r[200020], b[200020]; int main() { cin>>n>>q; for(int i=0; i<n; i++){ st.insert(i); } vector<int> ind(q); for(int i=0; i<q; i++){ cin>>l[i]>>r[i]>>b[i]; l[i]--; ind[i]=i; } sort(ind.begin(), ind.end(), [&](int i, int j){ return b[i]>b[j];}); vector<int> ans(n, 1); for(auto i:ind){ auto itr=st.lower_bound(l[i]); while(itr!=st.end() && *itr<r[i]){ ans[*itr]=b[i]; itr=st.erase(itr); } } const int INF=1e9+7; SegmentTree<int> seg(n, [&](int i, int j){ return min(i, j);}, INF, ans); bool dame=0; for(auto i:ind){ if(seg.query(l[i], r[i])!=b[i]){ cout<<-1<<endl; return 0; } } for(int i=0; i<n; i++){ cout<<ans[i]; if(i<n-1) cout<<" "; } cout<<endl; return 0; }