#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e5+5;
ll n, t, m, dp[nx], dp2[nx], a[nx], b[nx], q, l, r;
ll cost(ll x, ll y)
{
if (x<=y) return y-x;
return t-(x-y);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>t;
for (int i=2; i<=n; i++)
{
cin>>m>>a[i]>>b[i];
}
for (int i=2; i<=n; i++)
{
dp[i]=dp2[i-1]+b[i]-a[i];
if (i!=n) dp2[i]=dp[i]+cost(b[i], a[i+1]);
}
cin>>q;
while (q--)
{
cin>>l>>r;
cout<<dp[r]-dp2[l]<<'\n';
}
}
/*
6 10000
1
100 300
1
400 700
1
500 600
1
300 900
1
200 800
3
1 6
1 2
5 6
*/
# | 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... |