QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735673#9482. Count Pseudo-PalindromesNKheyuxiangTL 2ms9992kbC++141.1kb2024-11-11 21:13:352024-11-11 21:13:35

Judging History

This is the latest submission verdict.

  • [2024-11-11 21:13:35]
  • Judged
  • Verdict: TL
  • Time: 2ms
  • Memory: 9992kb
  • [2024-11-11 21:13:35]
  • 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>>4);
	x^=(1<<5);
	x^=(1>>14);
	return x;
}
ull s[N];
set<int > st;
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: 2ms
memory: 9980kb

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

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

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: 2ms
memory: 9992kb

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: 2ms
memory: 9916kb

input:

1
1 1

output:

1 1 

result:

ok 2 tokens

Test #5:

score: -100
Time Limit Exceeded

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:


result: