Submission #68661

#TimeUsernameProblemLanguageResultExecution timeMemory
68661dualitySynchronization (JOI13_synchronization)C++11
100 / 100
379 ms50180 KiB
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int X[100000],Y[100000],yes[100000]; vi adjList[100000]; int parent[100000],disc[100000],fin[100000],inv[100000],num = 0; int doDFS(int u,int p) { int i; parent[u] = p; inv[num] = u,disc[u] = num++; for (i = 0; i < adjList[u].size(); i++) { int v = adjList[u][i]; if (v != p) doDFS(v,u); } fin[u] = num-1; return 0; } int tree[1 << 18]; int update(int s,int e,int ai,int i,int num) { if ((s > ai) || (e < ai)) return tree[i]; else if (s == e) { tree[i] = num; return tree[i]; } int mid = (s+e) / 2; tree[i] = max(update(s,mid,ai,2*i+1,num),update(mid+1,e,ai,2*i+2,num)); return tree[i]; } int query(int s,int e,int q,int i) { if ((s > q) || (tree[i] < q)) return -1; else if (s == e) return inv[s]; int mid = (s+e) / 2; int r = query(mid+1,e,q,2*i+2); if (r != -1) return r; else return query(s,mid,q,2*i+1); } int val[100000],last[100000]; int main() { int i; int N,M,Q,D; scanf("%d %d %d",&N,&M,&Q); for (i = 0; i < N-1; i++) { scanf("%d %d",&X[i],&Y[i]); X[i]--,Y[i]--; adjList[X[i]].pb(Y[i]); adjList[Y[i]].pb(X[i]); } doDFS(0,-1); for (i = 0; i < N; i++) update(0,N-1,disc[i],0,fin[i]),val[i] = 1; for (i = 0; i < M; i++) { scanf("%d",&D),D--; int u = X[D],v = Y[D]; if (parent[v] != u) swap(u,v); int r = query(0,N-1,disc[u],0); if (yes[D]) { val[v] = last[v] = val[r]; update(0,N-1,disc[v],0,fin[v]); } else { val[r] += val[v]-last[v]; update(0,N-1,disc[v],0,-1); } yes[D] ^= 1; } for (i = 0; i < Q; i++) { scanf("%d",&D),D--; printf("%d\n",val[query(0,N-1,disc[D],0)]); } return 0; }

Compilation message (stderr)

synchronization.cpp: In function 'int doDFS(int, int)':
synchronization.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
synchronization.cpp: In function 'int main()':
synchronization.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&N,&M,&Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&X[i],&Y[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:106:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&D),D--;
         ~~~~~~~~~~~~~~^~~~
synchronization.cpp:121:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&D),D--;
         ~~~~~~~~~~~~~~^~~~
#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...