結果

問題 No.3553 Good Quartet
コンテスト
ユーザー ぽえ
提出日時 2026-05-07 13:30:18
言語 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  
実行時間 267 ms / 2,000 ms
コード長 1,001 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,480 ms
コンパイル使用メモリ 343,428 KB
実行使用メモリ 12,836 KB
最終ジャッジ日時 2026-05-22 21:49:05
合計ジャッジ時間 9,849 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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;
    unordered_set<long long> s;
    for (int i=0; i<n; i++) { long long x; cin >> x; s.insert(x); }
    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 (auto& i : s) ans += cnt(i);
    ans /= 4;
    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