QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199938#7347. HDRFDreamOn#Compile Error//C++142.9kb2023-10-04 14:43:492023-10-04 14:43:50

Judging History

你现在查看的是最新测评结果

  • [2023-10-04 14:43:50]
  • 评测
  • [2023-10-04 14:43:49]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <windows.h>
using namespace std;

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while('0' <= c && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

#define Maxn 100005
#define INF 100000000
struct TMP {int v, id;} tmp[Maxn];
int cmp(TMP fir, TMP sec) {return fir.v < sec.v;}

struct Edge {
    int next, to;
}
edge[Maxn];
int head[Maxn], edge_num, n, val[Maxn], ind[Maxn];
int cnt, dfn[Maxn], siz[Maxn];
int ans[Maxn], tot;

void add_edge(int from, int to) {
    edge[++edge_num].next = head[from];
    edge[edge_num].to = to;
    head[from] = edge_num;
}

struct SEGMENT {
    int l, r, Min;
}
tree[Maxn * 4];

#define lid id << 1
#define rid id << 1 | 1
void build(int id, int l, int r) {
    // cout << id << " " << l << " " << r << endl;
    tree[id].l = l, tree[id].r = r;
    if(l == r) {
        tree[id].Min = val[dfn[l]];
        return;
    }
    int mid = (l + r) >> 1;
    build(lid, l, mid); build(rid, mid + 1, r);
    tree[id].Min = min(tree[lid].Min, tree[rid].Min);
}
int query(int id, int l, int r) {
    // cerr << id << " " << l << " " << r << endl;
    // Sleep(500);
    if(tree[id].l == l && tree[id].r == r) return tree[id].Min;
    int mid = (tree[id].l + tree[id].r) >> 1;
    if(r <= mid) return query(lid, l, r);
    else if(mid < l) return query(rid, l, r);
    else return min(query(lid, l, mid), query(rid, mid + 1, r));
}
void cover(int id, int x) {
    if(tree[id].l == tree[id].r) {
        tree[id].Min = INF;
        return;
    }
    int mid = (tree[id].l + tree[id].r) >> 1;
    if(x <= mid) cover(lid, x);
    else cover(rid, x);
    tree[id].Min = min(tree[lid].Min, tree[rid].Min);
}

void dfs(int u) {
    dfn[u] = ++cnt;
    siz[u] = 1;
    for(int i = head[u]; i; i = edge[i].next) {
        int v = edge[i].to;
        dfs(v);
        siz[u] += siz[v];
    }
}

void solve(int u) {
    while(true) {
        if(siz[u] == 1) break;
        int tmp = query(1, dfn[u] + 1, dfn[u] + siz[u] - 1);
        if(tmp == INF) break;
        
        solve(ind[tmp]);
        // cerr << ind[tmp] << endl;
        // ans[++tot] = ind[tmp];
        // cover(1, dfn[ind[tmp]]);
    }
    ans[++tot] = u;
    cover(1, dfn[u]);
}

int main() {
    n = read();
    for(int i = 2; i <= n; ++i) {
        int p = read();
        add_edge(p, i);
    }
    for(int i = 1; i <= n; ++i) tmp[i].v = read(), tmp[i].id = i;
    sort(tmp + 1, tmp + n + 1, cmp);
    for(int i = 1; i <= n; ++i) val[tmp[i].id] = i;
    for(int i = 1; i <= n; ++i) ind[val[i]] = i;
    dfs(1);
    build(1, 1, n);
    solve(1);
    for(int i = 1; i <= tot; ++i) printf("%d ", ans[i]);
    return 0;
}

Details

answer.code:5:10: fatal error: windows.h: No such file or directory
    5 | #include <windows.h>
      |          ^~~~~~~~~~~
compilation terminated.