Pagini recente » Cod sursa (job #554509) | Cod sursa (job #886263) | Cod sursa (job #1155006) | Cod sursa (job #3186375) | Cod sursa (job #2800429)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int nmax=1000000;
int v[nmax+1], vp[nmax+1], op[nmax+1];
bool sol[nmax+1];
struct cmp{
bool operator()(int x, int y){
return v[x]<v[y];
}
};
int cautare(int x, int n, int n2){
int sol=0;
for(int i=n2;i>=1;i/=2){
if(sol+i<=n&&v[vp[sol+i]]<=x){
sol+=i;
}
}
if(v[vp[sol]]==x){
return sol;
}else{
return 0;
}
}
int main(){
int n;
fin>>n;
int n2=1;
while(n2*2<n){
n2*=2;
}
for(int i=1;i<=n;i++){
fin>>op[i];
fin>>v[i];
vp[i]=i;
}
sort(vp+1,vp+n+1,cmp());
for(int i=2;i<=n;i++){
if(v[vp[i]]==v[vp[i-1]]){
vp[i]=vp[i-1];
}
}
for(int i=1;i<=n;i++){
int a=cautare(v[i],n,n2);
if(op[i]==1){
sol[a]=1;
}else if(op[i]==2){
sol[a]=0;
}else{
fout<<sol[a]<<"\n";
}
}
return 0;
}