Submission #81843

# Submission time Handle Problem Language Result Execution time Memory
81843 2018-10-27T07:57:46 Z gs18115 None (KOI16_tree) C++14
55 / 100
458 ms 66560 KB
#include<iostream>
#include<vector>
using namespace std;
const int MAXN=2e5+10;
const int n=524288;
int in[MAXN],out[MAXN],dp[MAXN];
int ecnt;
vector<int>adj[MAXN];
void ET(const int&X,int dep)
{
    in[X]=++ecnt;
    dp[X]=dep++;
    for(const int&i:adj[X])
        ET(i,dep);
    out[X]=++ecnt;
    return;
}
inline int mn(const int&x,const int&y)
{
    return dp[x]>dp[y]?x:y;
}
int ST[n*2+10],lz[n*2+10];
int query(const int&N,const int&i,const int&x,const int&y)
{
    if(x==y)
        return mn(ST[N],lz[N]);
    int l=N<<1;
    int r=l+1;
    if(dp[ST[N]]<dp[lz[N]])
    {
        ST[N]=lz[N];
        lz[l]=mn(lz[l],lz[N]);
        lz[r]=mn(lz[r],lz[N]);
    }
    int mid=x+y>>1;
    if(i>mid)
        return query(r,i,mid+1,y);
    return query(l,i,x,mid);
}
void lazy(const int&N,const int&i,const int&j,const int&x,const int&y,const int&X)
{
    if(j<x||y<i)
        return;
    if(i<=x&&y<=j)
    {
        lz[N]=mn(X,lz[N]);
        return;
    }
    int l=N<<1;
    int r=l+1;
    if(dp[ST[N]]<dp[lz[N]])
    {
        ST[N]=lz[N];
        lz[l]=mn(lz[l],lz[N]);
        lz[r]=mn(lz[r],lz[N]);
    }
    int mid=x+y>>1;
    lazy(l,i,j,x,mid,X);
    lazy(r,i,j,mid+1,y,X);
    return;
}
inline int MC(const int&X)
{
    return query(1,in[X],0,n-1);
}
inline void cut(const int&X)
{
    lazy(1,in[X],out[X],0,n-1,X);
    return;
}
int N,Q,i;
bool flag;
int A,B,C;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>Q;
    for(i=1;i<N;i++)
    {
        cin>>A;
        adj[A-1].push_back(i);
    }
    ET(0,0);
    while(Q-->0)
    {
        cin>>A>>B>>C;
        flag=MC(--A)==MC(--B);
        cout<<(flag?"YES":"NO")<<'\n';
        if(C==1)
            cut(flag?A:B);
    }
    cout<<endl;
    return 0;
}

Compilation message

tree.cpp: In function 'int query(const int&, const int&, const int&, const int&)':
tree.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=x+y>>1;
             ~^~
tree.cpp: In function 'void lazy(const int&, const int&, const int&, const int&, const int&, const int&)':
tree.cpp:57:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=x+y>>1;
             ~^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 19 ms 5440 KB Output is correct
4 Correct 8 ms 5440 KB Output is correct
5 Correct 8 ms 5440 KB Output is correct
6 Correct 12 ms 5684 KB Output is correct
7 Correct 8 ms 5684 KB Output is correct
8 Correct 10 ms 5684 KB Output is correct
9 Correct 7 ms 5684 KB Output is correct
10 Correct 7 ms 5684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 19 ms 5440 KB Output is correct
4 Correct 8 ms 5440 KB Output is correct
5 Correct 8 ms 5440 KB Output is correct
6 Correct 12 ms 5684 KB Output is correct
7 Correct 8 ms 5684 KB Output is correct
8 Correct 10 ms 5684 KB Output is correct
9 Correct 7 ms 5684 KB Output is correct
10 Correct 7 ms 5684 KB Output is correct
11 Correct 7 ms 5684 KB Output is correct
12 Correct 8 ms 5684 KB Output is correct
13 Correct 8 ms 5684 KB Output is correct
14 Correct 7 ms 5684 KB Output is correct
15 Correct 10 ms 5684 KB Output is correct
16 Correct 8 ms 5736 KB Output is correct
17 Correct 7 ms 5752 KB Output is correct
18 Correct 10 ms 5768 KB Output is correct
19 Correct 7 ms 5784 KB Output is correct
20 Correct 8 ms 5828 KB Output is correct
21 Correct 7 ms 5828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 19 ms 5440 KB Output is correct
4 Correct 8 ms 5440 KB Output is correct
5 Correct 8 ms 5440 KB Output is correct
6 Correct 12 ms 5684 KB Output is correct
7 Correct 8 ms 5684 KB Output is correct
8 Correct 10 ms 5684 KB Output is correct
9 Correct 7 ms 5684 KB Output is correct
10 Correct 7 ms 5684 KB Output is correct
11 Correct 7 ms 5684 KB Output is correct
12 Correct 8 ms 5684 KB Output is correct
13 Correct 8 ms 5684 KB Output is correct
14 Correct 7 ms 5684 KB Output is correct
15 Correct 10 ms 5684 KB Output is correct
16 Correct 8 ms 5736 KB Output is correct
17 Correct 7 ms 5752 KB Output is correct
18 Correct 10 ms 5768 KB Output is correct
19 Correct 7 ms 5784 KB Output is correct
20 Correct 8 ms 5828 KB Output is correct
21 Correct 7 ms 5828 KB Output is correct
22 Correct 197 ms 8056 KB Output is correct
23 Correct 199 ms 8056 KB Output is correct
24 Correct 201 ms 8308 KB Output is correct
25 Correct 198 ms 8308 KB Output is correct
26 Correct 206 ms 8308 KB Output is correct
27 Correct 173 ms 8308 KB Output is correct
28 Correct 179 ms 8308 KB Output is correct
29 Correct 186 ms 8308 KB Output is correct
30 Correct 158 ms 8308 KB Output is correct
31 Correct 184 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 19 ms 5440 KB Output is correct
4 Correct 8 ms 5440 KB Output is correct
5 Correct 8 ms 5440 KB Output is correct
6 Correct 12 ms 5684 KB Output is correct
7 Correct 8 ms 5684 KB Output is correct
8 Correct 10 ms 5684 KB Output is correct
9 Correct 7 ms 5684 KB Output is correct
10 Correct 7 ms 5684 KB Output is correct
11 Correct 432 ms 30652 KB Output is correct
12 Correct 413 ms 30708 KB Output is correct
13 Correct 444 ms 30708 KB Output is correct
14 Correct 404 ms 30708 KB Output is correct
15 Correct 416 ms 35004 KB Output is correct
16 Correct 403 ms 39056 KB Output is correct
17 Correct 458 ms 44076 KB Output is correct
18 Correct 427 ms 48524 KB Output is correct
19 Correct 388 ms 53212 KB Output is correct
20 Correct 396 ms 56148 KB Output is correct
21 Correct 393 ms 61708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5240 KB Output is correct
2 Correct 7 ms 5376 KB Output is correct
3 Correct 19 ms 5440 KB Output is correct
4 Correct 8 ms 5440 KB Output is correct
5 Correct 8 ms 5440 KB Output is correct
6 Correct 12 ms 5684 KB Output is correct
7 Correct 8 ms 5684 KB Output is correct
8 Correct 10 ms 5684 KB Output is correct
9 Correct 7 ms 5684 KB Output is correct
10 Correct 7 ms 5684 KB Output is correct
11 Correct 7 ms 5684 KB Output is correct
12 Correct 8 ms 5684 KB Output is correct
13 Correct 8 ms 5684 KB Output is correct
14 Correct 7 ms 5684 KB Output is correct
15 Correct 10 ms 5684 KB Output is correct
16 Correct 8 ms 5736 KB Output is correct
17 Correct 7 ms 5752 KB Output is correct
18 Correct 10 ms 5768 KB Output is correct
19 Correct 7 ms 5784 KB Output is correct
20 Correct 8 ms 5828 KB Output is correct
21 Correct 7 ms 5828 KB Output is correct
22 Correct 197 ms 8056 KB Output is correct
23 Correct 199 ms 8056 KB Output is correct
24 Correct 201 ms 8308 KB Output is correct
25 Correct 198 ms 8308 KB Output is correct
26 Correct 206 ms 8308 KB Output is correct
27 Correct 173 ms 8308 KB Output is correct
28 Correct 179 ms 8308 KB Output is correct
29 Correct 186 ms 8308 KB Output is correct
30 Correct 158 ms 8308 KB Output is correct
31 Correct 184 ms 8308 KB Output is correct
32 Correct 432 ms 30652 KB Output is correct
33 Correct 413 ms 30708 KB Output is correct
34 Correct 444 ms 30708 KB Output is correct
35 Correct 404 ms 30708 KB Output is correct
36 Correct 416 ms 35004 KB Output is correct
37 Correct 403 ms 39056 KB Output is correct
38 Correct 458 ms 44076 KB Output is correct
39 Correct 427 ms 48524 KB Output is correct
40 Correct 388 ms 53212 KB Output is correct
41 Correct 396 ms 56148 KB Output is correct
42 Correct 393 ms 61708 KB Output is correct
43 Correct 315 ms 61708 KB Output is correct
44 Correct 344 ms 61708 KB Output is correct
45 Correct 327 ms 61708 KB Output is correct
46 Correct 306 ms 63408 KB Output is correct
47 Runtime error 308 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
48 Halted 0 ms 0 KB -