Submission #68060
ソースコード
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 | #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 i, int l, int r){ if (r<=a||b<=l) return INT_MAX; if (a<=l&&r<=b) return value[i]; else { ll aa=getMin(a,b,i*2+1,l,(l+r)/2); ll bb=getMin(a,b,i*2+2,(l+r)/2,r); return min(aa,bb); } } ll get( int a, int b){ return getMin(a,b+1,0,0,n); } }; int main(){ int n,a,b,c; cin>>n; string mei; Segtree st(n); for ( int i=0;i<n;i++){ cin>>a; st.update(i,a); } cin>>mei; while (mei!= "exit" ){ cin>>b>>c; if (mei== "update" ){ st.update(b,c); } else { cout<<st.get(b,c)<<endl; } cin>>mei; } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0459 - セグメントツリー練習 |
ユーザー名 | ei2109 |
投稿日時 | 2021-08-11 15:45:17 |
言語 | C++17 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 1248 Byte |
最大実行時間 | 51 ms |
最大メモリ使用量 | 2712 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
Input01 | AC | 28 ms | 604 KB |
1
|
Input02 | AC | 15 ms | 576 KB |
1
|
Input03 | AC | 19 ms | 416 KB |
1
|
Input04 | AC | 28 ms | 512 KB |
1
|
Input05 | AC | 25 ms | 476 KB |
1
|
Input06 | AC | 15 ms | 316 KB |
1
|
Input07 | AC | 18 ms | 536 KB |
1
|
Input08 | AC | 22 ms | 620 KB |
1
|
Input09 | AC | 36 ms | 816 KB |
1
|
Input10 | AC | 51 ms | 2712 KB |
1
|