Submission #76559


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
int n;
vector<int> value;
SegmentTree (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 updata(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]);
}
return;
}
int query(int a, int b, int i, int l, int r){
if (b <= l || r <= a) {
return(INT_MAX);
}
if (a <= l && r <= b) {
return(value[i]);
} else {
int le = query(a, b, i * 2 + 1, l, (l + r) / 2);
int ri = query(a, b, i * 2 + 2, (l + r) / 2, r);
return(min(le,ri));
}
}
int getMin(int a, int b){
return(query(a,b+1,0,0,n));
}
};
int main(){
int n,i;
cin>>n;
SegmentTree st(n);
int c[n];
for(i=0;i<n;i++){
cin>>c[i];
st.updata(i,c[i]);
}
string s;
int a,b;
while(1){
cin>>s;
if(s=="exit"){
break;
}else if(s=="update"){
cin>>a>>b;
st.updata(a,b);
}else if(s=="min"){
cin>>a>>b;
cout<<st.getMin(a,b)<<endl;
}
}
return(0);
}

ステータス

項目 データ
問題 0459 - セグメントツリー練習
ユーザー名 ei2122
投稿日時 2023-10-01 22:46:03
言語 C++17
状態 Accepted
得点 10
ソースコード長 1516 Byte
最大実行時間 55 ms
最大メモリ使用量 2156 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 36 ms 604 KB
1
Input02 AC 20 ms 448 KB
1
Input03 AC 24 ms 420 KB
1
Input04 AC 23 ms 388 KB
1
Input05 AC 20 ms 492 KB
1
Input06 AC 17 ms 588 KB
1
Input07 AC 23 ms 556 KB
1
Input08 AC 20 ms 524 KB
1
Input09 AC 26 ms 608 KB
1
Input10 AC 55 ms 2156 KB
1