結果

問題 No.3553 Good Quartet
コンテスト
ユーザー Iroha_3856
提出日時 2026-05-22 22:43:55
言語 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
結果
WA  
実行時間 -
コード長 1,162 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,518 ms
コンパイル使用メモリ 352,056 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2026-05-22 22:44:21
合計ジャッジ時間 12,074 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()

int main() {
    int N, Q; cin >> N >> Q;
    
    vector<map<int, int>> cnt(2);
    int ans = 0;
    
    vector<vector<int>> A = {
        {1, 5, 7, 11}, 
        {1, 11, 19, 29}
    };
    
    auto f = [&](int i, int s, int d) -> void {
        vector<int> upd;
        vector<int> a = A[i];
        for (int b : a) {
            if (s % b == 0) {
                upd.push_back(s/b);
            }
        }
        sort(all(upd)); upd.erase(unique(all(upd)));
        
        for (int u : upd) {
            ans -= (cnt[i][u] == 4);
        }
        for (int b : a) {
            if (s % b == 0) {
                cnt[i][s/b] += d;
            }
        }
        
        for (int u : upd) {
            ans += (cnt[i][u] == 4);
        }
    };
    
    auto g = [&](int s, int d) -> void {
        f(0, s, d);
        f(1, s, d);
    };
    
    for (int i = 0; i < N; i++) {
        int s; cin >> s;
        g(s, 1);
    }
    
    while(Q--) {
        int q, s; cin >> q >> s;
        int t = (q == 1? 1 : -1);
        g(s, t);
        cout << ans << endl;
    }
}
0