This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
struct segtree{
std::vector<int> t;
int n;
segtree(int n, int v) : t(2 * n, v), n(n) { }
int get(int l, int r){
int res = 1e9 + 7;
for (l += n, r += n; l <= r; l >>= 1, r >>= 1) {
if (l & 1) res = std::min(res, t[l++]);
if (!(r & 1)) res = std::min(res, t[r--]);
}
return res;
}
void update(int p, int val){
for (t[p += n] = val; p > 1; p >>= 1) t[p >> 1] = std::min(t[p], t[p ^ 1]);
}
};
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m, q;
std::cin >> n >> m;
segtree seg(n + 2, 0);
for (int i = 0; i < m; i++) {
int u, v, w;
std::cin >> u >> v >> w;
seg.update(i + 1, w);
}
std::cin >> q;
while (q--) {
int type;
std::cin >> type;
if (type == 1) {
int b, r;
std::cin >> b >> r;
seg.update(b, r);
} else {
int s, W;
std::cin >> s >> W;
s--;
int L, R;
if (s == 0) L = 1;
else {
int l = -1, r = n + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (seg.get(mid, s) >= W)
r = mid;
else
l = mid;
}
L = r;
}
if (s == n - 1) R = n;
else {
int l = 0, r = n + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (seg.get(s + 1, mid) >= W)
l = mid;
else
r = mid;
}
R = l + 1;
}
std::cout << R - L + 1 << '\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |