QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#490197 | #6159. 信号传递 | kymmykym# | 0 | 80ms | 88980kb | C++17 | 1.8kb | 2024-07-25 12:42:33 | 2024-07-25 12:42:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn=525015;
int A[maxn],par[maxn];
vector<int>child[maxn];
const int LG = 22;
const int SLG=11;
int pre[LG][maxn];
int B[LG][1<<SLG+5];
int out;
int sum[LG];
typedef pair<int,int>pi;
vector<pi>update[maxn];
int32_t main(){
cin >> n;
for(int i=1;i<=n;i++)cin>>A[i];
for(int i=2;i<=n;i++){
cin>>par[i];
child[par[i]].push_back(i);
}
for(int i=n;i>=1;i--){
for(int bit = SLG; bit<LG;bit++){ // just jump
int curt = A[i] % (1<<(bit+1));
if(curt>=1<<bit){
pre[bit][i]++;
} else{
pre[bit][i - ((1<<bit)-curt)]++;
}
int idx=i-((1<<(bit+1)) - curt);
if(idx >= 1)pre[bit][idx]--;
while(idx >= 1){
if(idx-(1<<bit) >= 1)pre[bit][idx-(1<<bit)]++;
if(idx - (1<<(bit+1)) >= 1)pre[bit][idx-(1<<(bit+1))]--;
idx-=1<<(bit+1);
}
}
for(int bit=0;bit<SLG;bit++){
int T = (1<<(bit+1));
int curt = A[i] % T;
if(curt>=1<<bit){
pre[bit][i]++;
} else{
if(i - ((1<<bit)-curt) >= 1)pre[bit][i - ((1<<bit)-curt)]++;
}
int ti = 0;
int idx=i-((1<<(bit+1)) - curt);
if(idx>=1)update[idx].push_back({bit,idx%T});
}
for(auto x:update[i]){
B[x.first][x.second]++;
}
for(int bit=0;bit<LG;bit++){
pre[bit][i]+=pre[bit][i+1];
}
int ans=0;
for(int bit = 0; bit<LG;bit++){
int T = (1<<(bit+1));
if(bit<SLG){
int diff=0;
diff -= B[bit][i%T];
if(i%T >= T/2)diff += B[bit][i%T - T/2];
else diff += B[bit][i%T + T/2];
pre[bit][i] += diff;
} else{
}
}
for(int bit=0;bit<LG;bit++){
int on = pre[bit][i] % 2;
if(on){
ans += 1<<bit;
}
}
out +=ans;
//cerr<<i<<":"<<ans<<endl;
}
cout<<out;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 62548kb
input:
62 4 6 1 3 3 1 2 3 2 3 4 3 3 3 4 3 2 1 1 4 3 3 1 1 1 4 1 2 4 2 4 4 1 1 2 2 3 4 2 3 4 4 1 1 4 4 2 1 4 2 2 4 3 3 2 2 1 2 3 1 2 1 1 1
output:
1423
result:
wrong answer 1st numbers differ - expected: '619', found: '1423'
Test #2:
score: 0
Wrong Answer
time: 7ms
memory: 63860kb
input:
87 4 2 1 4 2 3 4 4 2 2 1 4 2 3 3 3 1 3 1 4 2 2 2 4 4 4 4 3 1 1 2 3 2 4 2 3 4 3 3 3 3 2 4 3 2 1 1 1 3 2 3 3 4 4 3 1 3 4 1 3 2 2 3 2 2 4 3 4 1 1 4 1 1 1 2 2 3 2 3 1 4 2 2 3 2 4 2 1 2
output:
3200
result:
wrong answer 1st numbers differ - expected: '334', found: '3200'
Test #3:
score: 0
Wrong Answer
time: 7ms
memory: 64912kb
input:
95 7 5 3 5 7 3 2 5 6 1 1 4 2 2 5 4 6 3 5 7 1 1 3 3 6 7 3 1 2 2 4 6 3 6 7 1 5 3 3 4 7 1 1 4 1 3 7 5 6 4 7 4 7 4 2 6 4 5 2 2 6 1 4 6 5 2 6 2 7 1 1 4 3 2 6 6 6 5 6 7 3 2 3 1 1 5 3 2 5 7 1 5 1 4 6 4 2
output:
3778
result:
wrong answer 1st numbers differ - expected: '1363', found: '3778'
Test #4:
score: 0
Wrong Answer
time: 3ms
memory: 62008kb
input:
54 5 3 5 4 4 4 4 3 5 2 2 1 2 2 3 5 3 2 1 4 3 1 5 2 5 1 4 1 5 1 1 1 5 5 4 5 2 1 2 5 2 4 1 1 1 3 2 4 1 1 5 2 5 2 5 5
output:
1262
result:
wrong answer 1st numbers differ - expected: '322', found: '1262'
Test #5:
score: 0
Wrong Answer
time: 3ms
memory: 62804kb
input:
55 4 1 3 2 3 1 4 1 3 3 2 3 1 4 4 3 3 4 4 3 3 3 4 4 1 1 1 1 4 3 2 1 2 1 2 3 1 2 1 4 4 3 4 3 1 3 3 4 4 2 3 3 3 1 4 2 3
output:
1170
result:
wrong answer 1st numbers differ - expected: '114', found: '1170'
Test #6:
score: 0
Wrong Answer
time: 7ms
memory: 64344kb
input:
88 7 4 5 1 7 2 3 7 3 5 7 2 7 1 1 7 6 3 3 1 3 7 5 1 3 5 6 4 2 4 2 2 6 7 7 3 6 3 3 5 1 6 3 2 7 1 4 4 7 4 1 1 3 1 4 1 5 5 1 3 4 5 4 5 1 7 5 1 1 3 4 6 6 5 2 3 2 6 1 2 3 6 2 6 3 3 7 1 4 1
output:
3175
result:
wrong answer 1st numbers differ - expected: '1072', found: '3175'
Test #7:
score: 0
Wrong Answer
time: 69ms
memory: 88980kb
input:
97864 20 22 10 16 2 14 10 5 8 18 20 7 4 10 20 5 11 6 18 7 20 7 10 3 11 7 1 9 5 3 11 18 15 15 9 8 16 17 20 18 4 18 6 13 2 13 20 4 20 1 18 20 6 17 19 3 4 10 8 14 20 10 3 4 7 10 18 4 2 9 14 14 12 18 17 19 15 10 3 7 20 3 20 6 11 12 9 9 18 18 9 2 9 2 6 10 1 9 20 2 5 8 1 20 10 3 2 19 14 12 4 14 19 12 19 1...
output:
-737556131
result:
wrong answer 1st numbers differ - expected: '21467158', found: '-737556131'
Test #8:
score: 0
Wrong Answer
time: 75ms
memory: 86320kb
input:
99240 20 81 4 14 5 13 16 11 8 19 12 5 8 6 2 15 2 17 1 16 11 2 1 10 3 13 5 7 12 15 17 14 6 17 14 16 9 3 14 3 13 2 12 10 13 10 12 11 8 12 11 10 7 19 10 18 11 19 15 13 14 3 15 19 4 7 5 15 8 10 8 5 10 14 17 3 19 16 11 19 11 9 7 1 14 1 5 17 19 7 8 11 5 9 6 5 6 10 7 8 13 13 16 7 10 15 1 8 17 4 4 9 19 18 1...
output:
-678729590
result:
wrong answer 1st numbers differ - expected: '79146075', found: '-678729590'
Test #9:
score: 0
Wrong Answer
time: 64ms
memory: 84548kb
input:
90117 20 72 14 14 6 10 9 5 8 9 7 6 18 2 3 19 9 12 7 19 20 13 7 4 3 4 7 9 19 8 11 12 16 12 3 8 19 1 20 4 9 19 6 20 8 8 2 8 20 17 13 6 1 10 9 7 3 12 20 5 1 13 7 18 14 7 5 17 14 17 12 5 5 3 3 11 9 16 5 5 12 5 4 15 2 7 6 1 12 13 8 12 7 19 15 2 1 11 20 16 17 18 18 2 10 4 7 18 8 19 7 4 3 9 8 2 13 6 3 14 4...
output:
-1251327812
result:
wrong answer 1st numbers differ - expected: '63791487', found: '-1251327812'
Test #10:
score: 0
Wrong Answer
time: 69ms
memory: 86644kb
input:
93274 20 81 19 19 6 13 17 4 10 18 5 19 4 7 4 1 10 20 1 19 2 10 12 9 3 13 9 15 13 14 8 14 2 6 20 2 9 7 11 4 10 17 6 1 10 12 1 19 13 20 5 4 13 4 8 13 17 15 13 17 13 4 20 2 20 18 4 3 7 12 11 15 8 20 14 4 19 1 11 19 19 9 15 16 9 5 7 9 4 2 20 16 9 16 13 12 13 11 6 7 18 19 11 1 19 4 7 16 14 12 17 9 5 17 1...
output:
-1046324165
result:
wrong answer 1st numbers differ - expected: '74419960', found: '-1046324165'
Test #11:
score: 0
Wrong Answer
time: 80ms
memory: 88884kb
input:
96831 20 93 12 19 17 6 7 20 3 14 5 13 19 12 15 7 14 9 7 15 20 10 10 18 12 12 2 19 12 15 7 8 9 15 20 8 11 3 4 9 4 7 10 5 17 1 13 13 10 6 16 20 3 18 5 17 3 13 13 8 20 15 8 10 18 3 9 11 13 3 19 12 13 11 13 13 17 3 15 20 8 13 2 14 10 16 14 2 5 14 14 8 17 12 4 4 14 7 18 7 6 17 16 13 7 2 2 4 14 16 17 3 4 ...
output:
-792555103
result:
wrong answer 1st numbers differ - expected: '88602279', found: '-792555103'
Test #12:
score: 0
Wrong Answer
time: 67ms
memory: 86440kb
input:
96251 20 38 18 15 8 5 10 17 16 8 5 12 15 19 16 7 18 4 8 12 3 13 3 1 13 14 19 16 11 17 3 11 14 12 12 9 15 3 9 20 16 15 13 1 1 2 12 17 11 20 5 19 20 5 20 13 18 20 12 16 8 7 10 6 5 4 15 3 8 19 18 15 19 13 5 13 12 4 17 16 5 8 16 13 15 10 20 6 17 4 1 9 2 16 3 20 8 16 11 3 3 4 6 10 17 13 12 5 3 15 3 6 4 1...
output:
-830215184
result:
wrong answer 1st numbers differ - expected: '36201870', found: '-830215184'
Test #13:
score: 0
Wrong Answer
time: 72ms
memory: 85044kb
input:
92874 21 99 15 10 19 18 6 9 7 11 14 13 6 4 6 10 11 6 13 17 14 1 18 17 14 2 16 20 11 6 16 13 11 4 1 17 4 3 6 7 4 1 7 9 9 6 3 11 21 2 21 17 12 1 1 19 19 19 10 21 10 10 11 6 21 20 19 15 17 5 18 15 20 17 5 21 5 12 16 8 18 6 16 16 4 12 14 7 7 12 8 9 20 15 3 13 1 10 6 19 11 17 3 9 16 5 3 16 5 21 8 7 8 12 ...
output:
-1056012736
result:
wrong answer 1st numbers differ - expected: '95046580', found: '-1056012736'
Test #14:
score: 0
Wrong Answer
time: 59ms
memory: 88376kb
input:
93171 21 46 9 5 2 18 18 15 6 8 6 14 10 11 11 9 14 12 17 1 1 19 3 20 9 1 7 7 4 15 11 12 3 2 7 14 12 18 5 3 16 14 9 9 19 14 21 20 6 17 14 9 18 4 7 8 3 20 4 9 1 12 6 18 9 17 10 3 3 2 18 2 4 6 18 19 14 4 12 3 8 1 1 14 11 21 10 6 15 18 20 2 13 18 7 10 9 18 16 17 16 15 4 13 18 2 3 11 21 10 8 6 10 6 5 4 8 ...
output:
-1052947034
result:
wrong answer 1st numbers differ - expected: '44433601', found: '-1052947034'
Test #15:
score: 0
Wrong Answer
time: 73ms
memory: 85204kb
input:
95808 22 25 15 13 17 3 18 1 9 2 19 21 17 16 15 8 12 6 21 7 13 21 8 14 15 19 15 9 8 4 2 9 14 3 14 5 21 9 16 7 18 6 13 15 18 9 17 9 5 6 19 17 7 4 17 2 18 14 19 12 17 5 11 8 6 20 22 4 6 15 10 11 13 8 21 9 4 13 5 17 14 14 22 19 12 19 19 11 18 11 20 8 4 6 18 12 18 20 14 14 1 17 10 8 3 6 20 5 2 4 3 17 12 ...
output:
-869574991
result:
wrong answer 1st numbers differ - expected: '26221403', found: '-869574991'
Test #16:
score: 0
Wrong Answer
time: 64ms
memory: 86204kb
input:
97413 22 86 13 20 15 16 16 3 6 19 8 20 18 10 5 3 12 3 2 10 9 12 18 20 13 15 11 5 7 12 21 6 14 3 21 1 10 8 19 20 7 22 13 10 6 9 16 22 16 21 14 11 21 18 17 12 7 17 13 13 2 6 5 6 15 3 9 18 10 11 22 4 14 12 21 20 13 8 19 6 20 8 6 5 4 12 13 11 11 11 2 18 18 16 18 16 13 11 8 16 5 3 18 6 1 11 9 13 22 7 17 ...
output:
-786679909
result:
wrong answer 1st numbers differ - expected: '90534724', found: '-786679909'
Test #17:
score: 0
Wrong Answer
time: 67ms
memory: 86404kb
input:
100000 23 29 1 11 20 18 16 13 10 18 21 15 20 19 6 12 6 21 22 2 17 19 20 15 15 19 13 7 1 7 6 3 17 7 2 21 8 11 8 6 8 6 22 20 23 2 2 11 11 14 23 19 1 6 2 2 10 13 10 15 16 19 16 19 15 11 14 1 14 21 4 13 2 15 6 21 18 6 6 5 18 15 18 4 12 22 16 12 23 18 9 18 20 19 3 20 23 15 20 9 8 23 12 17 1 10 22 23 15 6...
output:
-608604564
result:
wrong answer 1st numbers differ - expected: '33082914', found: '-608604564'
Test #18:
score: 0
Wrong Answer
time: 71ms
memory: 86696kb
input:
100000 23 72 7 9 3 23 1 7 18 22 12 4 9 8 10 21 1 2 5 3 9 23 4 23 20 23 17 21 3 17 11 15 19 6 14 8 17 5 20 17 8 9 6 20 3 21 12 17 23 17 4 15 20 21 13 19 20 9 22 23 8 1 7 19 23 21 20 14 21 8 4 9 11 19 7 6 8 2 6 18 15 19 18 16 8 12 9 4 7 23 17 19 19 11 17 13 14 1 12 9 3 10 11 22 9 20 8 12 2 21 3 10 18 ...
output:
-609131584
result:
wrong answer 1st numbers differ - expected: '81511916', found: '-609131584'
Test #19:
score: 0
Wrong Answer
time: 71ms
memory: 86712kb
input:
100000 23 81 6 20 5 18 20 5 22 7 10 1 22 5 9 1 1 8 22 18 13 5 16 19 10 19 21 10 14 17 6 8 12 22 2 14 6 2 7 8 8 9 20 22 1 23 5 12 12 3 6 7 16 5 17 10 8 12 1 12 18 4 17 3 12 1 7 23 1 23 23 12 15 3 10 4 10 1 2 17 6 10 1 10 6 1 7 18 16 22 12 22 9 19 6 18 7 20 10 16 2 20 1 21 7 6 13 6 15 8 15 14 8 5 23 1...
output:
-594083424
result:
wrong answer 1st numbers differ - expected: '91713895', found: '-594083424'
Test #20:
score: 0
Wrong Answer
time: 75ms
memory: 87752kb
input:
100000 23 89 13 19 14 9 22 13 22 13 16 20 5 20 13 12 4 17 9 6 8 12 22 2 15 13 23 10 7 21 7 18 14 17 7 12 1 8 11 1 19 7 20 3 18 19 22 20 23 3 6 8 9 16 22 9 14 13 11 11 14 6 23 1 23 16 10 7 11 17 18 14 2 15 9 22 3 17 8 21 7 5 10 1 12 3 21 23 15 20 14 1 16 18 14 12 17 14 2 11 13 4 6 7 21 23 9 15 17 2 3...
output:
-598535382
result:
wrong answer 1st numbers differ - expected: '100478015', found: '-598535382'