Submission #77682


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
class segtree{
long long sz;
long long start = INT_MAX;//!!
vector<long long>seg;
public: segtree(long long n){//make tree
sz = 1;
while(sz < n)sz <<= 1;
seg.assign((sz*2)-1,start);
}
public: virtual long long f(long long x,long long y){return min(x,y);}
public: void update(long long a,long long b){//one point update
a += sz-1;
seg[a] = b;
while(a > 0){
a =(a-1)>>1;
seg[a] = f(seg[(2*a)+1],seg[(2*a)+2]);//!!
}
}
public: long long rmq(long long a,long long b,long long k,long long l,long long r){
//kukantansaku
if(a >= r||l >= b)return start;
if(a <= l&&b >= r)return seg[k];
return f(rmq(a,b,(k*2)+1,l,(l+r)>>1),rmq(a,b,(k*2)+2,(l+r)>>1,r));//!!
}
public: long long rmq(long long a,long long b){
//short cut
return rmq(a,b,0,0,sz);
}
};
int main(){
#define int long long
int n;
cin >>n;
segtree tree(n);//セグ木の作成
for(int i = 0;i < n;i++){
int x;
cin >>x;
tree.update(i,x);//値の更新(i番目をxに設定)
}
queue<int>ans;
while(1){
string s;
int x,y;
cin >>s;
if(s == "min"){//min値の出力
cin >>x>>y;
ans.push(tree.rmq(x,y+1));//min値の出力はxは含む、yは含まず。
}else if(s == "update"){//値の更新
cin >>x>>y;
tree.update(x,y);
}else{
break;
}
}
queue<int>debug = ans;
while(!debug.empty()){
cout <<debug.front()<<endl;
debug.pop();
}
return 0;
}

ステータス

項目 データ
問題 0459 - セグメントツリー練習
ユーザー名 ei2332
投稿日時 2024-04-11 16:06:14
言語 C++17
状態 Accepted
得点 10
ソースコード長 1790 Byte
最大実行時間 70 ms
最大メモリ使用量 2676 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 70 ms 604 KB
1
Input02 AC 23 ms 448 KB
1
Input03 AC 16 ms 544 KB
1
Input04 AC 22 ms 512 KB
1
Input05 AC 21 ms 600 KB
1
Input06 AC 22 ms 572 KB
1
Input07 AC 20 ms 664 KB
1
Input08 AC 18 ms 628 KB
1
Input09 AC 28 ms 688 KB
1
Input10 AC 55 ms 2676 KB
1