QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490199#6160. 树kymmykym#0 1014ms167848kbC++171.8kb2024-07-25 12:43:122024-07-25 12:43:13

Judging History

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

  • [2024-07-25 12:43:13]
  • 评测
  • 测评结果:0
  • 用时:1014ms
  • 内存:167848kb
  • [2024-07-25 12:43:12]
  • 提交

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;
		
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 74588kb

input:

1501
524935 524911 524956 524964 525002 524945 524944 524954 524980 525009 524971 524989 524955 524962 524933 524935 524938 524973 524931 524933 524939 524994 524948 524912 27768 524937 482489 525001 524961 524964 524988 524959 524984 43791 525005 524911 524929 524952 524944 524918 524924 524961 524...

output:

736188234

result:

wrong answer 1st numbers differ - expected: '701627312', found: '736188234'

Test #2:

score: 0
Wrong Answer
time: 7ms
memory: 75400kb

input:

2501
524935 524987 524985 15371 521077 524914 358211 524917 524933 524940 524997 524965 525010 508291 509667 525010 34977 524932 525001 524931 524927 524931 524942 524978 524940 524999 48818 524991 524942 524983 524953 524952 524932 524911 524996 524980 524926 524978 524988 524930 524951 524933 5249...

output:

1310428023

result:

wrong answer 1st numbers differ - expected: '1248760886', found: '1310428023'

Test #3:

score: 0
Wrong Answer
time: 107ms
memory: 90308kb

input:

100000
524940 524940 524924 524939 524984 524915 524961 524980 525007 524983 525000 524949 525003 183887 203283 524986 524948 524943 524962 524962 524951 524938 524971 524944 524978 353146 524954 288731 524914 524927 524930 524964 524939 524977 524968 524937 524930 524931 525005 524917 524935 524953...

output:

896890310

result:

wrong answer 1st numbers differ - expected: '48847009165', found: '896890310'

Test #4:

score: 0
Wrong Answer
time: 102ms
memory: 90388kb

input:

100000
525001 524945 300466 524918 524993 524942 524980 524940 524958 524982 524985 524930 525000 524914 524979 524916 524986 524952 524991 525010 524943 525003 404403 363004 524963 524999 524937 524940 307161 524926 524982 524988 524916 524987 524960 524993 524969 524946 524933 524951 524941 524920...

output:

986110194

result:

wrong answer 1st numbers differ - expected: '48821541653', found: '986110194'

Test #5:

score: 0
Wrong Answer
time: 99ms
memory: 89604kb

input:

100000
524983 525002 524939 524914 524941 29526 73021 524953 524927 525007 524993 524982 524976 524975 524981 524950 524970 524937 524980 524916 524979 524983 55981 524985 524975 524969 524982 524921 524985 459301 525008 524911 524932 524954 524952 524952 524959 306535 524989 524989 524987 524951 52...

output:

496888794

result:

wrong answer 1st numbers differ - expected: '48815029002', found: '496888794'

Test #6:

score: 0
Wrong Answer
time: 160ms
memory: 101948kb

input:

152501
524982 524933 525002 524967 82725 253741 524911 524981 524972 524935 244289 524931 524957 524927 524940 524960 524932 150931 524974 524920 524975 524940 525008 524963 71995 525001 524997 524974 69275 146625 459556 524968 524919 447791 524928 524983 524953 524963 524959 524985 524999 249653 52...

output:

-1572884843

result:

wrong answer 1st numbers differ - expected: '74328889396', found: '-1572884843'

Test #7:

score: 0
Wrong Answer
time: 169ms
memory: 99892kb

input:

152501
524970 524966 524938 524994 525004 524921 188941 525008 524943 524917 524999 524997 284880 524976 524946 524994 524976 524923 524960 524990 524917 525005 524987 524961 525009 254221 524982 108142 524971 524988 524927 524915 524983 524961 524951 524988 524985 525001 524936 524921 524973 524949...

output:

-1459497822

result:

wrong answer 1st numbers differ - expected: '74602741206', found: '-1459497822'

Test #8:

score: 0
Wrong Answer
time: 160ms
memory: 101876kb

input:

152501
524980 524993 525005 524943 524950 524998 524990 524952 261512 524968 524918 524973 524976 524920 524951 524952 524965 524966 524914 524976 524937 524917 524914 524911 524991 524997 524974 524964 524945 524941 524920 524916 524971 192185 524971 524926 524959 524971 524973 524911 524921 524997...

output:

-1738745727

result:

wrong answer 1st numbers differ - expected: '74603663049', found: '-1738745727'

Test #9:

score: 0
Wrong Answer
time: 994ms
memory: 165744kb

input:

525010
524955 524979 495345 524927 524966 524997 524942 138576 524956 524989 524940 524969 360541 524997 524952 524997 524933 524931 524958 524987 524933 524941 407091 524952 524951 524972 524998 524913 524955 524948 524988 524920 524981 524999 524985 525002 524940 524976 524956 524920 524921 524978...

output:

1199947287

result:

wrong answer 1st numbers differ - expected: '275846381079', found: '1199947287'

Test #10:

score: 0
Wrong Answer
time: 1003ms
memory: 167848kb

input:

525010
410691 524927 524994 524983 524994 524996 524933 524973 525009 331627 524951 524998 171113 524978 524960 525000 69833 524948 525002 524919 525001 294363 524925 263273 116049 524946 524993 524976 524961 524936 524968 7337 524987 524981 524925 260013 524931 427126 524993 524962 524950 524956 52...

output:

1038949135

result:

wrong answer 1st numbers differ - expected: '275754326799', found: '1038949135'

Test #11:

score: 0
Wrong Answer
time: 984ms
memory: 165732kb

input:

525010
524949 524945 524932 524948 524918 524939 524958 524963 524923 524995 524981 524950 524927 524929 524945 524972 524911 524961 524913 524949 524986 524934 524971 524925 524950 524957 524919 524945 524982 524929 524982 524926 524938 331619 524965 524934 524929 524949 524917 524978 337295 524919...

output:

1154855037

result:

wrong answer 1st numbers differ - expected: '275940487293', found: '1154855037'

Test #12:

score: 0
Wrong Answer
time: 1010ms
memory: 165812kb

input:

525010
524926 524992 524936 524979 524925 524994 525001 524946 524981 524922 524993 436287 525002 524939 525007 524926 524986 524975 524986 524961 524932 525007 524935 524948 524988 524972 524963 524956 524960 38337 524932 524924 524996 524955 524986 524976 524966 524973 524983 524991 524965 524978 ...

output:

1335154161

result:

wrong answer 1st numbers differ - expected: '275983685105', found: '1335154161'

Test #13:

score: 0
Wrong Answer
time: 860ms
memory: 166548kb

input:

525010
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

950665188

result:

wrong answer 1st numbers differ - expected: '23032985474', found: '950665188'

Test #14:

score: 0
Wrong Answer
time: 859ms
memory: 164420kb

input:

525010
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

950665188

result:

wrong answer 1st numbers differ - expected: '22985217528', found: '950665188'

Test #15:

score: 0
Wrong Answer
time: 862ms
memory: 166488kb

input:

525010
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

950665188

result:

wrong answer 1st numbers differ - expected: '23007875223', found: '950665188'

Test #16:

score: 0
Wrong Answer
time: 869ms
memory: 164424kb

input:

525010
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

950665188

result:

wrong answer 1st numbers differ - expected: '23045778723', found: '950665188'

Test #17:

score: 0
Wrong Answer
time: 1002ms
memory: 160972kb

input:

525010
524997 524962 524959 525010 524997 524946 524992 524974 524978 524988 524983 524960 524949 524922 524948 524925 179739 374866 524976 113487 524978 524936 524931 524912 524993 524933 524947 524940 524947 524949 525008 525006 524928 524979 524966 524925 524993 524917 524915 524969 524997 524936...

output:

1044772321

result:

wrong answer 1st numbers differ - expected: '256639673082', found: '1044772321'

Test #18:

score: 0
Wrong Answer
time: 1014ms
memory: 160984kb

input:

525010
524939 524971 524960 524991 524958 524977 525000 524920 524937 524925 524933 524944 524977 524921 524975 524942 524933 524998 524913 524938 524937 524980 525004 524986 15097 20701 524986 525008 524943 258327 525008 524982 524925 524956 439611 524955 42646 46145 525009 524957 524961 524946 524...

output:

779740502

result:

wrong answer 1st numbers differ - expected: '256545959720', found: '779740502'

Test #19:

score: 0
Wrong Answer
time: 1014ms
memory: 160904kb

input:

525010
524913 524930 525002 524948 524945 524933 524990 524998 525001 524995 524974 524912 524950 524951 524951 524960 524928 524927 524911 350625 524991 178441 300871 524988 524982 524949 325161 524957 524999 332281 525005 524913 524960 524998 525006 199811 525008 524960 338801 524944 524953 524935...

output:

699261246

result:

wrong answer 1st numbers differ - expected: '256775767753', found: '699261246'

Test #20:

score: 0
Wrong Answer
time: 1008ms
memory: 162916kb

input:

525010
524951 524981 524977 524964 524942 524945 524936 524994 524959 524920 524971 524979 524945 365305 524992 524945 525001 524979 524951 524951 524994 524955 524975 524937 524939 524913 524963 524960 524977 524949 524970 524995 524978 524989 524912 524933 524998 524999 524992 524983 524956 156707...

output:

765838246

result:

wrong answer 1st numbers differ - expected: '256735623773', found: '765838246'