結果
問題 | No.1675 Strange Minimum Query |
ユーザー | monnu |
提出日時 | 2021-09-16 20:45:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 1,380 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 169,068 KB |
実行使用メモリ | 9,496 KB |
最終ジャッジ日時 | 2023-09-12 04:13:10 |
合計ジャッジ時間 | 16,324 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 192 ms
5,360 KB |
testcase_04 | AC | 171 ms
6,700 KB |
testcase_05 | AC | 16 ms
5,264 KB |
testcase_06 | AC | 226 ms
6,004 KB |
testcase_07 | AC | 243 ms
7,640 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,376 KB |
testcase_10 | AC | 113 ms
8,108 KB |
testcase_11 | AC | 22 ms
7,208 KB |
testcase_12 | AC | 124 ms
8,168 KB |
testcase_13 | AC | 223 ms
9,340 KB |
testcase_14 | AC | 282 ms
9,496 KB |
testcase_15 | AC | 242 ms
9,320 KB |
testcase_16 | AC | 1 ms
4,380 KB |
testcase_17 | AC | 45 ms
4,380 KB |
testcase_18 | AC | 67 ms
4,624 KB |
testcase_19 | AC | 85 ms
7,696 KB |
testcase_20 | AC | 216 ms
8,568 KB |
testcase_21 | AC | 187 ms
8,564 KB |
testcase_22 | AC | 252 ms
8,896 KB |
testcase_23 | AC | 203 ms
5,728 KB |
testcase_24 | AC | 178 ms
6,488 KB |
testcase_25 | AC | 132 ms
5,272 KB |
testcase_26 | AC | 59 ms
5,424 KB |
testcase_27 | AC | 162 ms
7,996 KB |
testcase_28 | AC | 80 ms
7,520 KB |
testcase_29 | AC | 49 ms
7,216 KB |
testcase_30 | AC | 57 ms
5,484 KB |
testcase_31 | AC | 269 ms
7,364 KB |
testcase_32 | AC | 348 ms
9,364 KB |
testcase_33 | AC | 343 ms
9,432 KB |
testcase_34 | AC | 346 ms
9,360 KB |
testcase_35 | AC | 328 ms
9,424 KB |
testcase_36 | AC | 325 ms
9,396 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using Graph=vector<vector<int>>; #define INF 1000000000 int n=1; vector<int> tree1; void update(int a,int b,int x,int i,int left,int right){ if(a<=left&&right<=b){ tree1[i]=max(tree1[i],x); return; } if(right<=a||b<=left){ return; } update(a,b,x,2*i+1,left,(left+right)/2); update(a,b,x,2*i+2,(left+right)/2,right); } vector<int> tree2; int solve(int a,int b,int i,int left,int right){ if(a<=left&&right<=b){ return tree2[i]; } if(right<=a||b<=left){ return INF; } int x=solve(a,b,2*i+1,left,(left+right)/2); int y=solve(a,b,2*i+2,(left+right)/2,right); return min(x,y); } int main(){ int N,Q; cin>>N>>Q; while(n<N){ n<<=1; } vector<int> l(Q),r(Q),B(Q); for(int i=0;i<Q;i++){ cin>>l[i]>>r[i]>>B[i]; l[i]--; } tree1.assign(2*n-1,1); tree2.assign(2*n-1,INF); for(int i=0;i<Q;i++){ update(l[i],r[i],B[i],0,0,n); } for(int i=1;i<2*n-1;i++){ tree1[i]=max(tree1[i],tree1[(i-1)/2]); } for(int i=0;i<N;i++){ tree2[n-1+i]=tree1[n-1+i]; } for(int i=n-2;i>=0;i--){ tree2[i]=min(tree2[2*i+1],tree2[2*i+2]); } for(int i=0;i<Q;i++){ if(B[i]!=solve(l[i],r[i],0,0,n)){ cout<<-1<<'\n'; return 0; } } for(int i=0;i<N-1;i++){ cout<<tree1[n-1+i]<<' '; } cout<<tree1[n-1+N-1]<<'\n'; }