結果

問題 No.3553 Good Quartet
コンテスト
ユーザー ぽえ
提出日時 2026-05-19 21:22:25
言語 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  
実行時間 724 ms / 2,000 ms
コード長 974 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,586 ms
コンパイル使用メモリ 342,420 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2026-05-22 21:49:55
合計ジャッジ時間 10,935 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q; cin >> n >> q;
    set<long long> s;
    auto cnt = [&](long long x) -> long long {
    	long long re = 0;
    	vector<vector<int>> v = {
    		{1, 5, 7, 11},
    		{1, 11, 19, 29},
    	};
    	for (auto& i : v) {
    		for (auto& j : i) if (x%j == 0) {
    			long long y = x / j;
    			bool flag = true;
    			for (auto& k : i) if (!s.count(y*k)) flag = false;
    			if (flag) re++;
    		}
    	}
    	return re;
    };
    mint ans = 0;
    for (int i=0; i<n; i++) {
    	long long x; cin >> x;
    	s.insert(x);
    	ans += cnt(x);
    }
    while (q--) {
    	int t; long long x; cin >> t >> x;
    	if (t == 1) {
    		s.insert(x);
    		ans += cnt(x);
    	} else {
    		ans -= cnt(x);
    		s.erase(x);
    	}
    	cout << ans.val() << '\n';
    }
}
0