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;
void solve(){
int n, t, r;cin >> n >> t;
int a[n],b[n];for(int i = 0;i < n-1;i++){
cin >> r;
cin >> a[i] >> b[i];
}
long long g[n-1];
for(int i = 0;i < n-1;i++){
if(b[i] <= a[i+1]) g[i] = a[i+1]-a[i];
else g[i] = a[i+1]+t-a[i];
if(i) g[i] += g[i-1];
}
int q;cin >> q;
while(q--){
int l, r;cin >> l >> r;l--;r--;
if(r==l+1) cout << b[l]-a[l] << '\n';
else {
cout << g[r-2]-(l?g[l-1]:0) + b[r-1]-a[r-1] << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |