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;
using ll = long long;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n,q;
cin >> n >> q;
vector<ll> L(n-1),R(n-1);
for(ll i = 0;i<n-1;i++) cin >> L[i] >> R[i];
while(q--){
ll t,a,b,c,d;
cin >> t >> a >> b >> c;a--;
if (t==1){
L[a] = b;
R[a] = c;
}else{
c--;
cin >> d;
ll ans = 0;
ll t = b;
ll cur = a;
if (c>a){
while(cur<c){
cur++;
t++;
if (t>R[cur-1]){
ans += t-R[cur-1];
t = R[cur-1];
}
t = max(t,L[cur-1]+1);
//cout << "at " << cur << ", t=" << t << "\n";
}
}else{
while(cur>c){
cur--;
t++;
if (t>R[cur]){
ans += t-R[cur];
t = R[cur];
}
t = max(t,L[cur]+1);
//cout << "at " << cur << ", t=" << t << "\n";
}
}
if (t>d) ans += t-d;
cout << ans << "\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... |