#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;
struct qr{
int t,l,r,id;
inline friend bool operator < (qr fr,qr sc){
return fr.t<sc.t;
}
};
int n,q,t,l,r,tim,ans[MAXN],e[MAXN],d[MAXN];
int pos[MAXN],len[MAXN],pt,br,from,to;
qr query[MAXN];
int calc(int a,int b,int c,int d){
if(b<c or a>d)return 0;
if(a>=c and b<=d)return b-a+1;
if(a<=c and b>=d)return d-c+1;
if(a>=c)return d-a+1;
if(b<=d)return b-c+1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>e[i];
}
len[0]=1;
for(int i=n;i>=1;i--){
if(e[i]<=e[i-1])br++;
else{
pt++;
len[pt]=br+1;
pos[pt]=-i;
d[pt]=e[i];
br=0;
}
}
for(int i=1;i<=q;i++){
cin>>t>>l>>r;
query[i]={t,l,r,i};
}
reverse(pos+1,pos+pt+1);
reverse(len+1,len+pt+1);
reverse(d+1,d+pt+1);
sort(query+1,query+q+1);
for(int i=1;i<=q;i++){
while(tim<query[i].t){
tim++; pos[0]++;
for(int f=1;f<=pt;f++){
if((pos[f-1]-len[f-1]+1)-pos[f]>=d[f]+1){
pos[f]=(pos[f-1]-len[f-1]+1)-1;
}else break;
}
}
for(int f=0;f<=pt;f++){
from=pos[f]-len[f]+1; to=pos[f];
ans[query[i].id]+=calc(from,to,query[i].l,query[i].r);
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<"\n";
}
return 0;
}
Compilation message
worst_reporter3.cpp: In function 'int calc(int, int, int, int)':
worst_reporter3.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
23 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1467 ms |
20864 KB |
Output is correct |
2 |
Correct |
1480 ms |
36596 KB |
Output is correct |
3 |
Correct |
1454 ms |
36336 KB |
Output is correct |
4 |
Correct |
1555 ms |
36348 KB |
Output is correct |
5 |
Correct |
1449 ms |
36340 KB |
Output is correct |
6 |
Correct |
1461 ms |
36336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8540 KB |
Output is correct |
2 |
Correct |
2 ms |
8696 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
4 ms |
8540 KB |
Output is correct |
5 |
Correct |
3 ms |
8536 KB |
Output is correct |
6 |
Correct |
3 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1467 ms |
20864 KB |
Output is correct |
2 |
Correct |
1480 ms |
36596 KB |
Output is correct |
3 |
Correct |
1454 ms |
36336 KB |
Output is correct |
4 |
Correct |
1555 ms |
36348 KB |
Output is correct |
5 |
Correct |
1449 ms |
36340 KB |
Output is correct |
6 |
Correct |
1461 ms |
36336 KB |
Output is correct |
7 |
Correct |
3 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8696 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
4 ms |
8540 KB |
Output is correct |
11 |
Correct |
3 ms |
8536 KB |
Output is correct |
12 |
Correct |
3 ms |
8540 KB |
Output is correct |
13 |
Execution timed out |
2040 ms |
34200 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |