답안 #133834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133834 2019-07-21T13:48:39 Z Kastanda Birthday gift (IZhO18_treearray) C++11
0 / 100
26 ms 23928 KB
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 200005, LG = 18;
int n, m, q, A[N], H[N], P[N][LG];
vector < int > Adj[N];
set < int > S[N], T[N];
void DFS(int v, int p)
{
    for (int i = 1; i < LG; i ++)
        P[v][i] = P[P[v][i - 1]][i - 1];
    for (int u : Adj[v])
        if (u != p)
        {
            H[u] = H[v] + 1;
            P[u][0] = v;
            DFS(u, v);
        }
}
inline int LCA(int v, int u)
{
    if (H[v] < H[u])
        return (LCA(u, v));
    for (int i = 0; i < LG; i ++)
        if ((H[v] - H[u]) & (1 << i))
            v = P[v][i];
    if (v == u)
        return (v);
    for (int i = LG - 1; ~ i; i --)
        if (P[v][i] != P[u][i])
            v = P[v][i], u = P[u][i];
    return (P[v][0]);
}
int main()
{
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }
    DFS(1, 0);
    for (int i = 1; i <= m; i ++)
    {
        scanf("%d", &A[i]);
        S[A[i]].insert(i);
        if (i > 1)
            T[LCA(A[i], A[i - 1])].insert(i - 1);
    }
    for (; q; q --)
    {
        int tp, l, r, v;
        scanf("%d", &tp);
        if (tp == 1)
        {
            scanf("%d%d", &l, &v);
            S[A[l]].erase(l);
            if (l > 1)
                T[LCA(A[l], A[l - 1])].erase(l - 1);
            if (l < m)
                T[LCA(A[l], A[l + 1])].erase(l);
            A[l] = v;
            S[A[l]].insert(l);
            if (l > 1)
                T[LCA(A[l], A[l - 1])].insert(l - 1);
            if (l < m)
                T[LCA(A[l], A[l + 1])].insert(l);
        }
        else
        {
            scanf("%d%d%d", &l, &r, &v);
            auto it = S[v].lower_bound(l);
            if (it != S[v].end() && (* it) <= r)
            {
                printf("%d %d\n", * it, * it);
                continue;
            }
            it = T[v].lower_bound(l);
            if (it != T[v].end() && (* it) <= r)
                printf("%d %d\n", * it, (* it) + 1);
            else
                printf("-1 -1\n");
        }
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:36: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);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
treearray.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &tp);
         ~~~~~^~~~~~~~~~~
treearray.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &l, &v);
             ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:73:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d", &l, &r, &v);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 24 ms 23800 KB n=100
4 Correct 24 ms 23800 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 24 ms 23800 KB n=100
8 Correct 23 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 26 ms 23800 KB n=100
12 Incorrect 24 ms 23800 KB Wrong output format.
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 24 ms 23800 KB n=100
4 Correct 24 ms 23800 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 24 ms 23800 KB n=100
8 Correct 23 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 26 ms 23800 KB n=100
12 Incorrect 24 ms 23800 KB Wrong output format.
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 24 ms 23800 KB n=100
4 Correct 24 ms 23800 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 24 ms 23800 KB n=100
8 Correct 23 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 26 ms 23800 KB n=100
12 Incorrect 24 ms 23800 KB Wrong output format.
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23928 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 24 ms 23800 KB n=100
4 Correct 24 ms 23800 KB n=100
5 Correct 24 ms 23800 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 24 ms 23800 KB n=100
8 Correct 23 ms 23800 KB n=100
9 Correct 23 ms 23800 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 26 ms 23800 KB n=100
12 Incorrect 24 ms 23800 KB Wrong output format.
13 Halted 0 ms 0 KB -