QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735680#9482. Count Pseudo-PalindromesNKheyuxiangWA 1ms10176kbC++141.2kb2024-11-11 21:15:072024-11-11 21:15:07

Judging History

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

  • [2024-11-11 21:15:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10176kb
  • [2024-11-11 21:15:07]
  • 提交

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;
	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<<11);
	x^=(x>>4);
	x^=(x<<5);
	x^=(x>>14);
	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: 1ms
memory: 9964kb

input:

3
2 1 2 3 1 3

output:

1 2 2 2 2 1 

result:

ok 6 tokens

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 10176kb

input:

4
1 2 4 3 4 1 3 2

output:

1 3 1 2 2 4 1 1 

result:

wrong answer 2nd words differ - expected: '2', found: '3'