Submission #608963

# Submission time Handle Problem Language Result Execution time Memory
608963 2022-07-27T11:29:35 Z tamthegod Birthday gift (IZhO18_treearray) C++14
0 / 100
63 ms 125556 KB
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m, q;
vector<int> adj[maxN];
int f[maxN][21];
int lg[maxN];
int depth[maxN];
int st[4 * maxN];
int a[maxN];
set<int> s[maxN], s1[maxN];
void Log()
{
    for(int i=2; i<maxN; i++) lg[i] = lg[i / 2] + 1;
}
void predfs(int u, int par)
{
    for(int v : adj[u])
    {
        if(v == par) continue;
        f[v][0] = u;
        depth[v] = depth[u] + 1;
        for(int i=1; i<=lg[n]; i++)
            f[v][i] = f[f[v][i - 1]][i - 1];
        predfs(v, u);
    }
}
int LCA(int u, int v)
{
    if(depth[u] < depth[v]) swap(u, v);
    int k = depth[u] - depth[v];
    for(int i=lg[n]; i>=0; i--)
    {
        if(k & (1 << i))
        {
            u = f[u][i];
            k -= (1 << i);
        }
    }
    if(u == v) return u;
    for(int i=lg[n]; i>=0; i--)
    {
        if(f[u][i] != f[v][i])
        {
            u = f[u][i];
            v = f[v][i];
        }
    }
    return f[u][0];
}
void ReadInput()
{
    cin >> n >> m >> q;
    for(int i=1; i<n; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1; i<=m; i++) cin >> a[i];
}
void Solve()
{
    predfs(1, 0);
    for(int i=1; i<=m; i++)
    {
       // cout << LCA(a[i], a[i + 1]) << " ";
        s[LCA(a[i], a[i + 1])].insert(i);
        s1[a[i]].insert(i);
    }
  //  cout << q;return;
    while(q--)
    {
        int type;
        cin >> type;
        if(type == 1)
        {
            int l, r;
            cin >> l >> r;
            s1[a[l]].erase(l);
            s1[r].insert(l);
            if(l < n)
            {
                s[LCA(a[l], a[l + 1])].erase(l);
                s[LCA(r, a[l + 1])].insert(l);
            }
            if(l > 1)
            {
                s[LCA(a[l - 1], a[l])].erase(l - 1);
                s[LCA(a[l - 1], r)].insert(r);
            }
            a[l] = r;
        }
        else
        {
            int l, r, k;
            cin >> l >> r >> k;
            auto it = s1[k].lower_bound(l);
            if(it != s1[k].end() && *it <= r)
            {
                cout << *it << " " << *it << '\n';
                continue;
            }
            it = s[k].lower_bound(l);
            if(it != s[k].end() && *it < r)
            {
                cout << *it << " " << *it + 1 << '\n';
                continue;
            }
            cout << -1 << " " << -1 << '\n';
        }
    }
}
int32_t main()
{
 //   freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Log();
    ReadInput();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125512 KB n=5
2 Correct 54 ms 125556 KB n=100
3 Incorrect 63 ms 125512 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125512 KB n=5
2 Correct 54 ms 125556 KB n=100
3 Incorrect 63 ms 125512 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125512 KB n=5
2 Correct 54 ms 125556 KB n=100
3 Incorrect 63 ms 125512 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125512 KB n=5
2 Correct 54 ms 125556 KB n=100
3 Incorrect 63 ms 125512 KB Wrong range.
4 Halted 0 ms 0 KB -