Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("O3")
- #pragma GCC target ("avx2")
- #pragma GCC optimize("Ofast")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #include<bits/stdc++.h>
- #define sz(v) (int)v.size()
- #define ll long long
- #define pb push_back
- #define x first
- #define y second
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define nl "\n"
- using namespace std;
- using pii = pair<int, int>;
- const int N = (int)5e4 + 7; // make sure this is right
- const int M = (int)25e4 + 7;
- const int K = (int)450;
- const int inf = (int)1e9 + 7;
- const ll INF = (ll)3e18 + 7;
- const ll MOD = (ll)1e9 + 7; // make sure this is right
- pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
- int n, m, q, o, cnt[N], id[N];
- char t[M];
- int u[M], v[M];
- unordered_set<int> S[N];
- bitset<2 * K + 5> have[2 * K + 5];
- bool online[N], used[N];
- void solve() {
- cin >> n >> m >> q >> o;
- while(o--) {
- int x;
- cin >> x;
- online[x] = 1;
- }
- for(int i = 0; i < m; ++i) {
- int x, y;
- cin >> x >> y;
- S[x].insert(y);
- S[y].insert(x);
- }
- for(int i = 0; i < q; ++i) {
- cin >> t[i];
- if(t[i] == 'O') {
- cin >> u[i];
- } else if(t[i] == 'F') {
- cin >> u[i];
- } else if(t[i] == 'A') {
- cin >> u[i] >> v[i];
- } else if(t[i] == 'D') {
- cin >> u[i] >> v[i];
- } else {
- cin >> u[i];
- }
- }
- bitset<2 * K + 5> on;
- int sz;
- for(int I = 0; I < q; I += K) {
- on.reset();
- for(int i = 1; i <= n; ++i) {
- cnt[i] = id[i] = 0;
- used[i] = 0;
- }
- sz = 0;
- for(int i = I; i < min(q, I + K); ++i) {
- used[u[i]] = 1;
- if(t[i] == 'D' || t[i] == 'A') {
- used[v[i]] = 1;
- }
- }
- for(int i = 1; i <= n; ++i) {
- if(used[i]) {
- ++sz;
- id[i] = sz;
- on[sz] = online[i];
- }
- }
- for(int i = 1; i <= sz; ++i) {
- have[i].reset();
- }
- for(int i = 1; i <= n; ++i) {
- for(auto x : S[i]) {
- if(!used[x]) {
- if(online[x]) cnt[i]++;
- } else {
- if(used[i]) {
- have[id[i]][id[x]] = have[id[x]][id[i]] = 1;
- }
- }
- }
- }
- for(int i = I; i < min(q, I + K); ++i) {
- if(t[i] == 'O') {
- online[u[i]] = 1;
- on[id[u[i]]] = 1;
- } else if(t[i] == 'F') {
- online[u[i]] = 0;
- on[id[u[i]]] = 0;
- } else if(t[i] == 'A') {
- S[u[i]].insert(v[i]);
- S[v[i]].insert(u[i]);
- have[id[u[i]]][id[v[i]]] = have[id[v[i]]][id[u[i]]] = 1;
- } else if(t[i] == 'D') {
- S[u[i]].erase(v[i]);
- S[v[i]].erase(u[i]);
- have[id[u[i]]][id[v[i]]] = have[id[v[i]]][id[u[i]]] = 0;
- } else {
- int ans = cnt[u[i]];
- /*
- for(int j = 1; j <= sz; ++j) {
- if(online[s[j]] && have[id[u[i]]][j]) ans++;
- }
- */
- ans += (on & have[id[u[i]]]).count();
- cout << ans << nl;
- }
- }
- }
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int test = 1;
- //cin >> test;
- for(int i = 1; i <= test; ++i) {
- //cout << "Case " << i << ":\n";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement