需要把标记数组开大开大开大!
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int N=500005;
bool temp[10*N];
int a[N];
int main()
{
memset(temp,false,sizeof(temp));
memset(a,0,sizeof(a));
a[0]=0;
temp[0]=true;
for(int i=1;i<N;i++)
{
if(a[i-1]-i>0&&temp[a[i-1]-i]==false)
{
a[i]=a[i-1]-i;
temp[a[i]]=true;
}
else
{
a[i]=a[i-1]+i;
temp[a[i]]=true;
}
}
int n;
while(scanf("%d",&n)!=-1)
{
if(n==-1) break;
else printf("%d\n",a[n]);;
}
return 0;
}