http://www.spoj.pl/problems/OLOLO/
plz help the is 10th time i tried to optimize this code
should be AC
#include <iostream>
using namespace std;
int main()
{
unsigned char* A= new unsigned char [125000000];
unsigned char m=1;
int t,I;
unsigned long X;
unsigned long long b=0;
cin>>t;
for(int i0=0;i0<t;++i0)
{
cin>>X;
m=1<<(X%8);
if(A[X/8] & m) { A[X/8]-=m; b-=X; } // if X apeared before
else { A[X/8]+=m; b+=X; }
}
printf("%llu",b);
return 0;
}
i tried to take 10^9 bit (125000000 unsigned char) that each bit denote to decimal num from 1 to 10^9.
i make bit(X) = 1 if X apear 1st time ( b increased by X), and =0 if 2ed (b decreased by X) .
thanks