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"
using namespace std;
#define int long long
#define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
#define repd(i, a, b) for(int (i) = (a); i >= (b); --i)
#define em emplace
#define eb emplace_back
#define pi pair<int, int>
#define fr first
#define sc second
#define mp make_pair
const char nl = '\n';
const int mod = 1e9 + 7;
const int inf = 1e17;
/* struct SGT { */
/* int n, m; */
/* vector<int> a; */
/* SGT() {} */
/* SGT(int N, int wt[]) { */
/* /1* n = 1; while(n < N + 1) n *= 2; *1/ */
/* /1* a.resize(2*n, -inf); *1/ */
/* /1* m = N - 1; *1/ */
/* /1* rep(i, 1, N - 1) { *1/ */
/* /1* a[i + n] = wt[i]; *1/ */
/* /1* } *1/ */
/* /1* repd(i, n - 1, 1) calc(i); *1/ */
/* n = N - 1; */
/* a.resize(n + 1); */
/* rep(i, 1, n - 1) a[i] = wt[i]; */
/* } */
/* void mod(int x, int v) { */
/* /1* x += n; *1/ */
/* /1* a[x] = v; *1/ */
/* /1* for(x /= 2; x > 0; x /= 2) calc(x); *1/ */
/* } */
/* void calc(int i) { */
/* /1* if(i >= n) a[i] = min(a[2*i], a[2*i + 1]); *1/ */
/* } */
/* /1* int left(int x, int lx, int rx, int pos, int val) { *1/ */
/* /1* if(rx < pos) return n; *1/ */
/* /1* if(a[x] >= val) return n; *1/ */
/* /1* int d = (lx + rx) / 2; *1/ */
/* /1* if(d < pos) return left(2*x + 1, d + 1, rx, pos, val); *1/ */
/* /1* int ans = left(2*x, lx, d, pos, val); *1/ */
/* /1* if(ans < n) return ans; *1/ */
/* /1* return left(2*x + 1, d + 1, rx, pos, val); *1/ */
/* /1* } *1/ */
/* int left(int pos, int val) { // first i >= pos with a[i] < val */
/* while(pos < n && a[pos] >= val) ++pos; */
/* return pos; */
/* /1* return min(m + 1, left(1, 0, n - 1, pos, val)); *1/ */
/* } */
/* /1* int right(int x, int lx, int rx, int pos, int val) { *1/ */
/* /1* if(lx > pos) return 0; *1/ */
/* /1* if(a[x] >= val) return 0; *1/ */
/* /1* int d = (lx + rx) / 2; *1/ */
/* /1* if(pos < d + 1) return right(2*x, lx, d, pos, val); *1/ */
/* /1* int ans = right(2*x + 1, d + 1, rx, pos, val); *1/ */
/* /1* if(ans > 0) return ans; *1/ */
/* /1* return right(2*x, lx, d, pos, val); *1/ */
/* /1* } *1/ */
/* int right(int pos, int val) { // first i <= pos with a[i] < val */
/* /1* return max(1ll, right(1, 0, n - 1, pos, val)); *1/ */
/* while(pos > 0 && a[pos] >= val) --pos; */
/* return pos; */
/* } */
/* }; */
#warning constants according to subtask
const int N = 5e4L + 10;
const int M = 1e5L + 10;
int n, m, q;
int ed[M][3];
int wt[N];
/* SGT sgt; */
void modify(int b, int r) {
wt[b] = r;
/* sgt.mod(b, r); */
}
void query(int s, int w) {
int r = s;
int l = s;
while(r < n && wt[r] >= w) ++r;
while(l > 0 && wt[l] >= w) --l;
cout << r - l << nl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
rep(i, 1, m) {
int u, v, d;
cin >> u >> v >> d;
assert(u == i);
assert(v == i + 1);
wt[u] = d;
}
/* sgt = SGT(n + 1, wt); */
cin >> q;
rep(i, 1, q) {
int t; cin >> t;
if(t == 1) {
int b, r; cin >> b >> r;
modify(b, r);
}
else {
int s, w; cin >> s >> w;
query(s, w);
}
}
}
Compilation message (stderr)
bridges.cpp:81:2: warning: #warning constants according to subtask [-Wcpp]
81 | #warning constants according to subtask
| ^~~~~~~
bridges.cpp: In function 'int32_t main()':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
| ^
bridges.cpp:107:5: note: in expansion of macro 'rep'
107 | rep(i, 1, m) {
| ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
| ^
bridges.cpp:118:5: note: in expansion of macro 'rep'
118 | rep(i, 1, q) {
| ^~~
# | 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... |