Submission #64289


ソースコード

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll inf=(1LL<<31)-1;
struct Segment{
vector<ll> value;
int N;
Segment(int n){
N=1;
while(N<n){
N*=2;
}
value.resize(N*2);
for(ll i=0;i<N*2;i++){
value[i]=inf;
}
}
void update(int i,ll 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 query(int a,int b,int k,int l,int r){
if(r<=a||l>=b){
return inf;
}
if(a<=l&&b>=r){
return value[k];
}
else{
ll c1=query(a,b,k*2+1,l,(l+r)/2);
ll c2=query(a,b,k*2+2,(l+r)/2,r);
return min(c1,c2);
}
}
ll get(int a,int b){
return query(a,b+1,0,0,N);
}
};
signed main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin>>n;
ll a;
Segment seg(n);
for(int i=0;i<n;i++){
cin>>a;
seg.update(i,a);
}
string str;
while(str!="exit"){
cin>>str;
if(str=="update"){
int a,b;
cin>>a>>b;
seg.update(a,b);
}
if(str=="min"){
int a,b;
cin>>a>>b;
cout<<seg.get(a,b)<<'\n';
}
if(str=="exit"){
break;
}
}
return 0;
}

ステータス

項目 データ
問題 0459 - セグメントツリー練習
ユーザー名 ei2009
投稿日時 2020-10-15 17:23:48
言語 C++17
状態 Accepted
得点 10
ソースコード長 1525 Byte
最大実行時間 44 ms
最大メモリ使用量 2680 KB

セット

セット 得点 Cases
1 ALL 10 / 10 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 24 ms 600 KB
1
Input02 AC 20 ms 560 KB
1
Input03 AC 24 ms 516 KB
1
Input04 AC 21 ms 600 KB
1
Input05 AC 20 ms 548 KB
1
Input06 AC 20 ms 496 KB
1
Input07 AC 16 ms 572 KB
1
Input08 AC 24 ms 644 KB
1
Input09 AC 16 ms 692 KB
1
Input10 AC 44 ms 2680 KB
1