Submission #68661

# Submission time Handle Problem Language Result Execution time Memory
68661 2018-08-17T20:55:50 Z duality Synchronization (JOI13_synchronization) C++11
100 / 100
379 ms 50180 KB
#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

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 time Memory Grader output
1 Correct 4 ms 2684 KB Output is correct
2 Correct 5 ms 2796 KB Output is correct
3 Correct 4 ms 2872 KB Output is correct
4 Correct 4 ms 2872 KB Output is correct
5 Correct 4 ms 2872 KB Output is correct
6 Correct 5 ms 3008 KB Output is correct
7 Correct 21 ms 3920 KB Output is correct
8 Correct 26 ms 4240 KB Output is correct
9 Correct 23 ms 4412 KB Output is correct
10 Correct 292 ms 13628 KB Output is correct
11 Correct 278 ms 15888 KB Output is correct
12 Correct 230 ms 22728 KB Output is correct
13 Correct 233 ms 22728 KB Output is correct
14 Correct 244 ms 22728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 26192 KB Output is correct
2 Correct 152 ms 27060 KB Output is correct
3 Correct 127 ms 29316 KB Output is correct
4 Correct 126 ms 29316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29316 KB Output is correct
2 Correct 4 ms 29316 KB Output is correct
3 Correct 4 ms 29316 KB Output is correct
4 Correct 5 ms 29316 KB Output is correct
5 Correct 4 ms 29316 KB Output is correct
6 Correct 6 ms 29316 KB Output is correct
7 Correct 25 ms 29316 KB Output is correct
8 Correct 302 ms 29920 KB Output is correct
9 Correct 299 ms 29960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 355 ms 32760 KB Output is correct
2 Correct 154 ms 34996 KB Output is correct
3 Correct 161 ms 37388 KB Output is correct
4 Correct 169 ms 39648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 39648 KB Output is correct
2 Correct 5 ms 39648 KB Output is correct
3 Correct 4 ms 39648 KB Output is correct
4 Correct 6 ms 39648 KB Output is correct
5 Correct 6 ms 39648 KB Output is correct
6 Correct 31 ms 39648 KB Output is correct
7 Correct 379 ms 39648 KB Output is correct
8 Correct 339 ms 39648 KB Output is correct
9 Correct 370 ms 39648 KB Output is correct
10 Correct 298 ms 39648 KB Output is correct
11 Correct 207 ms 43072 KB Output is correct
12 Correct 190 ms 45884 KB Output is correct
13 Correct 171 ms 50180 KB Output is correct