QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735687#9482. Count Pseudo-PalindromesNKheyuxiangWA 1ms9856kbC++141.2kb2024-11-11 21:16:562024-11-11 21:17:00

Judging History

This is the latest submission verdict.

  • [2024-11-11 21:17:00]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 9856kb
  • [2024-11-11 21:16:56]
  • Submitted

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>>7);
	x^=(x<<5);
	x^=(x>>3);
	x^=(x<<2);
	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]);
}

詳細信息

Test #1:

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

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 1ms
memory: 9840kb

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: 0ms
memory: 9856kb

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'