Submission #66119


ソースコード

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
79
80
81
#include<bits/stdc++.h>
using namespace std;
#define lol long long
#define inf INT_MAX
#define mk(f,s) make_pair(f,s)
#define P pair<int,int>
#define fi first
#define se second
#define Deg2Rad (M_PI*2)/360
#define Rad2Deg 360/(M_PI*2)
//セグ木
struct segment{
int N; //葉の数
vector<int> nodes; //ノード
segment(int n){
N = 1;
while(N<n){
N*=2;
}
nodes.resize(N*2);
for(int i=0;i<N*2;i++){
nodes[i] = inf;
}
}
void updata(int i,int x){
i+=N-1;
nodes[i] = x;
while(i>0){
i = (i-1)/2;
nodes[i] = min(nodes[i*2+1],nodes[i*2+2]);
}
}
int quety(int a,int b,int k,int l,int r){
if(r<=a || b <= l){
return(inf);
}
if(a <= l && r <= b){
return(nodes[k]);
}
int c1 = quety(a,b,2*k+1,l,(r+l)/2);
int c2 = quety(a,b,2*k+2,(r+l)/2,r);
return(min(c1,c2));
}
int get(int a,int b){
return(quety(a,b+1,0,0,N));
}
};
int main(){
int n;
cin>>n;
segment seg(n);
for(int i=0;i<n;i++){
int c;
cin>>c;
seg.updata(i,c);
}
string str;
cin>>str;
int a,b;
while(str != "exit"){
cin>>a>>b;
if(str == "update"){
seg.updata(a,b);
}
if(str == "min"){
cout<<seg.get(a,b)<<"\n";
}
cin>>str;
}
return(0);
}

ステータス

項目 データ
問題 0459 - セグメントツリー練習
ユーザー名 ei2007
投稿日時 2021-04-12 16:38:28
言語 C++17
状態 Accepted
得点 10
ソースコード長 1570 Byte
最大実行時間 101 ms
最大メモリ使用量 2188 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 38 ms 604 KB
1
Input02 AC 24 ms 704 KB
1
Input03 AC 21 ms 672 KB
1
Input04 AC 24 ms 648 KB
1
Input05 AC 21 ms 624 KB
1
Input06 AC 29 ms 464 KB
1
Input07 AC 19 ms 564 KB
1
Input08 AC 28 ms 664 KB
1
Input09 AC 67 ms 748 KB
1
Input10 AC 101 ms 2188 KB
1