## #2235971

Solution for DSL_2_A: Range Minimum Query (RMQ) by Tsuta_J

Source Code Status Test Cases
Policy: public     Reviewed: 63
00.11 sec    4144 KB    50 lines     1172 bytes    2017-03-29 16:00
```#include <bits/stdc++.h>
using namespace std;

int N, Q;
int const INF = INT_MAX;

struct SegmentTree {
private:
int n;
vector<int> node;

public:
SegmentTree(vector<int> v) {
int sz = v.size();
n = 1; while(n < sz) n *= 2;
node.resize(2*n-1, INF);
for(int i=0; i<sz; i++) node[i+n-1] = v[i];
for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
}

void update(int x, int val) {
x += (n - 1);
node[x] = val;
while(x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2*x+1], node[2*x+2]);
}
}

int getmin(int a, int b, int k=0, int l=0, int r=-1) {
if(r < 0) r = n;
if(r <= a || b <= l) return INF;
if(a <= l && r <= b) return node[k];

int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
return min(vl, vr);
}
};

int main() {
cin >> N >> Q;
SegmentTree seg( vector<int>(N, INF) );
for(int i=0; i<Q; i++) {
int c, x, y; cin >> c >> x >> y;
if(c == 0) seg.update(x, y);
else cout << seg.getmin(x, y+1) << endl;
}
}

```
 Compile Error Logs: You are not authorized to see the message.

Status
 Judge: 20/20 C++ CPU: 00.11 sec Memory: 4144 KB Length: 1172 B 2017-03-29 16:00 2017-03-29 16:00
Results for testcases
 Case # Verdict CPU Time Memory In Out Case Name Case #1: : Accepted 00.00 sec 3108 KB Case #2: : Accepted 00.00 sec 3104 KB Case #3: : Accepted 00.00 sec 3084 KB Case #4: : Accepted 00.00 sec 3008 KB Case #5: : Accepted 00.00 sec 3084 KB Case #6: : Accepted 00.00 sec 3096 KB Case #7: : Accepted 00.00 sec 2988 KB Case #8: : Accepted 00.00 sec 3004 KB Case #9: : Accepted 00.00 sec 3060 KB Case #10: : Accepted 00.00 sec 3080 KB Case #11: : Accepted 00.00 sec 3008 KB Case #12: : Accepted 00.09 sec 3592 KB Case #13: : Accepted 00.00 sec 3088 KB Case #14: : Accepted 00.00 sec 3032 KB Case #15: : Accepted 00.00 sec 3108 KB Case #16: : Accepted 00.00 sec 3116 KB Case #17: : Accepted 00.10 sec 4088 KB Case #18: : Accepted 00.11 sec 4036 KB Case #19: : Accepted 00.11 sec 4144 KB Case #20: : Accepted 00.11 sec 4052 KB
 < prev | / | next >

 Judge Input #  ( | ) Judge Output #  ( | )