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;
const int nx=5e4+5;
int n, m, q, w[nx], u[nx], v[nx], t, idx, vl, st, k;
struct segtree
{
int d[4*nx];
void build(int l, int r, int i)
{
if (l==r) return void(d[i]=w[l]);
int md=(l+r)/2;
build(l, md, 2*i);
build(md+1, r, 2*i+1);
d[i]=max(d[2*i], d[2*i+1]);
}
void update(int l, int r, int i, int idx, int vl)
{
if (idx<l||r<idx) return;
if (l==r) return void(d[i]=vl);
int md=(l+r)/2;
update(l, md, 2*i, idx, vl);
update(md+1, r, 2*i+1, idx, vl);
d[i]=max(d[2*i], d[2*i+1]);
}
int query(int l, int r, int i, int ql, int qr)
{
//cout<<"query "<<l<<' '<<r<<' '<<ql<<' '<<qr<<'\n';
if (qr<l||r<ql) return INT_MIN;
if (ql<=l&&r<=qr) return d[i];
int md=(l+r)/2;
return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr));
}
} s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<n; i++) cin>>u[i]>>v[i]>>w[i];
cin>>q;
s.build(1, n-1, 1);
//for (int i=1; i<n; i++) for (int j=i; j<n; j++) cout<<i<<' '<<j<<' '<<s.query(1, n-1, 1, i, j)<<'\n';
while (q--)
{
cin>>t;
if (t==1) cin>>idx>>vl, s.update(1, n-1, 1, idx, vl);
else
{
cin>>st>>k;
int l=1, r=st;
while (l<r)
{
int md=(l+r)/2;
if (s.query(1, n-1, 1, md, st-1)<=k) r=md;
else l=md+1;
}
//if (st==1||s.query(1, n-1, 1, st-1, st-1)>k) l=st;
int l2=st, r2=n-1;
while (l2<r2)
{
int md=(l2+r2+1)/2;
if (s.query(1, n-1, 1, st, md)<=k) l2=md;
else r2=md-1;
}
if (st==n||s.query(1, n-1, 1, st, st)>k) l2=st-1;
cout<<(l2-l+2)<<'\n';
}
}
}
/*
5 4
1 2 5
2 3 3
3 4 10
4 5 1
10
2 1 6
2 2 6
2 2 4
2 5 11
2 4 2
2 1 20
2 1 0
2 5 10
2 5 2
2 5 0
*/
# | 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... |