Submission #1104154

# Submission time Handle Problem Language Result Execution time Memory
1104154 2024-10-23T03:39:21 Z InvMOD Synchronization (JOI13_synchronization) C++14
0 / 100
225 ms 50516 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
const int lg = 21;

int n, m, q, timerDFS, tin[N], tout[N], h[N], par[lg][N], bit[N], info[N], last_sync[N];
pair<int,int> E[N];
bool on[N];

vector<int> adj[N];

void update(int p, int val){
    for(; p <= timerDFS; p += (p & (-p))) bit[p] += val;
}

int get(int p){
    int res = 0;
    for(; p; p -= (p & (-p))) res += bit[p];
    return res;
}

void dfs(int x, int p){
    tin[x] = ++timerDFS;
    info[x] = 1;

    for(int v : adj[x])if(v != p){

        h[v] = h[x] + 1;
        par[0][v] = x;
        for(int i = 1; i < lg; i++) par[i][v] = par[i-1][par[i-1][v]];

        dfs(v, x);
    }

    tout[x] = ++timerDFS;
    return;
}

int get_par(int x){
    int cur_node = x, state = get(tin[x]);

    for(int i = lg-1; i >= 0; i--){
        if(par[i][cur_node] && get(tin[par[i][cur_node]]) == state) cur_node = par[i][cur_node];
    }

    return cur_node;
}

void solve()
{
    cin >> n >> m >> q;
    for(int i = 1; i < n; i++){
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        E[i] = make_pair(u, v);
    }

    dfs(1, -1);

    for(int i = 1; i <= n; i++){
        update(tin[i], -1);
        update(tout[i], 1);
    }

    while(m--){
        int d; cin >> d;
        int u = E[d].first, v = E[d].second;

        if(h[u] > h[v]) swap(u, v);


        int asc = get_par(u);

        if(!on[d]){
            info[asc] = info[asc] + (info[v] - last_sync[v]);
            //cout << asc << " " << info[asc] <<"\n";
            update(tin[v], 1);
            update(tout[v], -1);
        }
        else{
            info[v] = info[asc];
            last_sync[v] = info[asc];
            update(tin[v], -1);
            update(tout[v], 1);
        }

        on[d] = on[d] ^ 1;
    }

    while(q--){
        int u; cin >> u;
        cout << info[get_par(u)] <<"\n";
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    solve();
    return 0;
}

Compilation message

synchronization.cpp: In function 'int32_t main()':
synchronization.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 2 ms 12880 KB Output is correct
4 Correct 2 ms 12880 KB Output is correct
5 Correct 2 ms 12880 KB Output is correct
6 Correct 3 ms 12880 KB Output is correct
7 Correct 12 ms 13484 KB Output is correct
8 Correct 10 ms 13392 KB Output is correct
9 Correct 12 ms 13392 KB Output is correct
10 Incorrect 111 ms 19784 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 22616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 3 ms 12880 KB Output is correct
4 Correct 2 ms 12880 KB Output is correct
5 Correct 2 ms 12880 KB Output is correct
6 Correct 3 ms 12880 KB Output is correct
7 Correct 18 ms 14160 KB Output is correct
8 Runtime error 64 ms 48968 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 225 ms 50516 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 2 ms 12880 KB Output is correct
4 Correct 2 ms 12880 KB Output is correct
5 Correct 3 ms 12880 KB Output is correct
6 Correct 12 ms 13816 KB Output is correct
7 Incorrect 123 ms 20520 KB Output isn't correct
8 Halted 0 ms 0 KB -