1 条题解

  • 0
    @ 2026-9-5 21:31:58

    太轻松了吧?

    正常模拟即可。

    当然,你会用二分的对吧。

    代码

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    
    int T = 1;
    const int N = 3e5 + 10;
    int n, q, cnt;
    vector<set<int>> graph(N);
    
    void Solve() {
    	cin >> n >> q;
    	cnt = n;
    	while (q--) {
    		int op;
    		cin >> op;
    		if (op == 1) {
    			int u, v;
    			cin >> u >> v;
    			if (graph[u].size() == 0) cnt--;
    			if (graph[v].size() == 0) cnt--;
    			graph[u].insert(v);
    			graph[v].insert(u);
    		} else {
    			int u;
    			cin >> u;
    			if (graph[u].size() > 0) cnt++; 
    			for (auto v : graph[u]) {
    				auto del = graph[v].lower_bound(u);
    				graph[v].erase(del);
    				if (graph[v].size() == 0) cnt++;
    			}
    			graph[u].clear();
    		}
    		cout << cnt << '\n';
    	}
    }
    
    signed main() {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	
    	while (T--) {
    		Solve();
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    2937
    时间
    2000ms
    内存
    1024MiB
    难度
    提高
    标签
    递交数
    2
    已通过
    1
    上传者