結果
| 問題 | No.3390 Public or Private |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2026-10-22 20:56:44 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 2,215 bytes |
| 記録 | |
| コンパイル時間 | 2,494 ms |
| コンパイル使用メモリ | 352,692 KB |
| 実行使用メモリ | 9,932 KB |
| 最終ジャッジ日時 | 2026-10-22 20:57:01 |
| 合計ジャッジ時間 | 8,730 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 5 RE * 23 |
ソースコード
#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);
rep(i, m) {
int u, v;
std::cin >> u >> v;
--u, --v;
mp0[u].insert(v);
}
int q;
std::cin >> q;
struct Query {
int t, a, b;
};
std::vector<Query> queries(q);
std::vector<int> xs;
rep(i, q) {
auto& [t, a, b] = queries[i];
std::cin >> t >> a >> b;
--a, --b;
if (t == 2) xs.push_back(a);
}
std::sort(xs.begin(), xs.end());
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
int k = xs.size();
std::vector<int> id(n, -1);
rep(i, k) id[xs[i]] = i;
std::vector<int> bit(k + 1);
auto add = [&](int i, int x) {
for (++i; i <= k; 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);
int locked = 0;
for (auto [t, a, b] : queries) {
if (t == 1) {
auto it = mp0[a].find(b);
if (it != mp0[a].end()) mp0[a].erase(it);
else mp0[a].insert(b);
}
else {
if (lock[a]) {
lock[a] = false;
--locked;
add(id[a], -1);
}
else {
lock[a] = true;
++locked;
add(id[a], 1);
}
}
int ans = n - locked;
for (int v : mp0[a]) {
if (id[v] != -1 && sum(id[v] + 1) - sum(id[v]) > 0) {
++ans;
}
}
if (!lock[a]) --ans;
std::cout << ans << '\n';
}
}
kwm_t