#include <bits/stdc++.h>
using namespace std;
int arr[50001],n,l;
unsigned short ind[50001],ind2[50001];
void init(int N,int L,int X[]){
l = L;
n = N;
for(int i =0 ;i<n;i++){
arr[i] = X[i];
ind[i] = i;
ind2[i] = i;
}
}
int update(int i, int y){
i = ind[i];
arr[i] = y;
if(arr[i]>arr[i-1]){
while(i<n-1&&arr[i+1]<arr[i]){
swap(arr[i],arr[i+1]);
swap(ind[ind2[i]],ind[ind2[i+1]]);
swap(ind2[i],ind2[i+1]);
i++;
}
}else{
while(i>0&&arr[i-1]>arr[i]){
swap(arr[i],arr[i-1]);
swap(ind[ind2[i]],ind[ind2[i-1]]);
swap(ind2[i],ind2[i-1]);
i--;
}
}
int ans = 1 , la = arr[0];
for(int i = 1;i<n;i++){
if(arr[i]>la+l){
la = arr[i];ans++;
}
}
return ans;
}/*
int main(){
int N = 4 , L = 10;
int X[] ={10,15,17,20};
init(N,L,X);
cout<<update(2,16)<<endl;
cout<<update(1,25)<<endl;
cout<<update(3,35)<<endl;
cout<<update(0,38)<<endl;
cout<<update(2,0)<<endl;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1014 ms |
1824 KB |
Output is correct |
8 |
Correct |
2012 ms |
1992 KB |
Output is correct |
9 |
Correct |
1460 ms |
2912 KB |
Output is correct |
10 |
Correct |
8266 ms |
2688 KB |
Output is correct |
11 |
Correct |
8283 ms |
2632 KB |
Output is correct |
12 |
Correct |
7635 ms |
2780 KB |
Output is correct |
13 |
Correct |
8478 ms |
2484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1014 ms |
1824 KB |
Output is correct |
8 |
Correct |
2012 ms |
1992 KB |
Output is correct |
9 |
Correct |
1460 ms |
2912 KB |
Output is correct |
10 |
Correct |
8266 ms |
2688 KB |
Output is correct |
11 |
Correct |
8283 ms |
2632 KB |
Output is correct |
12 |
Correct |
7635 ms |
2780 KB |
Output is correct |
13 |
Correct |
8478 ms |
2484 KB |
Output is correct |
14 |
Correct |
1981 ms |
2724 KB |
Output is correct |
15 |
Correct |
4235 ms |
2636 KB |
Output is correct |
16 |
Execution timed out |
9041 ms |
3264 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1014 ms |
1824 KB |
Output is correct |
8 |
Correct |
2012 ms |
1992 KB |
Output is correct |
9 |
Correct |
1460 ms |
2912 KB |
Output is correct |
10 |
Correct |
8266 ms |
2688 KB |
Output is correct |
11 |
Correct |
8283 ms |
2632 KB |
Output is correct |
12 |
Correct |
7635 ms |
2780 KB |
Output is correct |
13 |
Correct |
8478 ms |
2484 KB |
Output is correct |
14 |
Correct |
1981 ms |
2724 KB |
Output is correct |
15 |
Correct |
4235 ms |
2636 KB |
Output is correct |
16 |
Execution timed out |
9041 ms |
3264 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |