이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=300010;
int N, Q, L[Nmax], R[Nmax];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>Q;
for(int i=1; i<N; i++) cin>>L[i]>>R[i];
while(Q--) {
int op; cin>>op;
if(op==1) {
int k, l, r; cin>>k>>l>>r;
L[k]=l, R[k]=r;
}
else {
int s, x, e, y, ans=0;
cin>>s>>x>>e>>y;
if(s<e) {
for(int i=s; i<e; i++) {
if(x<=L[i]) x=L[i]+1;
else if(x<R[i]) x++;
else ans+=x-(R[i]-1), x=R[i];
}
ans+=max(0ll, x-y);
}
else {
for(int i=s-1; i>=e; i--) {
if(x<=L[i]) x=L[i]+1;
else if(x<R[i]) x++;
else ans+=x-(R[i]-1), x=R[i];
}
ans+=max(0ll, x-y);
}
cout<<ans<<"\n";
}
}
return 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... |