Advertisement
aayyk

Untitled

Jul 18th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <functional>
  19. #include <unordered_set>
  20. #include <cstring>
  21. #include <cassert>
  22. #include <bitset>
  23. #include <ext/pb_ds/assoc_container.hpp>
  24. #include <ext/pb_ds/tree_policy.hpp>
  25. #ifdef LOCAL
  26. #include "debug.h"
  27. #else
  28. #define debug(x...)
  29. #endif
  30.  
  31. //#define int ll
  32. //#pragma GCC optimize("Ofast")
  33.  
  34.  
  35. using namespace std;
  36. using namespace __gnu_pbds;
  37. typedef long long ll;
  38. typedef long double ld;
  39. typedef pair <int, int> pii;
  40. typedef pair <ll, ll> pll;
  41. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  42. typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
  43. #define sz(x) int((x).size())
  44.  
  45. #ifdef ONLINE_JUDGE
  46. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  47. #else
  48. mt19937 rng(1000 - 7);
  49. #endif
  50.  
  51. const int N = 1e5 + 7;
  52. const int inf = INT_MAX / 2;
  53. const ll INF = LLONG_MAX / 3;
  54. const int MOD = 998244353;
  55. //const int MOD = 1e9 + 7;
  56. const ld eps = 1e-6;
  57. const pii dir[] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
  58.  
  59. const int C = 300;
  60.  
  61. int n, m, q, c[N], se;
  62. vector <int> g[N];
  63. unordered_map <int, int> a[N];
  64. pii s[C + 7];
  65.  
  66. void rebuild(unordered_map <int, int> &b) {
  67.     for (auto [u, color] : b) {
  68.         for (int v : g[u]) {
  69.             if (--a[v][c[u]] == 0) {
  70.                 a[v].erase(c[u]);
  71.             }
  72.             a[v][color]++;
  73.         }
  74.         c[u] = color;
  75.     }
  76.  
  77.     b.clear();
  78. }
  79.  
  80. signed main() {
  81. #ifdef LOCAL
  82.     freopen("input.txt", "r", stdin);
  83.     freopen("output.txt", "w", stdout);
  84. #endif
  85.     cout << fixed << setprecision(9);
  86.     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  87.  
  88.     cin >> n >> m >> q;
  89.  
  90.     for (int i = 1; i <= n; i++) {
  91.         cin >> c[i];
  92.     }
  93.  
  94.     for (int i = 0, u, v; i < m; i++) {
  95.         cin >> u >> v;
  96.  
  97.         g[u].push_back(v);
  98.         g[v].push_back(u);
  99.     }
  100.  
  101.     for (int u = 1; u <= n; u++) {
  102.         sort(g[u].begin(), g[u].end());
  103.     }
  104.  
  105.     for (int u = 1; u <= n; u++) {
  106.         for (int v : g[u]) {
  107.             a[v][c[u]]++;
  108.         }
  109.     }
  110.  
  111.     unordered_map <int, int> b;
  112.     b.rehash(C);
  113.  
  114.     for (int it = 1; it <= q; it++) {
  115.         if (sz(b) == C) {
  116.             rebuild(b);
  117.         }
  118.  
  119.         int type;
  120.         cin >> type;
  121.  
  122.         if (type == 2) {
  123.             int u;
  124.             cin >> u;
  125.  
  126.             se = 0;
  127.             for (auto [v, color] : b) {
  128.                 if (binary_search(g[u].begin(), g[u].end(), v)) {
  129.                     if (--a[u][c[v]] == 0) {
  130.                         a[u].erase(c[v]);
  131.                     }
  132.                     a[u][color]++;
  133.                     s[se++] = { v, color };
  134.                 }
  135.             }
  136.  
  137.             cout << sz(a[u]) << "\n";
  138.  
  139.             for (int i = 0; i < se; i++) {
  140.                 int v = s[i].first, color = s[i].second;
  141.                 if (--a[u][color] == 0) {
  142.                     a[u].erase(color);
  143.                 }
  144.                 a[u][c[v]]++;
  145.             }
  146.         }
  147.         else {
  148.             int u, color;
  149.             cin >> u >> color;
  150.  
  151.             b[u] = color;
  152.         }
  153.     }
  154.  
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement