# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
412461 | 2021-05-27T00:13:45 Z | Malheiros | Synchronization (JOI13_synchronization) | C++17 | 561 ms | 26996 KB |
#include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; const int maxlog=20; #define ll long long struct fenwick{ ll* arr; int size; fenwick(int v){ int n=v; arr= new ll[n+1]; size=n; for (int i=0;i<=n+1;i++) arr[i]=0; } fenwick(vector<int>& v){ int n=v.size(); arr = new ll[n+1]; size=n; for (int i=0;i<n;i++){ arr[i+1]=v[i]; } build(); } void build () { for (int i=1;i<=size;i++){ int j= i + (i & (-i)); if (j<=size)arr[j]+=arr[i]; } } void update(int i,int delta){ for (;i<=size;i += i&(-i))arr[i]+=delta; } ll query(int i){ ll soma=0; for (;i;i-= i &(-i))soma+=arr[i]; return soma; } ll query(int l,int r){ if (l==1)return query(r); return query(r)-query(l-1); } }; int beg[maxn]; int en[maxn]; int ddepth[maxn]; int tempo=0; int pai[maxn]; int dp[maxn][maxlog]; vector<int>grafo[maxn]; void dfs(int u,int p,int cc=0){ ddepth[u]=cc; dp[u][0]=p; for (int i = 1; i < 20 ; i++) { dp[u][i] = dp[dp[u][i - 1]][i - 1]; } tempo++; beg[u]=tempo; for (auto k:grafo[u]) if (k!=p) dfs(k,u,cc+1); en[u]=tempo; } fenwick f(maxn); int getpar(int u){ int teste = u; for (int i = 19; i>=0; i--) { if (f.query(beg[dp[teste][i]]) == f.query(beg[u])) teste = dp[teste][i]; } return teste; } pair<int,int> edge[maxn]; vector<int> isset(maxn,false); vector<int> ans(maxn,1); vector<int> lazyness(maxn,0); void add(int t){ auto u=edge[t].first; auto v=edge[t].second; if (ddepth[u]<ddepth[v])swap(u,v); //u eh o de baixo ans[getpar(v)]+=ans[u]-lazyness[u]; f.update(beg[u],-1); f.update(en[u]+1,1); } void rem(int t){ auto u=edge[t].first; auto v=edge[t].second; if (ddepth[u]<ddepth[v])swap(u,v); //u eh o de baixo VER ISSO AQUI O ans[u]=ans[getpar(v)]; lazyness[u]=ans[getpar(v)]; f.update(beg[u],1); f.update(en[u]+1,-1); } int main(){ cin.tie(NULL);cin.sync_with_stdio(false); int n,m,q;cin>>n>>m>>q; for (int i=1;i<n;i++){ int a,b;cin>>a>>b; grafo[a].push_back(b); grafo[b].push_back(a); edge[i]={a,b}; } dfs(1,0); for (int i=1;i<=n;i++)f.update(i,1); //cout<<1<<endl; while(m--){ int a;cin>>a; if (isset[a]){ rem(a); } else{ add(a); } isset[a]=!isset[a]; } while(q--){ int a;cin>>a; cout<<ans[getpar(a)]<<endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4556 KB | Output is correct |
2 | Correct | 3 ms | 4664 KB | Output is correct |
3 | Correct | 3 ms | 4648 KB | Output is correct |
4 | Incorrect | 3 ms | 4656 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 139 ms | 22884 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4556 KB | Output is correct |
2 | Correct | 3 ms | 4660 KB | Output is correct |
3 | Correct | 4 ms | 4660 KB | Output is correct |
4 | Correct | 3 ms | 4684 KB | Output is correct |
5 | Correct | 3 ms | 4684 KB | Output is correct |
6 | Correct | 6 ms | 4884 KB | Output is correct |
7 | Correct | 44 ms | 6732 KB | Output is correct |
8 | Correct | 545 ms | 26852 KB | Output is correct |
9 | Correct | 558 ms | 26904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 561 ms | 26996 KB | Output is correct |
2 | Correct | 373 ms | 26708 KB | Output is correct |
3 | Correct | 370 ms | 26688 KB | Output is correct |
4 | Correct | 372 ms | 26772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4556 KB | Output is correct |
2 | Incorrect | 3 ms | 4556 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |