Submission #427893

# Submission time Handle Problem Language Result Execution time Memory
427893 2021-06-15T04:10:15 Z 반딧불(#7617) Corporate life (after hostile takover) (CPSPC17_corpo) C++17
30 / 100
1000 ms 69532 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct mst{
    vector<int> tree[800002];

    void addPoint(int i, int l, int r, int x, int y){
        if(l==r){
            tree[i].push_back(y);
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) addPoint(i*2, l, m, x, y);
        else addPoint(i*2+1, m+1, r, x, y);
    }

    void init(int i, int l, int r){
        if(l==r){
            sort(tree[i].begin(), tree[i].end());
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m), init(i*2+1, m+1, r);
        tree[i].resize(tree[i*2].size() + tree[i*2+1].size());
        merge(tree[i*2].begin(), tree[i*2].end(), tree[i*2+1].begin(), tree[i*2+1].end(), tree[i].begin());
    }

    int query(int i, int l, int r, int s, int e, int qs, int qe){
        if(r<s || e<l) return 0;
        if(s<=l && r<=e){
            return upper_bound(tree[i].begin(), tree[i].end(), qe) - lower_bound(tree[i].begin(), tree[i].end(), qs);
        }
        int m = (l+r)>>1;
        return query(i*2, l, m, s, e, qs, qe) + query(i*2+1, m+1, r, s, e, qs, qe);
    }
} tree;

int n;
int par1[200002], par2[200002];
vector<int> link1[200002], link2[200002];
int in1[200002], in2[200002], inCnt;
int out1[200002], out2[200002];

void dfs1(int x){
    in1[x] = ++inCnt;
    out1[x] = in1[x];
    for(auto y: link1[x]){
        dfs1(y);
        out1[x] = out1[y];
    }
}
void dfs2(int x){
    in2[x] = ++inCnt;
    out2[x] = in2[x];
    for(auto y: link2[x]){
        dfs2(y);
        out2[x] = out2[y];
    }
}

int main(){
    scanf("%d", &n);
    for(int i=2; i<=n; i++){
        scanf("%d", &par1[i]);
        link1[par1[i]].push_back(i);
    }
    for(int i=2; i<=n; i++){
        scanf("%d", &par2[i]);
        link2[par2[i]].push_back(i);
    }

    dfs1(1);
    inCnt = 0;
    dfs2(1);

    for(int i=1; i<=n; i++) tree.addPoint(1, 1, n, in1[i], in2[i]);
    tree.init(1, 1, n);
    for(int i=1; i<=n; i++){
        printf("%d ", tree.query(1, 1, n, in1[i]+1, out1[i], in2[i]+1, out2[i]));
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d", &par1[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf("%d", &par2[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28616 KB Output is correct
2 Correct 20 ms 28484 KB Output is correct
3 Correct 20 ms 28388 KB Output is correct
4 Correct 18 ms 28404 KB Output is correct
5 Correct 18 ms 28460 KB Output is correct
6 Correct 18 ms 28492 KB Output is correct
7 Correct 17 ms 28492 KB Output is correct
8 Correct 18 ms 28620 KB Output is correct
9 Correct 19 ms 28620 KB Output is correct
10 Correct 20 ms 28696 KB Output is correct
11 Correct 19 ms 28660 KB Output is correct
12 Correct 19 ms 28632 KB Output is correct
13 Correct 22 ms 28620 KB Output is correct
14 Correct 18 ms 28608 KB Output is correct
15 Correct 20 ms 28820 KB Output is correct
16 Correct 21 ms 28840 KB Output is correct
17 Correct 21 ms 28916 KB Output is correct
18 Correct 20 ms 28864 KB Output is correct
19 Correct 21 ms 28956 KB Output is correct
20 Correct 19 ms 28888 KB Output is correct
21 Correct 19 ms 28968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28616 KB Output is correct
2 Correct 20 ms 28484 KB Output is correct
3 Correct 20 ms 28388 KB Output is correct
4 Correct 18 ms 28404 KB Output is correct
5 Correct 18 ms 28460 KB Output is correct
6 Correct 18 ms 28492 KB Output is correct
7 Correct 17 ms 28492 KB Output is correct
8 Correct 18 ms 28620 KB Output is correct
9 Correct 19 ms 28620 KB Output is correct
10 Correct 20 ms 28696 KB Output is correct
11 Correct 19 ms 28660 KB Output is correct
12 Correct 19 ms 28632 KB Output is correct
13 Correct 22 ms 28620 KB Output is correct
14 Correct 18 ms 28608 KB Output is correct
15 Correct 20 ms 28820 KB Output is correct
16 Correct 21 ms 28840 KB Output is correct
17 Correct 21 ms 28916 KB Output is correct
18 Correct 20 ms 28864 KB Output is correct
19 Correct 21 ms 28956 KB Output is correct
20 Correct 19 ms 28888 KB Output is correct
21 Correct 19 ms 28968 KB Output is correct
22 Correct 344 ms 48012 KB Output is correct
23 Correct 401 ms 49728 KB Output is correct
24 Correct 588 ms 51744 KB Output is correct
25 Correct 338 ms 49028 KB Output is correct
26 Correct 315 ms 53920 KB Output is correct
27 Correct 323 ms 53828 KB Output is correct
28 Correct 319 ms 53960 KB Output is correct
29 Correct 878 ms 66572 KB Output is correct
30 Execution timed out 1069 ms 69532 KB Time limit exceeded
31 Halted 0 ms 0 KB -