1. #include <iostream>
2. #include <algorithm>
3. using namespace std;
4.
5. struct Key {
6. int a;
7. int b;
8. };
9. Key x[200000];
10.
11. int main() {
12. int n,k,i,i1,j1=0,j2=0,p,p1=0,p2=0,q,l,m,r;
13. char s[10];
14. cin >> n;
15. char y[n]; int z[n]; int u[n];
16. for (i=0; i<n; i++) {
17. cin >> s >> k;
18. y[i]=s[0]; z[i]=k;
19. if (s[0]=='i') {
20. u[j1]=k; j1++;
21. }
22. }
23. sort(u,u+j1);
24. for (i=0; i<j1; i++) {
25. if (u[i]!=u[i+1]) {
26. x[j2].a=u[i]; j2++;
27. }
28. }
29. for (i=0; i<n; i++) {
30. p=0; l=0; r=j2-1;
31. while (l<=r && p==0) {
32. m=(l+r)/2;
33. if (z[i]==x[m].a) {
34. i1=m; p=1;
35. } else if (z[i]<x[m].a) r=m-1;
36. else l=m+1;
37. }
38. if (p==1) {
39. q=x[i1].b;
40. if (y[i]=='i') {
41. q++;
42. if (q==1) p1++;
43. if (q==2) p2++;
44. x[i1].b=q;
45. } else if (q>0) {
46. q--;
47. if (q==0) p1--;
48. if (q==1) p2--;
49. x[i1].b=q;
50. }
51. }
52. if (p1>=2 && p2>=1) cout << "both" << endl;
53. else if (p1<2 && p2>=1) cout << "homo" << endl;
54. else if (p1>=2 && p2<1) cout << "hetero" << endl;
55. else cout << "neither" << endl;
56. }
57. return 0;
58. }
Success #stdin #stdout 0s 16800KB
stdin
11
insert 1
insert 2
insert 1
insert 4
delete 1
delete 3
delete 2
delete 1
insert 4
delete 4
delete 4
stdout
neither
hetero
both
both
hetero
hetero
hetero
neither
homo
neither
neither