Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Q {
  5.     char type;
  6.     int val;
  7. };
  8.  
  9. int main() {
  10.     int n;
  11.     scanf("%d", &n);
  12.     vector<int> comp(n);
  13.     vector<Q> q(n);
  14.     char buf[10];
  15.     for(int i = 0; i < n; ++i) {
  16.         int x;
  17.         scanf("%s%d", buf, &x);
  18.         comp[i] = x;
  19.         q[i] = {buf[0], x};
  20.     }
  21.     sort(comp.begin(), comp.end());
  22.     vector<int> cnt(n);
  23.     int neq = 0, ndif = 0;
  24.     for(int i = 0; i < n; ++i) {
  25.         int idx = lower_bound(comp.begin(), comp.end(), q[i].val) - comp.begin();
  26.         if(q[i].type == 'i') {
  27.             int z = ++cnt[idx];
  28.             if(z == 2) {
  29.                 ++neq;
  30.             }
  31.             if(z == 1) {
  32.                 ++ndif;
  33.             }
  34.         } else {
  35.             if(cnt[idx]) {
  36.                 int z = --cnt[idx];
  37.                 if(z == 1) {
  38.                     --neq;
  39.                 }
  40.                 if(!z) {
  41.                     --ndif;
  42.                 }
  43.             }
  44.         }
  45.         if(neq) {
  46.             puts(ndif >= 2 ? "both" : "homo");
  47.         } else {
  48.             puts(ndif >= 2 ? "hetero" : "neither");
  49.         }
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement