#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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
4592 KB |
Output is correct |
3 |
Correct |
33 ms |
5200 KB |
Output is correct |
4 |
Correct |
40 ms |
7000 KB |
Output is correct |
5 |
Correct |
33 ms |
5436 KB |
Output is correct |
6 |
Correct |
39 ms |
6992 KB |
Output is correct |
7 |
Correct |
38 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
5196 KB |
Output is correct |
9 |
Correct |
40 ms |
6928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
4592 KB |
Output is correct |
3 |
Correct |
33 ms |
5200 KB |
Output is correct |
4 |
Correct |
40 ms |
7000 KB |
Output is correct |
5 |
Correct |
33 ms |
5436 KB |
Output is correct |
6 |
Correct |
39 ms |
6992 KB |
Output is correct |
7 |
Correct |
38 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
5196 KB |
Output is correct |
9 |
Correct |
40 ms |
6928 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
4592 KB |
Output is correct |
3 |
Correct |
33 ms |
5200 KB |
Output is correct |
4 |
Correct |
40 ms |
7000 KB |
Output is correct |
5 |
Correct |
33 ms |
5436 KB |
Output is correct |
6 |
Correct |
39 ms |
6992 KB |
Output is correct |
7 |
Correct |
38 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
5196 KB |
Output is correct |
9 |
Correct |
40 ms |
6928 KB |
Output is correct |
10 |
Correct |
48 ms |
8528 KB |
Output is correct |
11 |
Correct |
63 ms |
11800 KB |
Output is correct |
12 |
Correct |
59 ms |
11860 KB |
Output is correct |
13 |
Correct |
52 ms |
9824 KB |
Output is correct |
14 |
Correct |
60 ms |
11856 KB |
Output is correct |
15 |
Correct |
61 ms |
11856 KB |
Output is correct |
16 |
Correct |
43 ms |
8532 KB |
Output is correct |
17 |
Correct |
60 ms |
11856 KB |
Output is correct |
18 |
Correct |
27 ms |
6016 KB |
Output is correct |
19 |
Correct |
25 ms |
5460 KB |
Output is correct |
20 |
Correct |
26 ms |
5980 KB |
Output is correct |
21 |
Correct |
28 ms |
5968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
4592 KB |
Output is correct |
3 |
Correct |
33 ms |
5200 KB |
Output is correct |
4 |
Correct |
40 ms |
7000 KB |
Output is correct |
5 |
Correct |
33 ms |
5436 KB |
Output is correct |
6 |
Correct |
39 ms |
6992 KB |
Output is correct |
7 |
Correct |
38 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
5196 KB |
Output is correct |
9 |
Correct |
40 ms |
6928 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
29 ms |
4592 KB |
Output is correct |
3 |
Correct |
33 ms |
5200 KB |
Output is correct |
4 |
Correct |
40 ms |
7000 KB |
Output is correct |
5 |
Correct |
33 ms |
5436 KB |
Output is correct |
6 |
Correct |
39 ms |
6992 KB |
Output is correct |
7 |
Correct |
38 ms |
6992 KB |
Output is correct |
8 |
Correct |
30 ms |
5196 KB |
Output is correct |
9 |
Correct |
40 ms |
6928 KB |
Output is correct |
10 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |