Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <algorithm>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <string>
- #include <set>
- #include <cmath>
- #include <map>
- #include <unordered_map>
- #include <numeric>
- #include <random>
- #include <memory>
- #include <chrono>
- #include <functional>
- #include <unordered_set>
- #include <cstring>
- #include <cassert>
- #include <bitset>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #ifdef LOCAL
- #include "debug.h"
- #else
- #define debug(x...)
- #endif
- //#define int ll
- //#pragma GCC optimize("Ofast")
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef long double ld;
- typedef pair <int, int> pii;
- typedef pair <ll, ll> pll;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
- #define sz(x) int((x).size())
- #ifdef ONLINE_JUDGE
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #else
- mt19937 rng(1000 - 7);
- #endif
- const int N = 1e5 + 7;
- const int inf = INT_MAX / 2;
- const ll INF = LLONG_MAX / 3;
- const int MOD = 998244353;
- //const int MOD = 1e9 + 7;
- const ld eps = 1e-6;
- const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
- const int C = 300;
- int n, m, q, c[N], se;
- vector <int> g[N];
- unordered_map <int, int> a[N];
- pii s[C + 7];
- void rebuild(unordered_map <int, int> &b) {
- for (auto [u, color] : b) {
- for (int v : g[u]) {
- if (--a[v][c[u]] == 0) {
- a[v].erase(c[u]);
- }
- a[v][color]++;
- }
- c[u] = color;
- }
- b.clear();
- }
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(9);
- ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
- cin >> n >> m >> q;
- for (int i = 1; i <= n; i++) {
- cin >> c[i];
- }
- for (int i = 0, u, v; i < m; i++) {
- cin >> u >> v;
- g[u].push_back(v);
- g[v].push_back(u);
- }
- for (int u = 1; u <= n; u++) {
- sort(g[u].begin(), g[u].end());
- }
- for (int u = 1; u <= n; u++) {
- for (int v : g[u]) {
- a[v][c[u]]++;
- }
- }
- unordered_map <int, int> b;
- b.rehash(C);
- for (int it = 1; it <= q; it++) {
- if (sz(b) == C) {
- rebuild(b);
- }
- int type;
- cin >> type;
- if (type == 2) {
- int u;
- cin >> u;
- se = 0;
- for (auto [v, color] : b) {
- if (binary_search(g[u].begin(), g[u].end(), v)) {
- if (--a[u][c[v]] == 0) {
- a[u].erase(c[v]);
- }
- a[u][color]++;
- s[se++] = { v, color };
- }
- }
- cout << sz(a[u]) << "\n";
- for (int i = 0; i < se; i++) {
- int v = s[i].first, color = s[i].second;
- if (--a[u][color] == 0) {
- a[u].erase(color);
- }
- a[u][c[v]]++;
- }
- }
- else {
- int u, color;
- cin >> u >> color;
- b[u] = color;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement