#include <elephants.h>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const int MAX=1e6;
int N,L,start,ptr,arr[MAX],nxt[MAX],pos[MAX];
void init(int n, int l, int X[])
{
N=n;
L=l;
ptr=N;
start=1;
for(int A=1;A<=N;A++)
{
pos[A]=A;
nxt[A]=A+1;
arr[A]=X[A-1];
}
nxt[N]=0;
return ;
}
int cal()
{
int cur=arr[start],res=1;
for(int A=start;A>0;A=nxt[A])
{
if(arr[A]-cur>L)
{
cur=arr[A];
res++;
}
}
return res;
}
int update(int i, int y)
{
if(N==1)
return 1;
i++;
++ptr;
if(start==pos[i])
start=nxt[start];
else
{
for(int A=start;A>0;A=nxt[A])
{
if(nxt[A]==pos[i])
{
nxt[A]=nxt[nxt[A]];
break;
}
}
}
pos[i]=ptr;
arr[ptr]=y;
if(y<arr[start])
{
nxt[ptr]=start;
start=ptr;
}
else
{
int lol=0;
for(int A=start;A>0;A=nxt[A])
{
if(y>arr[A])
lol=A;
}
nxt[ptr]=nxt[lol];
nxt[lol]=ptr;
}
return cal();
}
/*signed main()
{
ios_base::sync_with_stdio(false);
int X[]={10,15,17,20};
init(4,10,X);
cout<<update(2,16)<<"\n";
cout<<update(1,25)<<"\n";
cout<<update(3,35)<<"\n";
cout<<update(0,38)<<"\n";
cout<<update(2,0)<<"\n";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
5741 ms |
2764 KB |
Output is correct |
8 |
Correct |
8424 ms |
4120 KB |
Output is correct |
9 |
Execution timed out |
9041 ms |
5896 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
5741 ms |
2764 KB |
Output is correct |
8 |
Correct |
8424 ms |
4120 KB |
Output is correct |
9 |
Execution timed out |
9041 ms |
5896 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
612 KB |
Output is correct |
5 |
Correct |
3 ms |
612 KB |
Output is correct |
6 |
Correct |
2 ms |
612 KB |
Output is correct |
7 |
Correct |
5741 ms |
2764 KB |
Output is correct |
8 |
Correct |
8424 ms |
4120 KB |
Output is correct |
9 |
Execution timed out |
9041 ms |
5896 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |