Pagini recente » Profil EugenStoica | Cod sursa (job #551009) | Cod sursa (job #1617886) | Cod sursa (job #2025943) | Cod sursa (job #1609741)
#include <iostream>
#include <stdbool.h>
#include <stdio.h>
#define N 62500000
#include <assert.h> /* assert */
using namespace std;
typedef unsigned long ul;
ul b[N];
bool getb(ul &boolv, ul pos)
{
return (boolv >> pos) & 1;
}
void setb(ul &boolv, ul pos, bool val)
{
boolv ^= (-(val & 1) ^ boolv) & (1 << pos);
}
template <typename T>
void print(T n)
{
// cout << sizeof(n) * 8 << "b: ";
for(int i = sizeof(n) * 8; i >= 0; i--)
{
cout << (n >> i & 1);
}
}
int main()
{
int opt;
long nrOperatii;
long nr;
FILE * fread = fopen("hashuri.in","r");
FILE * fwrite = fopen("hashuri.out","w");
fscanf(fread, "%lu", &nrOperatii);
for(long i = 0; i < nrOperatii; i++)
{
fscanf(fread, "%lu", &opt);
fscanf(fread, "%lu", &nr);
cout << "nr / N = " << nr / 32 << endl;
switch(opt)
{
case(1):
setb(b[nr / 32], nr, true);
break;
case(2):
setb(b[nr / 32], nr, false);
break;
case(3):
fprintf(fwrite, "%d\n", getb(b[nr / 32], nr));
//cout << exists << endl;
break;
}
// cout << i << " ";
// print(b[0]);cout<<"|";
// print(b[1]);
// cout << endl;
// cout << endl;
}
fclose(fread);
fclose(fwrite);
return 0;
}