結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define Yes cout << "Yes" << "\n"
#define No cout << "No" << "\n"
#define rtr0 return(0)
#define all(x) x.begin(), x.end()
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint=static_modint<998244353>;
//using mint=static_modint<1000000007>;
////using mint=modint;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using ll=long long;
using l3=__int128;
using ull=unsigned long long;
using ld=long double;
using P=pair<ll,ll>;
const ld PI=acos(-1);
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
void yn(bool f){cout<<(f?"Yes":"No")<<endl;}
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};
const int inf=1001001001;
const ll INF=1001001001001001001;

ll mod=998244353;

//1 5 7 11
//1 11 19 29

vector<ll> v1={1,5,7,11};
vector<ll> v2={1,11,19,29};

void solve(){
    ll n,q;cin>>n>>q;

    unordered_set<ll> st;
    unordered_set<ll> s1,s2;

    rep(i,n){
        ll x;cin>>x;
        st.insert(x);
        if(x%11==0)s1.insert(x);
        if(x%29==0)s2.insert(x);
    }

    unordered_set<ll> a1,a2;

    ll ans=0;
    for(auto x:s1){
        ll y=x/11;
        if(st.count(y*7)&&st.count(y*5)&&st.count(y)){
            ans++;
            a1.insert(y);
        }
    }
    for(auto x:s2){
        ll y=x/29;
        if(st.count(y*19)&&st.count(y*11)&&st.count(y)){
            ans++;
            a2.insert(y);
        }
    }

    rep(i,q){
        ll t,x;cin>>t>>x;
        if(t==1){
            st.insert(x);
            rep(i,4){
                if(x%v1[i]!=0)continue;
                ll m=x/v1[i];
                if(st.count(v1[(i+1)%4]*m)&&st.count(v1[(i+2)%4]*m)&&st.count(v1[(i+3)%4]*m)){
                    ans++;
                    a1.insert(m);
                }
            }
            rep(i,4){
                if(x%v2[i]!=0)continue;
                ll m=x/v2[i];
                if(st.count(v2[(i+1)%4]*m)&&st.count(v2[(i+2)%4]*m)&&st.count(v2[(i+3)%4]*m)){
                    ans++;
                    a2.insert(m);
                }
            }
        }
        else{
            rep(i,4){
                if(x%v1[i]!=0)continue;
                ll m=x/v1[i];
                if(st.count(v1[(i+1)%4]*m)&&st.count(v1[(i+2)%4]*m)&&st.count(v1[(i+3)%4]*m)){
                    ans--;
                    a1.erase(m);
                }
            }
            rep(i,4){
                if(x%v2[i]!=0)continue;
                ll m=x/v2[i];
                if(st.count(v2[(i+1)%4]*m)&&st.count(v2[(i+2)%4]*m)&&st.count(v2[(i+3)%4]*m)){
                    ans--;
                    a2.erase(m);
                }
            }
            st.erase(x);
        }
        cout<<ans<<endl;
    }
}


int main(){
    ll t=1;
    //cin>>t;
    rep(i,t)solve();
}
0