Submission #464665

#TimeUsernameProblemLanguageResultExecution timeMemory
464665Killer2501Synchronization (JOI13_synchronization)C++14
100 / 100
359 ms37376 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "asd" #define pll pair<ll, ll> #define pii pair<pll, ll> #define fi first #define se second using namespace std; const ll mod = 1e9+7; const ll N = 2e5+5; const int base = 313; ll n, m, t, k, T, ans, tong, a[N], b[N], c[N], h[N], P[N][20], in[N], out[N], d[N], fe[N]; vector<ll> adj[N]; vector<ll> kq; bool ok[N]; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void add(ll id, ll x) { for(; id <= n; id += id & -id)fe[id] += x; } ll get(ll id) { ll total = 0; for(; id; id -= id & -id)total += fe[id]; return total; } void dfs(ll u, ll p) { for(int i = 1; i < 20; i ++)P[u][i] = P[P[u][i-1]][i-1]; in[u] = ++k; for(ll v : adj[u]) { if(v == p)continue; P[v][0] = u; dfs(v, u); } out[u] = k; } ll findp(ll u) { ll node = u; for(int i = 19; i >= 0; i --) { if(P[u][i] && get(in[P[u][i]]) == get(in[node]))u = P[u][i]; } return u; } void sol() { cin >> n >> m >> t; for(int i = 1; i < n; i ++) { cin >> a[i] >> b[i]; adj[a[i]].pb(b[i]); adj[b[i]].pb(a[i]); } dfs(1, 0); for(int i = 1; i <= n; i ++) { add(in[i], 1); add(out[i]+1, -1); d[i] = 1; } while(m -- > 0) { ll i; cin >> i; ll u = a[i], v = b[i]; if(P[u][0] == v)swap(u, v); if(ok[i]) { d[v] = c[v] = d[findp(u)]; add(in[v], 1); add(out[v]+1, -1); } else { d[findp(u)] += d[v] - c[v]; add(in[v], -1); add(out[v]+1, 1); } //cout << d[findp(a[i])] <<" "<<d[findp(b[i])]<<'\n'; ok[i] = !ok[i]; } while(t -- > 0) { ll u; cin >> u; cout << d[findp(u)] << '\n'; } } int main() { if(fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 1 2 2 3 3 4 4 5 */

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:107:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |        freopen(task".INP", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:108:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |        freopen(task".OUT", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...