답안 #199566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199566 2020-02-02T04:09:36 Z SamAnd Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 487632 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 200005;

int n, m;
pair<int, int> b[N];
vector<int> a[N];
int d[N];

int ti, tin[N], tout[N];
void dfs(int x)
{
    tin[x] = ++ti;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        dfs(h);
    }
    tout[x] = ti;
}

int z;
int t[N * 32][2];
set<int> s[N * 32];

void ubd(int x, int y)
{
    int pos = 0;
    for (int i = 30; i >= 0; --i)
    {
        int u;
        if (!(y & (1 << i)))
            u = 0;
        else
            u = 1;
        if (!t[pos][u])
        {
            t[pos][u] = ++z;
        }
        pos = t[pos][u];
        s[pos].insert(x);
    }
}

int qry(int l, int r, int y)
{
    int pos = 0;
    int ans = 0;
    for (int i = 30; i >= 0; --i)
    {
        int u;
        if (!(y & (1 << i)))
            u = 0;
        else
            u = 1;
        if (t[pos][(u ^ 1)])
        {
            set<int>::iterator it = s[t[pos][(u ^ 1)]].lower_bound(l);
            if (it != s[t[pos][(u ^ 1)]].end() && (*it) <= r)
            {
                ans += (1 << i);
                pos = t[pos][(u ^ 1)];
            }
            else
                pos = t[pos][u];
        }
        else
        {
            pos = t[pos][u];
        }
    }
    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &m);
    n = 1;
    for (int i = 1; i <= m; ++i)
    {
        char ty[10];
        scanf(" %s", ty);
        if (ty[0] == 'A')
        {
            int x, y;
            scanf("%d%d", &x, &y);
            ++n;
            a[x].push_back(n);
            d[n] = (d[x] ^ y);
            b[i] = m_p(n, -1);
        }
        else
        {
            int x, y;
            scanf("%d%d", &x, &y);
            b[i] = m_p(x, y);
        }
    }
    dfs(1);
    ubd(tin[1], d[1]);
    for (int i = 1; i <= m; ++i)
    {
        if (b[i].second == -1)
        {
            int x = b[i].first;
            ubd(tin[x], d[x]);
        }
        else
        {
            int x = b[i].first;
            int y = b[i].second;
            printf("%d\n", qry(tin[y], tout[y], d[x]));
        }
    }
    return 0;
}

Compilation message

klasika.cpp: In function 'void dfs(int)':
klasika.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
klasika.cpp: In function 'int main()':
klasika.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
klasika.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", ty);
         ~~~~~^~~~~~~~~~~
klasika.cpp:88:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
klasika.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 305656 KB Output is correct
2 Correct 184 ms 305860 KB Output is correct
3 Correct 180 ms 305912 KB Output is correct
4 Correct 181 ms 305912 KB Output is correct
5 Correct 190 ms 305632 KB Output is correct
6 Correct 185 ms 305784 KB Output is correct
7 Correct 181 ms 305888 KB Output is correct
8 Correct 177 ms 305912 KB Output is correct
9 Correct 183 ms 305656 KB Output is correct
10 Correct 178 ms 305828 KB Output is correct
11 Correct 179 ms 305788 KB Output is correct
12 Correct 183 ms 305912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 305656 KB Output is correct
2 Correct 184 ms 305860 KB Output is correct
3 Correct 180 ms 305912 KB Output is correct
4 Correct 181 ms 305912 KB Output is correct
5 Correct 190 ms 305632 KB Output is correct
6 Correct 185 ms 305784 KB Output is correct
7 Correct 181 ms 305888 KB Output is correct
8 Correct 177 ms 305912 KB Output is correct
9 Correct 183 ms 305656 KB Output is correct
10 Correct 178 ms 305828 KB Output is correct
11 Correct 179 ms 305788 KB Output is correct
12 Correct 183 ms 305912 KB Output is correct
13 Correct 186 ms 306400 KB Output is correct
14 Correct 177 ms 307064 KB Output is correct
15 Correct 182 ms 307736 KB Output is correct
16 Correct 187 ms 308476 KB Output is correct
17 Correct 181 ms 306296 KB Output is correct
18 Correct 187 ms 307064 KB Output is correct
19 Correct 187 ms 307704 KB Output is correct
20 Correct 182 ms 308344 KB Output is correct
21 Correct 181 ms 306296 KB Output is correct
22 Correct 182 ms 307084 KB Output is correct
23 Correct 187 ms 307740 KB Output is correct
24 Correct 191 ms 308216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1124 ms 374776 KB Output is correct
2 Correct 3180 ms 443512 KB Output is correct
3 Execution timed out 5102 ms 487632 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 305656 KB Output is correct
2 Correct 184 ms 305860 KB Output is correct
3 Correct 180 ms 305912 KB Output is correct
4 Correct 181 ms 305912 KB Output is correct
5 Correct 190 ms 305632 KB Output is correct
6 Correct 185 ms 305784 KB Output is correct
7 Correct 181 ms 305888 KB Output is correct
8 Correct 177 ms 305912 KB Output is correct
9 Correct 183 ms 305656 KB Output is correct
10 Correct 178 ms 305828 KB Output is correct
11 Correct 179 ms 305788 KB Output is correct
12 Correct 183 ms 305912 KB Output is correct
13 Correct 186 ms 306400 KB Output is correct
14 Correct 177 ms 307064 KB Output is correct
15 Correct 182 ms 307736 KB Output is correct
16 Correct 187 ms 308476 KB Output is correct
17 Correct 181 ms 306296 KB Output is correct
18 Correct 187 ms 307064 KB Output is correct
19 Correct 187 ms 307704 KB Output is correct
20 Correct 182 ms 308344 KB Output is correct
21 Correct 181 ms 306296 KB Output is correct
22 Correct 182 ms 307084 KB Output is correct
23 Correct 187 ms 307740 KB Output is correct
24 Correct 191 ms 308216 KB Output is correct
25 Correct 1124 ms 374776 KB Output is correct
26 Correct 3180 ms 443512 KB Output is correct
27 Execution timed out 5102 ms 487632 KB Time limit exceeded
28 Halted 0 ms 0 KB -