QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746557#9482. Count Pseudo-PalindromesAcoippTL 3ms46800kbC++142.0kb2024-11-14 14:59:502024-11-14 14:59:51

Judging History

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

  • [2024-11-14 14:59:51]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:46800kb
  • [2024-11-14 14:59:50]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define N 1000005
using namespace std;
inline char nc(){
	static char buf[1000000],*p=buf,*q=buf;
	return p==q&&(q=(p=buf)+fread(buf,1,1000000,stdin),p==q)?EOF:*p++;
}
inline ll read(){
	ll res = 0,w = 1;
	char c = nc();
	while(c<'0'||c>'9')w=(c=='-'?-1:w),c=nc();
	while(c<='9'&&c>='0')res=res*10+c-'0',c=nc();
	return res*w;
}
char obuf[1<<21],*p3=obuf; 
inline void pc(char c){ 
	p3-obuf<=(1<<20)?(*p3++=c):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=c); 
} 
inline void write(ll x){ 
	if(x<0) pc('-'),x=-x; 
	if(x>9) write(x/10); 
	pc(x%10+'0'); 
}
vector<pair<ll,ll> > op[N];
ll n,i,j,a[N],ls[N],rs[N],to[N],lseq[N],rseq[N],tor[N],tol[N],ans[N],num[N],qzh[N];
priority_queue<ll> que,emp;
mt19937_64 rnd_64(time(0));
map<ll,ll> nums;
int main(){
	n=read();
	for(i=1;i<=n;i++) num[i]=rnd_64()%1000000000000000000+1;
	for(i=1;i<=2*n;i++){
		a[i]=read();
		if(!ls[a[i]]) ls[a[i]]=i;
		else rs[a[i]]=i,tol[i]=ls[a[i]],tor[ls[a[i]]]=i;
	}
	for(i=1,que=emp;i<=2*n;i++){
		if(tor[i]) que.push(i);	
		while(que.size()&&tor[que.top()]<=i) que.pop();
		if(que.size()) lseq[i]=que.top();
	}
	for(i=2*n,que=emp;i>=1;i--){
		if(tol[i]) que.push(-i);	
		while(que.size()&&tol[-que.top()]>=i) que.pop();		
		if(que.size()) rseq[i]=-que.top();
	}
	for(i=1;i<=2*n;i++) qzh[i]=(qzh[i-1]^num[a[i]]);
	for(i=1;i<=2*n;i++) op[i].clear();
	for(i=1;i<=2*n;i++) if(lseq[i]) op[lseq[i]].push_back(make_pair(i,rs[a[lseq[i]]]));
	nums.clear(),nums[0]=1;
	for(i=1;i<=2*n;nums[qzh[i]]++,i++) for(j=0;j<op[i].size();j++) ans[i]+=nums[qzh[op[i][j].first]^num[a[i]]];
	for(i=2*n;i>=1;i--) qzh[i]=(qzh[i+1]^num[a[i]]);
	for(i=1;i<=2*n;i++) op[i].clear();
	for(i=1;i<=2*n;i++) if(rseq[i]) op[rseq[i]].push_back(make_pair(i,ls[a[rseq[i]]]));
	nums.clear(),nums[0]=1;
	for(i=2*n;i>=1;nums[qzh[i]]++,i--) for(j=0;j<op[i].size();j++) ans[i]+=nums[qzh[op[i][j].first]^num[a[i]]];
	for(i=1;i<=2*n;i++) write(ans[i]),pc(' ');
	pc('\n');
	return fwrite(obuf,p3-obuf,1,stdout),0;
}

詳細信息

Test #1:

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

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 3ms
memory: 44728kb

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: 46664kb

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: 46800kb

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:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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: