#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,q;
cin>>n>>q;
int pos[n];
for(int i=1;i<n;i++)pos[i]=1;
pos[0]=0;
int ans=0;
while(q--)
{
int x;
cin>>x;
if(x>0)
{
// aneeqa overtook x
if(pos[x]<pos[0]) // if x is behind then loop
{
ans++;
}
pos[0]=pos[x]+1;
}
else
{
// x<0
// this means -x over took aneeqa
// if(pos[0]<pos[-x]) // 0 is behind then x loop
// {
// }
pos[-x]=pos[0]+1;
}
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |