Submission #427918

# Submission time Handle Problem Language Result Execution time Memory
427918 2021-06-15T05:06:36 Z 장태환(#7562) Corporate life (after hostile takover) (CPSPC17_corpo) C++17
100 / 100
362 ms 47932 KB
#include <bits/stdc++.h>
using namespace std;
vector<int>link[2][200100];
int s[2][200100];
int e[2][200100];
int c;
vector<pair<pair<int,int>,pair<int,int>>>q;
int pr[200100];
int ans[200100];
int fwtree[200100];
int N;
void upd(int n,int k)
{
    while(n<=N)
    {
        fwtree[n]+=k;
        n+=n&(-n);
    }
}
int get(int n)
{
    int ans=0;
    while(n)
    {
        ans+=fwtree[n];
        n-=n&(-n);
    }
    return ans;
}
void dfs(int ind,int n)
{
    s[ind][n]=++c;
    int i;
    for(i=0;i<link[ind][n].size();i++)
    {
        dfs(ind,link[ind][n][i]);
    }
    e[ind][n]=c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    int i;
    for(i=1;i<N;i++)
    {
        int a;
        cin >> a;
        link[0][a].push_back(i+1);
    }
    for(i=1;i<N;i++)
    {
        int a;
        cin >> a;
        link[1][a].push_back(i+1);
    }
    dfs(0,1);
    c=0;
    dfs(1,1);
    for(i=1;i<=N;i++)
    {
        pr[s[0][i]]=s[1][i];
    }
    for(i=1;i<=N;i++)
    {
        q.push_back({{e[0][i],i},{s[1][i]-1,e[1][i]}});
        q.push_back({{s[0][i]-1,-i},{s[1][i]-1,e[1][i]}});
    }
    sort(q.begin(),q.end());
    int j=0;
    for(i=1;i<=N;i++)
    {
        while(j<q.size()&&q[j].first.first<i)
        {
            int nod=abs(q[j].first.second);
            int re=q[j].first.second/nod;
            ans[nod]+=re*(-get(q[j].second.first)+get(q[j].second.second));
            j++;
        }
        upd(pr[i],1);
    }
    while(j<q.size()&&q[j].first.first<i)
    {
        int nod=abs(q[j].first.second);
        int re=q[j].first.second/nod;
        ans[nod]+=re*(-get(q[j].second.first)+get(q[j].second.second));
        j++;
    }
    for(i=1;i<=N;i++)
        cout << ans[i]-1<<'\n';
}

Compilation message

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:34:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(i=0;i<link[ind][n].size();i++)
      |             ~^~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:74:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         while(j<q.size()&&q[j].first.first<i)
      |               ~^~~~~~~~~
Main.cpp:83:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     while(j<q.size()&&q[j].first.first<i)
      |           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 8 ms 9676 KB Output is correct
3 Correct 8 ms 9760 KB Output is correct
4 Correct 7 ms 9720 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
6 Correct 7 ms 9676 KB Output is correct
7 Correct 9 ms 9716 KB Output is correct
8 Correct 9 ms 9804 KB Output is correct
9 Correct 8 ms 9804 KB Output is correct
10 Correct 7 ms 9932 KB Output is correct
11 Correct 7 ms 9904 KB Output is correct
12 Correct 8 ms 9932 KB Output is correct
13 Correct 8 ms 9892 KB Output is correct
14 Correct 7 ms 9968 KB Output is correct
15 Correct 9 ms 9932 KB Output is correct
16 Correct 9 ms 10060 KB Output is correct
17 Correct 11 ms 10060 KB Output is correct
18 Correct 10 ms 9944 KB Output is correct
19 Correct 9 ms 10060 KB Output is correct
20 Correct 10 ms 10188 KB Output is correct
21 Correct 8 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 8 ms 9676 KB Output is correct
3 Correct 8 ms 9760 KB Output is correct
4 Correct 7 ms 9720 KB Output is correct
5 Correct 7 ms 9676 KB Output is correct
6 Correct 7 ms 9676 KB Output is correct
7 Correct 9 ms 9716 KB Output is correct
8 Correct 9 ms 9804 KB Output is correct
9 Correct 8 ms 9804 KB Output is correct
10 Correct 7 ms 9932 KB Output is correct
11 Correct 7 ms 9904 KB Output is correct
12 Correct 8 ms 9932 KB Output is correct
13 Correct 8 ms 9892 KB Output is correct
14 Correct 7 ms 9968 KB Output is correct
15 Correct 9 ms 9932 KB Output is correct
16 Correct 9 ms 10060 KB Output is correct
17 Correct 11 ms 10060 KB Output is correct
18 Correct 10 ms 9944 KB Output is correct
19 Correct 9 ms 10060 KB Output is correct
20 Correct 10 ms 10188 KB Output is correct
21 Correct 8 ms 10060 KB Output is correct
22 Correct 120 ms 22128 KB Output is correct
23 Correct 163 ms 24004 KB Output is correct
24 Correct 153 ms 26280 KB Output is correct
25 Correct 118 ms 22264 KB Output is correct
26 Correct 129 ms 28840 KB Output is correct
27 Correct 171 ms 28840 KB Output is correct
28 Correct 126 ms 28912 KB Output is correct
29 Correct 278 ms 33396 KB Output is correct
30 Correct 338 ms 36984 KB Output is correct
31 Correct 318 ms 41092 KB Output is correct
32 Correct 290 ms 33620 KB Output is correct
33 Correct 301 ms 46020 KB Output is correct
34 Correct 296 ms 45928 KB Output is correct
35 Correct 301 ms 45952 KB Output is correct
36 Correct 309 ms 34344 KB Output is correct
37 Correct 304 ms 38388 KB Output is correct
38 Correct 324 ms 42708 KB Output is correct
39 Correct 305 ms 34684 KB Output is correct
40 Correct 362 ms 47932 KB Output is correct
41 Correct 339 ms 47900 KB Output is correct
42 Correct 321 ms 47812 KB Output is correct