Submission #66019
ソースコード
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 63 | #include<bits/stdc++.h> #define lol long long using namespace std; struct Segment{ vector<lol> value; int N=1; Segment( int n){ while (N<n) 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]); } } lol queryMin(lol a,lol b,lol k,lol l,lol r){ if (r<=a || b<=l) return INT_MAX; if (a<=l && r<=b) return value[k]; else { lol c1=queryMin(a,b,k*2+1,l,(l+r)/2); lol c2=queryMin(a,b,k*2+2,(l+r)/2,r); return min(c1,c2); } } lol get(lol a,lol b){ return queryMin(a,b+1,0,0,N); } }; int main(){ int n; cin>>n; Segment seguki(n); int a,b,c[n]; for ( int i=0;i<n;i++){ cin>>c[i]; seguki.update(i,c[i]); } while ( true ){ string s; cin>>s; if (s== "exit" ){ break ; } else if (s== "update" ){ cin>>a>>b; seguki.update(a,b); } else if (s== "min" ){ cin>>a>>b; cout<<seguki.get(a,b)<< "\n" ; } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0459 - セグメントツリー練習 |
ユーザー名 | ei2038 |
投稿日時 | 2021-03-18 13:53:30 |
言語 | C++17 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 1334 Byte |
最大実行時間 | 53 ms |
最大メモリ使用量 | 3088 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
Input01 | AC | 26 ms | 604 KB |
1
|
Input02 | AC | 18 ms | 580 KB |
1
|
Input03 | AC | 22 ms | 556 KB |
1
|
Input04 | AC | 23 ms | 656 KB |
1
|
Input05 | AC | 18 ms | 620 KB |
1
|
Input06 | AC | 20 ms | 588 KB |
1
|
Input07 | AC | 16 ms | 556 KB |
1
|
Input08 | AC | 20 ms | 644 KB |
1
|
Input09 | AC | 31 ms | 708 KB |
1
|
Input10 | AC | 53 ms | 3088 KB |
1
|