QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735713#9482. Count Pseudo-PalindromesNKheyuxiangWA 1540ms114680kbC++141.2kb2024-11-11 21:22:362024-11-11 21:22:37

Judging History

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

  • [2024-11-11 21:22:37]
  • 评测
  • 测评结果:WA
  • 用时:1540ms
  • 内存:114680kb
  • [2024-11-11 21:22:36]
  • 提交

answer

#include<bits/stdc++.h>
#define N 1000005 
#define ull unsigned long long
#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++)
using namespace std;
char buf[100000], *p1, *p2;
inline int read(){
	char ch;
	int x = 0;
	scanf("%d",&x);
	return x;
	while ((ch = gc) < 48);
	do x = x * 10 + ch - 48; while ((ch = gc) >= 48);
	return x;
}
int n,a[N],b[N],c[N];
ull shift(ull x){
	x=x*x;
	x^=(x<<11);
	x^=(x>>7);
	x^=(x<<9);
	x^=(x>>5);
	return x;
}
ull s[N];
set<int > st;
unordered_map<int ,int > mp;
long long ans[N];
int main(){
	n=read();
	for(int i=1;i<=2*n;i++){
		a[i]=read();
		if(c[a[i]]) b[c[a[i]]]=i,b[i]=c[a[i]];
		c[a[i]]=i;
	}
	for(int i=1;i<=2*n;i++) s[i]=s[i-1]^shift(a[i]);
	for(int i=1;i<=2*n;i++){
		mp[s[i-1]]++;
		if(i<b[i]) st.insert(i);
		else st.erase(b[i]);
		if(!st.empty()){
			auto it=st.end();it--;
			ans[*it]+=mp[s[i]^shift(a[*it])];
		}
	}
	mp.clear();st.clear();
	for(int i=2*n;i>=1;i--){
		mp[s[i]]++;
		if(i>b[i]) st.insert(i);
		else st.erase(b[i]);
		if(!st.empty()){
			auto it=st.begin();
			ans[*it]+=mp[s[i-1]^shift(a[*it])];
		}
	}
	for(int i=1;i<=2*n;i++) printf("%lld ",ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9964kb

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 2ms
memory: 10252kb

input:

3
2 1 2 3 1 3

output:

1 2 2 2 2 1 

result:

ok 6 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 11952kb

input:

4
1 2 4 3 4 1 3 2

output:

1 2 1 2 1 3 1 1 

result:

ok 8 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 10244kb

input:

1
1 1

output:

1 1 

result:

ok 2 tokens

Test #5:

score: -100
Wrong Answer
time: 1540ms
memory: 114680kb

input:

500000
233733 151347 468353 495903 234861 297169 312993 2734 287872 359375 79017 285205 219439 37290 409190 194953 306816 472906 123794 121028 66509 62235 385879 300188 485875 72413 167304 333428 33910 220100 151575 22575 206653 82054 111518 34032 48702 198940 6262 222529 170641 1735 38943 235003 11...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

wrong answer 1356th words differ - expected: '1', found: '2'