結果

問題 No.3390 Public or Private
コンテスト
ユーザー kwm_t
提出日時 2026-10-22 20:53:14
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,519 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,524 ms
コンパイル使用メモリ 357,996 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-10-22 20:53:35
合計ジャッジ時間 8,720 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1 RE * 1
other AC * 5 RE * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

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

	int n, m;
	std::cin >> n >> m;

	std::vector<std::set<int>> mp0(n);
	std::vector<std::vector<int>> rev(n);

	rep(i, m) {
		int u, v;
		std::cin >> u >> v;
		--u, --v;
		if (mp0[u].insert(v).second) {
			rev[v].push_back(u);
		}
	}

	int q;
	std::cin >> q;

	struct Query {
		int t, a, b;
	};

	std::vector<Query> queries(q);
	rep(i, q) {
		auto& [t, a, b] = queries[i];
		std::cin >> t >> a >> b;
		--a, --b;
	}

	std::vector<int> xs;
	xs.reserve(2 * q);
	for (auto [t, a, b] : queries) {
		if (t == 2) xs.push_back(a);
	}

	std::sort(xs.begin(), xs.end());
	xs.erase(std::unique(xs.begin(), xs.end()), xs.end());

	std::vector<int> id(n, -1);
	rep(i, xs.size()) id[xs[i]] = i;

	std::vector<int> bit(xs.size() + 1);
	auto add = [&](int i, int x) {
		for (++i; i < (int)bit.size(); i += i & -i) {
			bit[i] += x;
		}
		};
	auto sum = [&](int i) {
		int res = 0;
		for (; i > 0; i -= i & -i) {
			res += bit[i];
		}
		return res;
		};

	std::vector<char> lock(n, false);
	std::vector<int> cnt(n, 0);

	for (int v : xs) {
		for (int u : rev[v]) {
			cnt[u] += lock[v];
		}
	}

	for (auto [t, a, b] : queries) {
		if (t == 1) {
			auto it = mp0[a].find(b);
			if (it != mp0[a].end()) {
				mp0[a].erase(it);
				if (lock[b]) --cnt[a];
			}
			else {
				mp0[a].insert(b);
				if (lock[b]) ++cnt[a];
			}
		}
		else {
			int d = lock[a] ? -1 : 1;
			lock[a] ^= 1;
			add(id[a], d);
			for (int u : rev[a]) {
				if (mp0[u].count(a)) cnt[u] += d;
			}
		}

		int ans = n - sum((int)xs.size()) + sum((int)xs.size());
		ans = n;
		rep(i, n) ans -= lock[i];
		ans += cnt[a];
		if (!lock[a]) --ans;

		std::cout << ans << '\n';
	}
}
0