結果
| 問題 | No.3390 Public or Private |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-28 21:47:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 230 ms / 2,000 ms |
| コード長 | 1,555 bytes |
| コンパイル時間 | 2,128 ms |
| コンパイル使用メモリ | 216,356 KB |
| 実行使用メモリ | 34,976 KB |
| 最終ジャッジ日時 | 2025-11-28 21:48:13 |
| 合計ジャッジ時間 | 9,423 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int,int>> edge(m);
vector<int> c;
for(auto &&[u, v] : edge){
cin >> u >> v;
c.emplace_back(u);
c.emplace_back(v);
}
int Q;
cin >> Q;
vector<tuple<int,int,int>> query(Q);
for(auto &&[cmd, a, b] : query){
cin >> cmd >> a >> b;
c.emplace_back(a);
c.emplace_back(b);
}
// aにフォローされていて非公開のユーザーの数を数える
int cur = n;
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
m = c.size();
vector<bool> tb(m);
vector<set<int>> S(m);
for(auto &&[u, v] : edge){
u = lower_bound(c.begin(), c.end(), u) - c.begin();
v = lower_bound(c.begin(), c.end(), v) - c.begin();
S[u].insert(v);
}
for(auto &&[cmd, a, b] : query){
a = lower_bound(c.begin(), c.end(), a) - c.begin();
b = lower_bound(c.begin(), c.end(), b) - c.begin();
if(cmd == 1){
if(S[a].count(b)){
S[a].erase(b);
}else{
S[a].insert(b);
}
}else{
if(tb[a]){
tb[a] = false;
cur++;
}else{
tb[a] = true;
cur--;
}
}
int vl = cur - 1 + tb[a];
for(auto u : S[a]) vl += tb[u];
cout << vl << '\n';
}
}