#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++)
{
nxt[A]=A+1;
arr[A]=X[A-1];
}
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;
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);
return 0;
}*/
Compilation message
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:79:19: warning: 'lol' may be used uninitialized in this function [-Wmaybe-uninitialized]
nxt[ptr]=nxt[lol];
~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9012 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9012 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9012 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9012 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
9012 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |