Submission #81767


ソースコード

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<bits/stdc++.h>
using namespace std;
template<typename T>
struct Dseg {
T shoki;
function<T(T,T)>f;
long long sz;
struct Node {
T val;
Node* l;
Node* r;
Node(T sh) : val(sh),l(nullptr), r(nullptr) {}
};
Node* root;
// 初期化
Dseg(int n,function<T(T,T)>F,T sh = 0) {
shoki = sh;
f = F;
sz = 1;
while (sz < n) sz *= 2;
root = new Node(shoki);
}
// 更新
void update(Node*& node, int k, T x, int l, int r) {
if (!node) node = new Node(shoki);
if (r - l == 1) {
node->val = x;
return;
}
int m = (l + r) / 2;
if (k < m)
update(node->l, k, x, l, m);
else
update(node->r, k, x, m, r);
node->val = f(node->l ? node->l->val : shoki, node->r ? node->r->val : shoki);
}
void update(int k, T x) {
update(root, k, x, 0, sz);
}
// クエリ
T query(Node* node, int a, int b, int l, int r) {
if (!node) return shoki;
if (r <= a || b <= l) return shoki;
if (a <= l && r <= b) return node->val;
int m = (l + r) / 2;
return f(query(node->l, a, b, l, m), query(node->r, a, b, m, r));
}
T query(int a, int b) {
return query(root, a, b, 0, sz);
}
void debug(Node* node, int l, int r, int depth = 0) {
if (!node) return;
cout << string(depth * 2, ' ') << "[" << l << ", " << r << "): " << node->val << endl;
int m = (l + r) / 2;
debug(node->l, l, m, depth + 1);
debug(node->r, m, r, depth + 1);
}
void debug() {
debug(root, 0, sz);
}
};
int main(){
cin.tie(nullptr);ios::sync_with_stdio(false);
cout << std::fixed << std::setprecision(10);
Dseg<int> st(1e9+10,[](int x,int y){return min(x,y);},INT_MAX);
int n;
cin >>n;
for(int i = 0;i < n;i++){
int x;
cin >>x;
st.update(i,x);
}
while(true){
string s;
cin >>s;
if(s[0] == 'm'){
int x,y;
cin >>x>>y;
cout <<st.query(x,y+1)<<"\n";
}else if(s[0] == 'u'){
int x,y;
cin >>x>>y;
st.update(x,y);
}else{
break;
}
}
// st.debug();
}

ステータス

項目 データ
問題 0459 - セグメントツリー練習
ユーザー名 ei2332
投稿日時 2024-12-01 20:36:26
言語 C++17
状態 Accepted
得点 10
ソースコード長 2231 Byte
最大実行時間 63 ms
最大メモリ使用量 8796 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
Input01 AC 18 ms 604 KB
1
Input02 AC 20 ms 552 KB
1
Input03 AC 16 ms 632 KB
1
Input04 AC 23 ms 576 KB
1
Input05 AC 16 ms 520 KB
1
Input06 AC 23 ms 460 KB
1
Input07 AC 27 ms 392 KB
1
Input08 AC 26 ms 568 KB
1
Input09 AC 21 ms 1164 KB
1
Input10 AC 63 ms 8796 KB
1