Submission #68057
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include<bits/stdc++.h> using namespace std; #define ll long long struct segtree{ int n; vector<ll> value; segtree( int size){ n=1; while (n<size){ n*=2; } value.resize(n*2); for ( int i=0;i<n*2;i++){ value[i]=0; } } void update( int i, int x){ i+=n-1; value[i]=x; while (i>0){ i=(i-1)/2; value[i]=min(value[i*2+1],value[i*2+2]); } } ll getMin( int a, int b, int k, int l, int r){ if (r<=a || b<=l) return INT_MAX; if (a<=l && r<=b) return value[k]; else { ll c1=getMin(a,b,2*k+1,l,(l+r)/2); ll c2=getMin(a,b,2*k+2,(l+r)/2,r); return min(c1,c2); } } ll get( int a, int b){ return getMin(a,b+1,0,0,n); } }; int main(){ int n; cin>>n; int a[n]; segtree st(n); for ( int i=0;i<n;i++){ cin>>a[i]; st.update(i,a[i]); } int c,d; string u; while ( true ){ cin>>u; if (u== "exit" ){ break ; } else if (u== "update" ){ cin>>c>>d; st.update(c,d); } else if (u== "min" ){ cin>>c>>d; cout<<st.get(c,d)<<endl; } } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0459 - セグメントツリー練習 |
ユーザー名 | ei2113 |
投稿日時 | 2021-08-11 15:41:17 |
言語 | C++17 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 1344 Byte |
最大実行時間 | 60 ms |
最大メモリ使用量 | 3080 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
Input01 | AC | 26 ms | 604 KB |
1
|
Input02 | AC | 26 ms | 448 KB |
1
|
Input03 | AC | 20 ms | 416 KB |
1
|
Input04 | AC | 24 ms | 516 KB |
1
|
Input05 | AC | 17 ms | 480 KB |
1
|
Input06 | AC | 25 ms | 580 KB |
1
|
Input07 | AC | 24 ms | 676 KB |
1
|
Input08 | AC | 33 ms | 508 KB |
1
|
Input09 | AC | 22 ms | 700 KB |
1
|
Input10 | AC | 60 ms | 3080 KB |
1
|