1 条题解

  • 1
    @ 2024-12-24 12:34:28

    #include #include #include using namespace std;

    inline int get() { int x = 0, f = 1; char c = getchar(); while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); } while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x * f; }

    const int N = 5e5 + 5; int n; struct Edge { //实测爆栈的铁证 int v, nxt; } edge[N << 1]; long long head[N], k = 0, fa[N], f[N], ans, last[N], line[N]; char w[N]; /* inline void addedge(int u, int v) { edge[++k].v = v; edge[k].nxt = head[u]; head[u] = k; }

    inline void insedge(int u, int v) { addedge(u, v), addedge(v, u); } */ inline void file() { freopen("brackets.in", "r", stdin); freopen("brackets.out", "w", stdout); }

    int main() { file(); n = get(); scanf("%s", w + 1); for(register int i = 2; i <= n; i++) { fa[i] = get(); //insedge(fa[i], i); } for(register int u = 1; u <= n; u++) { int fath = fa[u]; f[u] = f[fath], last[u] = last[fath]; if(w[u] == '(') last[u] = u; else if(w[u] == ')' && last[u]) { line[u] = line[fa[last[u]]] + 1; last[u] = last[fa[last[u]]]; f[u] += line[u]; } ans ^= u * f[u]; } printf("%lld", ans); return 0; }

    • 1

    信息

    ID
    311
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    52
    已通过
    19
    上传者