#include<bits/stdc++.h>
using namespace std;
const int N = 5e5;
int v[N];
array <int,3> trains[N + 1];
struct query{
int t,l,r,id;
}q2[N];
int ans[N];
int main(){
int n,q;
cin>>n>>q;
for(int i = 0;i < n;i++){
cin>>v[i];
if(i){
if(v[i]%v[i - 1] == 0){
v[i] = v[i]/v[i - 1]*v[i - 1];
}else{
v[i] = v[i]/v[i - 1]*v[i - 1] + v[i - 1];
}
}
}
int cnt = 0;
trains[cnt++] = {0,0,1};
int nr = 0;
for(int i = 0;i < n;i++){
if(i && v[i] != v[i - 1]){
trains[cnt++] = {-i,-i + nr - 1,v[i - 1]};
nr = 1;
}else nr++;
}
trains[cnt++] = {-n,-n + nr - 1,v[n - 1]};
///l,r,jumppower
for(int i = 0;i < q;i++){
cin>>q2[i].t>>q2[i].l>>q2[i].r;
q2[i].id = i;
}
sort(q2,q2 + q,[&](query a,query b){
return a.t < b.t;
});
int timp = 0;
for(int i = 0;i < q;i++){
trains[0][0]+=q2[i].t - timp;
trains[0][1]+=q2[i].t - timp;
for(int j = 1;j < cnt;j++){
if(trains[j][1] < trains[j - 1][0] - trains[j][2]){
int sum = (trains[j - 1][0] - trains[j][1] - 1)/trains[j][2];
trains[j][0]+=sum*trains[j][2];
trains[j][1]+=sum*trains[j][2];
}
}
//cout<<q2[i].t<<'\n';
int score = 0;
for(int j = 0;j < cnt;j++){
//cout<<trains[j][0]<<' '<<trains[j][1]<<' '<<trains[j][2]<<'\n';
score+=max(0,min(q2[i].r,trains[j][1]) - max(q2[i].l,trains[j][0]) + 1);
}
ans[q2[i].id] = score;
timp = q2[i].t;
}
for(int i = 0;i < q;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
429 ms |
17232 KB |
Output is correct |
2 |
Correct |
472 ms |
32308 KB |
Output is correct |
3 |
Correct |
454 ms |
32180 KB |
Output is correct |
4 |
Correct |
424 ms |
32340 KB |
Output is correct |
5 |
Correct |
433 ms |
32340 KB |
Output is correct |
6 |
Correct |
470 ms |
32172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
429 ms |
17232 KB |
Output is correct |
2 |
Correct |
472 ms |
32308 KB |
Output is correct |
3 |
Correct |
454 ms |
32180 KB |
Output is correct |
4 |
Correct |
424 ms |
32340 KB |
Output is correct |
5 |
Correct |
433 ms |
32340 KB |
Output is correct |
6 |
Correct |
470 ms |
32172 KB |
Output is correct |
7 |
Correct |
1 ms |
6744 KB |
Output is correct |
8 |
Correct |
1 ms |
6488 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
442 ms |
30800 KB |
Output is correct |
14 |
Correct |
474 ms |
31316 KB |
Output is correct |
15 |
Correct |
405 ms |
30032 KB |
Output is correct |
16 |
Correct |
452 ms |
30624 KB |
Output is correct |
17 |
Correct |
509 ms |
34904 KB |
Output is correct |
18 |
Correct |
512 ms |
34896 KB |
Output is correct |
19 |
Correct |
487 ms |
34848 KB |
Output is correct |
20 |
Correct |
577 ms |
34724 KB |
Output is correct |
21 |
Correct |
572 ms |
34960 KB |
Output is correct |
22 |
Correct |
520 ms |
34900 KB |
Output is correct |
23 |
Correct |
502 ms |
34836 KB |
Output is correct |
24 |
Correct |
548 ms |
34900 KB |
Output is correct |
25 |
Correct |
424 ms |
32340 KB |
Output is correct |
26 |
Correct |
436 ms |
32340 KB |
Output is correct |
27 |
Correct |
541 ms |
34332 KB |
Output is correct |
28 |
Correct |
528 ms |
34848 KB |
Output is correct |
29 |
Correct |
455 ms |
34388 KB |
Output is correct |
30 |
Correct |
487 ms |
34336 KB |
Output is correct |
31 |
Correct |
490 ms |
34616 KB |
Output is correct |
32 |
Correct |
407 ms |
30900 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |