結果

問題 No.3390 Public or Private
コンテスト
ユーザー GOTKAKO
提出日時 2025-11-29 04:58:14
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 1,378 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,205 ms
コンパイル使用メモリ 215,980 KB
実行使用メモリ 35,088 KB
最終ジャッジ日時 2025-11-29 04:58:33
合計ジャッジ時間 9,306 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<pair<int,int>> AB(M);
    vector<int> all;
    for(auto &[a,b] : AB) cin >> a >> b,all.push_back(a),all.push_back(b);
    int Q; cin >> Q;
    vector<tuple<int,int,int>> Query(Q);
    for(auto &[q,a,b] : Query) cin >> q >> a >> b,all.push_back(a),all.push_back(b);
    sort(all.begin(),all.end());
    all.erase(unique(all.begin(),all.end()),all.end());

    int n = all.size();
    vector<set<int>> Graph(n);
    for(auto [a,b] : AB){
        a = lower_bound(all.begin(),all.end(),a)-all.begin();
        b = lower_bound(all.begin(),all.end(),b)-all.begin();
        Graph.at(a).insert(b);
    }
    int ng = 0;
    set<int> NG;
    for(auto [q,a,b] : Query){
        a = lower_bound(all.begin(),all.end(),a)-all.begin();
        b = lower_bound(all.begin(),all.end(),b)-all.begin();
        if(q == 1){
            if(Graph.at(a).count(b)) Graph.at(a).erase(b);
            else Graph.at(a).insert(b);
        }
        else{
            if(NG.count(a)) NG.erase(a);
            else NG.insert(a);
        }
        
        int answer = N-1;
        for(auto p : NG){
            if(a == p) continue;
            if(Graph.at(a).count(p)){}
            else answer--;
        }
        cout << answer << "\n";
    }
}
0