結果

問題 No.3553 Good Quartet
コンテスト
ユーザー ルク
提出日時 2026-05-08 21:19:48
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 891 ms / 2,000 ms
コード長 2,223 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,644 ms
コンパイル使用メモリ 344,640 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2026-05-22 21:49:23
合計ジャッジ時間 11,689 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
constexpr ll dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Init {
  Init() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(15);
  }
} init;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {
  os << pair_var.first << " " << pair_var.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << " ";
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vec) {
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << " ";
  }
  return os;
}

int main() {
  ll n, q;
  cin >> n >> q;
  set<ll> st;
  rep(i, n) {
    ll x;
    cin >> x;
    st.insert(x);
  }
  ll ans = 0;
  vector<vector<ll>> vv = {{1, 5, 7, 11}, {1, 11, 19, 29}};
  for (auto x : st) {
    for (auto k : vv) {
      for (auto j : k) {
        if (x % j == 0) {
          ll base = x / j;
          bool f = true;
          for (auto l : k) {
            if (st.count(l * base) == 0) f = false;
          }
          if (f) ans += 1;
        }
      }
    }
  }
  ans /= 4;
  rep(i, q) {
    int t, x;
    cin >> t >> x;
    if (t == 1) {
      st.insert(x);
      for (auto k : vv) {
        for (auto j : k) {
          if (x % j == 0) {
            ll base = x / j;
            bool f = true;
            for (auto l : k) {
              if (st.count(l * base) == 0) f = false;
            }
            if (f) ans += 1;
          }
        }
      }
    } else {
      for (auto k : vv) {
        for (auto j : k) {
          if (x % j == 0) {
            ll base = x / j;
            bool f = true;
            for (auto l : k) {
              if (st.count(l * base) == 0) f = false;
            }
            if (f) ans -= 1;
          }
        }
      }
      st.erase(x);
    }
    cout << ans << endl;
  }
  return 0;
}
0