#ifdef NACHIA #define _GLIBCXX_DEBUG #else // disable assert #define NDEBUG #endif #include #include #include #include #include #include #include #include #include namespace nachia { template struct Hash { using u64 = unsigned long long; using u128 = __uint128_t; u64 seed; u64 base; static u64 RngInit(){ return std::chrono::high_resolution_clock::now().time_since_epoch().count() ^ std::random_device()(); }; u64 splitmix64(u64& x) { u64 z = (x += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; return z ^ (z >> 31); } Hash() : seed(RngInit()), base(mulmod(splitmix64(seed), 1)) {} Hash(u64 seed) : seed(seed) {} static constexpr u64 MOD = (1ull << 61) - 1; static u64 takemod(u64 a){ return a >= MOD ? a - MOD : a; } static u64 mulmod(u64 a, u64 b){ u128 x = u128(a) * b; return takemod((x >> 61) + (x & MOD)); } template, int> = 0> u64 operator()(const K& key) const { if constexpr (std::is_integral_v && (sizeof(L) <= 8)) return hash_trivial(key); constexpr size_t z = (sizeof(K) + 7) / 8; u64 h[z] = {}, res = 0; memcpy(h, &key, sizeof(K)); for(u64 a : h) res = takemod(mulmod(res, base) + hash_trivial(a)); return res; } u64 operator()(const K& key, int bitnum) const { return operator()(key) >> (61 - bitnum); } private: u64 hash_trivial(u64 key) const { u64 x = (key ^ seed) * 0x1cafefdc0172110full; return takemod((x >> 61) + (x & MOD)); } }; } // namespace nachia namespace nachia { template struct HashMap { struct Tuple { Key key; Val val; bool has = false; }; Hash hasher; int lgn; int n; unsigned long long mask; std::vector vload; struct iterator { typename std::vector::iterator i; typename std::vector::iterator e; iterator& operator++(){ i++; while(i != e && !i->has){ i++; } return *this; } iterator operator++(int) { auto res = *this; ++*this; return res; } bool operator==(const iterator& r) const { return i == r.i; } bool operator!=(const iterator& r) const { return !(i == r.i); } Tuple* operator->() const { return i.operator->(); } }; HashMap() : lgn(2), n(0), mask(0), vload(0){} int hkey(const Key& key) const { return hasher(key, lgn); } int find_internal(const Key& key) const { int p = hkey(key); while(vload[p].has && !(vload[p].key == key)) p = (p + 1) & mask; return p; } void set_internal(Key key, Val val){ int p = find_internal(key); if(!vload[p].has){ vload[p].key = std::move(key); vload[p].has = true; } vload[p].val = std::move(val); } void alloc(int new_lgn){ lgn = new_lgn; mask = (1ull << lgn) - 1; auto buf = std::move(vload); vload.assign(1 << lgn, Tuple()); for(size_t i=0; i= int(mask / 2)) alloc(lgn + 1); int p = find_internal(key); if(!vload[p].has){ vload[p].key = std::move(key); vload[p].has = true; n++; } return vload[p].val; } int size(){ return n; } iterator begin() { if(size() == 0) return end(); auto i = vload.begin(); while(!i->has) i++; return { i, vload.end() }; } iterator end() { return { vload.end(), vload.end() }; } iterator find(const Key& key){ int p = find_internal(key); if(!vload[p].has) return end(); return { vload.begin() + p, vload.end() }; } void clear() { vload.clear(); lgn = 2; n = 0; mask = 0; } void reserve(int expect_n){ if(expect_n < n) expect_n = n; int next_lgn = 3; while(expect_n >= (1 << next_lgn) / 2 - 1) next_lgn++; alloc(next_lgn); } }; } // namespace nachia using namespace std; using ll = long long; const ll INF = 1ll << 60; #define REP(i,n) for(ll i=0; i using V = vector; template void chmax(A& l, const B& r){ if(l < r) l = r; } template void chmin(A& l, const B& r){ if(r < l) l = r; } void testcase(){ ll N, Q; cin >> N >> Q; V A(N); REP(i,N) cin >> A[i]; nachia::HashMap ds0, ds1, ds2; ll ans = 0; auto insds0 = [&](ll x) -> void { if(++ds0[x] == 4) ans += 1; }; auto remds0 = [&](ll x) -> void { if(ds0[x]-- == 4) ans -= 1; }; auto insds1 = [&](ll x) -> void { if(++ds1[x] == 4) ans += 1; }; auto remds1 = [&](ll x) -> void { if(ds1[x]-- == 4) ans -= 1; }; auto insds2 = [&](ll x) -> void { if(++ds2[x] == 4) ans += 1; }; auto remds2 = [&](ll x) -> void { if(ds2[x]-- == 4) ans -= 1; }; auto insxds = [&](ll x) -> void { for(ll d : {1,5,7,11}) if(x%d == 0) insds0(x/d); for(ll d : {1,11,19,29}) if(x%d == 0) insds1(x/d); }; auto remxds = [&](ll x) -> void { for(ll d : {1,5,7,11}) if(x%d == 0) remds0(x/d); for(ll d : {1,11,19,29}) if(x%d == 0) remds1(x/d); }; REP(i,N) insxds(A[i]); REP(qi,Q){ ll t, x; cin >> t >> x; if(t == 1) insxds(x); else remxds(x); cout << ans << "\n"; } } int main(){ cin.tie(0)->sync_with_stdio(0); testcase(); return 0; }