#2236696

Solution for DSL_2_F: RMQ and RUQ by Tsuta_J

Source Code Status Test Cases
Policy: public     Reviewed: 129
00.15 sec    5224 KB    78 lines     2030 bytes    2017-03-29 23:39
```#include <bits/stdc++.h>
using namespace std;

int N, Q;
const int INF = INT_MAX;
struct LazySegmentTree {
private:
int n;
vector<int> node, lazy;
vector<bool> lazyFlag;

public:
LazySegmentTree(vector<int> v) {
int sz = (int)v.size();
n = 1; while(n < sz) n *= 2;
node.resize(2*n-1);
lazy.resize(2*n-1, INF);
lazyFlag.resize(2*n-1, false);

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[i*2+1], node[i*2+2]);
}

void lazyEvaluate(int k, int l, int r) {
if(lazyFlag[k]) {
node[k] = lazy[k];
if(r - l > 1) {
lazy[k*2+1] = lazy[k*2+2] = lazy[k];
lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
}
lazyFlag[k] = false;
}
}

void update(int a, int b, int x, int k=0, int l=0, int r=-1) {
if(r < 0) r = n;
lazyEvaluate(k, l, r);
if(b <= l || r <= a) return;
if(a <= l && r <= b) {
lazy[k] = x;
lazyFlag[k] = true;
lazyEvaluate(k, l, r);
}
else {
update(a, b, x, 2*k+1, l, (l+r)/2);
update(a, b, x, 2*k+2, (l+r)/2, r);
node[k] = min(node[2*k+1], node[2*k+2]);
}
}

int find(int a, int b, int k=0, int l=0, int r=-1) {
if(r < 0) r = n;
lazyEvaluate(k, l, r);
if(b <= l || r <= a) return INF;
if(a <= l && r <= b) return node[k];
int vl = find(a, b, 2*k+1, l, (l+r)/2);
int vr = find(a, b, 2*k+2, (l+r)/2, r);
return min(vl, vr);
}
};

int main() {
cin >> N >> Q;
LazySegmentTree seg( vector<int>(N, INF) );
for(int i=0; i<Q; i++) {
int query; cin >> query;
if(query == 0) {
int s, t, x; cin >> s >> t >> x;
seg.update(s, t+1, x);
}
else {
int s, t; cin >> s >> t;
cout << seg.find(s, t+1) << endl;
}
}
return 0;
}

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

Status
 Judge: 22/22 C++ CPU: 00.15 sec Memory: 5224 KB Length: 2030 B 2017-03-29 23:39 2017-03-29 23:39
Results for testcases
 Case # Verdict CPU Time Memory In Out Case Name Case #1: : Accepted 00.00 sec 3052 KB Case #2: : Accepted 00.00 sec 3124 KB Case #3: : Accepted 00.00 sec 3060 KB Case #4: : Accepted 00.00 sec 3008 KB Case #5: : Accepted 00.00 sec 3060 KB Case #6: : Accepted 00.00 sec 2992 KB Case #7: : Accepted 00.00 sec 2996 KB Case #8: : Accepted 00.00 sec 3024 KB Case #9: : Accepted 00.00 sec 3064 KB Case #10: : Accepted 00.00 sec 3016 KB Case #11: : Accepted 00.02 sec 3148 KB Case #12: : Accepted 00.01 sec 3148 KB Case #13: : Accepted 00.01 sec 3104 KB Case #14: : Accepted 00.01 sec 3060 KB Case #15: : Accepted 00.13 sec 5120 KB Case #16: : Accepted 00.15 sec 5144 KB Case #17: : Accepted 00.15 sec 5180 KB Case #18: : Accepted 00.13 sec 5096 KB Case #19: : Accepted 00.10 sec 5176 KB Case #20: : Accepted 00.14 sec 5072 KB Case #21: : Accepted 00.07 sec 5124 KB Case #22: : Accepted 00.13 sec 5224 KB
 < prev | / | next >

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