QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#67535 | #2008. 括号树 | alpha1022 | 100 ✓ | 106ms | 29668kb | C++23 | 941b | 2022-12-10 17:04:40 | 2022-12-10 17:04:43 |
Judging History
answer
#include <cstdio>
using namespace std;
const int N = 5e5;
int n,a[N + 5],f_[3 * N + 5],*f = f_ + N,rot;
int to[N + 5],pre[N + 5],first[N + 5];
inline void add(int u,int v)
{
static int tot = 0;
to[++tot] = v,pre[tot] = first[u],first[u] = tot;
}
long long cur,ans;
int temp[N + 5];
void dfs(int p)
{
rot += a[p];
(a[p] == 1) && (temp[p] = f[-rot],f[-rot] = 0,++f[a[p] - rot]);
ans ^= p * (cur += f[-rot]);
for(register int i = first[p];i;i = pre[i])
dfs(to[i]);
cur -= f[-rot];
(a[p] == 1) && (--f[a[p] - rot],f[-rot] = temp[p]);
rot -= a[p];
}
int main()
{
//freopen("brackets.in","r",stdin);
//freopen("brackets.out","w",stdout);
scanf("%d",&n);
char ch;
for(register int i = 1;i <= n;++i)
scanf(" %c",&ch),a[i] = ch == '(' ? 1 : -1;
int u;
for(register int i = 2;i <= n;++i)
scanf("%d",&u),add(u,i);
dfs(1);
printf("%lld\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3660kb
input:
7 (()()(( 1 2 3 4 5 6
output:
15
result:
ok "15"
Test #2:
score: 5
Accepted
time: 1ms
memory: 3696kb
input:
8 )())((() 1 2 3 4 5 6 7
output:
19
result:
ok "19"
Test #3:
score: 5
Accepted
time: 1ms
memory: 3672kb
input:
198 )))())(())())(()))(()))))()(()(()()))())(()()(()()())()()))(())(())())((()((()((()(((())((()())))))))()((()((())(()))))(()))))())(())(())((()()())()))())())(()()((())()())(())())())))))()())(())))(( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3...
output:
3273
result:
ok "3273"
Test #4:
score: 5
Accepted
time: 1ms
memory: 3692kb
input:
200 ))((())())())(())))()))())(((()()((((()((()(((((())())(()))())()))((((())((()()(())()()()())(()(((()))))())(()))()(())))(())))))(()(((()((())()((()(((())(()(()))((()((())()((()))))(()(((()))()()((())) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
output:
21364
result:
ok "21364"
Test #5:
score: 5
Accepted
time: 2ms
memory: 3820kb
input:
1949 (())))((()))(()))()()((())()(()))())((()()))(())))((())))()()(())((())(())()(()((()((((()((())()))()(()(((()((()))((()(())))))()))((((())))()))))()()())(()((()()((())))))))))()(((())((()))()((()(()()(()())))(()(()))()(()()((())(())())())())((((()))(()))((()))()()(((((((())())()))))))()(()(())((...
output:
1098479
result:
ok "1098479"
Test #6:
score: 5
Accepted
time: 1ms
memory: 3736kb
input:
1926 ())(((()()()))(()))())()))((((()(((())())())((((())()()))((())(())))))))(())))()))()(()()()))())())()((())())())()))()))())())((()((()(())()()))))(()(()()(()(((()()))(())())))))()()(()()()()())))()()()(()((()(((())())())(()))(())(()))())))((()(()((((()())((((()()((((((()))((((()))))()()()))(())...
output:
531389
result:
ok "531389"
Test #7:
score: 5
Accepted
time: 0ms
memory: 3744kb
input:
2000 ))())())()())))(()()(())))))(()((((()(()())())())))(()())))(()))()()())(())()((()()(()()))(())())))()))()(()))())))()(()((()())()))))()))())()(()(()))))(())()(())()(()())()))()()))()))()()))())()()))())(())()())))))))())))))())()))))((()(((((((((((()(()((((()()(())(()))((()))))(())))((()(((()((...
output:
63861
result:
ok "63861"
Test #8:
score: 5
Accepted
time: 1ms
memory: 3616kb
input:
1998 ()))((()((()(()))))()((())()())())((((()))((((()()((((((())())))((()))()()))(())()((()))))()(())(()()()(()()())()))())((((())))(()(()()(()))))())((()))(((()((((())(((()((((()()))())(()))))((())()()()()()(((((()()())))))((()())(((()()()())()))))())())((((((()))(((()())(()))))()))))()()()(((()))(...
output:
1416
result:
ok "1416"
Test #9:
score: 5
Accepted
time: 2ms
memory: 3708kb
input:
1999 )))(((()(()()()(()))())((()()()(()))(((()())()))))))))(()()))(((())((()))))())((()(())()(((())))))()(())()(((())((((())))(()())))()))))()((()(((((()(((()))())(()(()(()))((()()()()()(()(())((((()))())(())((((()()()((()(()()())()(((()(()))((()())((((((()(())))()()))))))((((((()((())()())())())(()...
output:
27926
result:
ok "27926"
Test #10:
score: 5
Accepted
time: 1ms
memory: 3700kb
input:
2000 ()((()()(((()(()()))()()(((()))((()))()()()(((()()(())((()(((())(()()))()))(((((())()(()()()()))()(((()(())()()())()()))))(()()()()((())()((((((()))))()))()((((()))()))))))(((((((())()))()))(())(()()(()((())))(())))))())))()))))))(()))(()(())())())((((()(((((((()((())((((()(()))((())((()()()())...
output:
10983
result:
ok "10983"
Test #11:
score: 5
Accepted
time: 4ms
memory: 11388kb
input:
99997 ()(((()()))()()(())(()))(((()(((())()((())((()))))))))()(((())((())())())())()()(()())()(((()(()))()((((())((())))))))(())((()))((()(())))()((()(()))())()()(())()()()(()()())()((()(((()))))((()())))()((()())((()(()))((()()(()))()())(()()())(()()())()((()()(())())()()(((((()()()()))))))))()()((...
output:
3818846184119
result:
ok "3818846184119"
Test #12:
score: 5
Accepted
time: 15ms
memory: 11488kb
input:
99998 (((()((((()(()))()((()))))))))(()())()()()()()()((()))(()(())()((())((((()((()())()))()((())(()))(())()))))())(()()())()(())()()()((()(((()()))()()()()))((()())))((((((()()(())(()))((())(())))())())))()(()(()))((()))()(((()()))(()((())()))())(())((())(()((((())()((())))()())))(()))((((((((()))...
output:
6201171476965
result:
ok "6201171476965"
Test #13:
score: 5
Accepted
time: 17ms
memory: 11724kb
input:
99999 ()(())()(())()()()()(()())()()(())()(()()()()(()()()()(()())(())((((()((()()))((()))())))(()(())))))()(()((()()()((())))))()((()()()()()((()))))()((()))()(())(()(()())()())()(()()()()(()))()()()()((((())(()(())()())())))((()())())()()()((())())((())()(((())())()))((()()))()(())()()(())()()((()...
output:
242124759663
result:
ok "242124759663"
Test #14:
score: 5
Accepted
time: 7ms
memory: 11724kb
input:
100000 ()(()())()()((((())((())()(((()))))()())()(()((())()))()()))(((()(((()(())))))))((()()()))()(())()()(((()()(()(()()(()))((((()))))((((()())())()))))))(()(()))()(()()()())(((((((())))))))(((((())))((())())))()(()()(((()(())(((()(())))))(()()))(())))()()(())()()()((())((()()(()))(())))(((((()((...
output:
5113850219609
result:
ok "5113850219609"
Test #15:
score: 5
Accepted
time: 13ms
memory: 8580kb
input:
99999 ((()()()(((()())(()))()((())))))(((())())()()())(()()(()))()()()()(()((()()((((())))))))()()()()()(())((()(((((((()(()))()((())()((()(())(())(()()))))))))))))(())()()(()())(())()(())()()((()()((())()((())))))((()))()()()(())(((((()())))))()()(())()((((())()())(((()))())))()(()())()()()()()()()...
output:
2085082970032
result:
ok "2085082970032"
Test #16:
score: 5
Accepted
time: 23ms
memory: 8832kb
input:
100000 ()((())(()()())(()()))(()())(())()((()()((())(()((()()(()))))((())))))()((()((()((())())((()((()))))))))()(()())(())()(())()()((((()())))(())(())(()))((())(()((((((()())(((()))))))))))(()(()())())((()()))()(())()()(()((((()))(()()(((((()((())))()())()))()(())())))))()()(()((((())))((((())))))...
output:
2112798541955
result:
ok "2112798541955"
Test #17:
score: 5
Accepted
time: 91ms
memory: 28720kb
input:
500000 (())()((()))(((())))()()()()(())()()(())()(())()(((())))(((())))(())()()()()(())((()()))(((()())))()()()((()()))()((()()))()()()()(())(()())()(()())()(())()()()()()()(())(()()())()()()(()())(((())))()()(())()()()((()))((((()))))(())(())(())()()()()()()()()()()(())()()()()(())(())(())()()()()(...
output:
487466589970316
result:
ok "487466589970316"
Test #18:
score: 5
Accepted
time: 74ms
memory: 28916kb
input:
500000 ()()()()((((()))))((()))(())(()(()))()(())(())()()(()()(()))()(()())()((()(())))(())(())()(()())()(())(())((()))()(()(()))()()()(())(())()()()()()()()()(())(()())()(((())))((()))()()()()()()()()()()()()()(())()(()())()(((())))(())()()()(())()(())(((())))()()(((())))()()(())((()))(())()()()(((...
output:
1047922056418682
result:
ok "1047922056418682"
Test #19:
score: 5
Accepted
time: 90ms
memory: 29668kb
input:
500000 ()()(())(())()()()(((())((()(()()(()))(()))((()())))))(()(()((((()))()()((()(()(())(((()(((((()))(()())()))))(()))))))())(((())())))(((()))(()()()))))(())(()())()(())(()())()()()()(((()())(())((()(((())))()((((())()())))))())())()()(((()())))(()((())))()()()(()())()(())((()))((()))()()()((()(...
output:
1616950739745800
result:
ok "1616950739745800"
Test #20:
score: 5
Accepted
time: 106ms
memory: 28760kb
input:
500000 ()((()(())))()((()())((())()())(())())((())())()((()))(())((()()()))()(()())(()(()))()(()(((((((()()()))((())))))((()())())()((()()((()((()))))())))(())))()()((()(((((()((()((())())))(()))))))))()()()()()()(()()()(()((()))))()((()))(()()()((()(())()()))(((((((()())))()()))())))()()(())((()))(...
output:
1464802790801058
result:
ok "1464802790801058"
Extra Test:
score: 0
Extra Test Passed