QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657892#9482. Count Pseudo-Palindromesucup-team3161#WA 1ms10252kbC++201.1kb2024-10-19 15:39:422024-10-19 15:39:49

Judging History

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

  • [2024-10-19 15:39:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10252kb
  • [2024-10-19 15:39:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define eb emplace_back
const int N=1e6+5;
mt19937_64 rand1(0);
int n,a[N],b[N],nw[N];ll ans[N];ull s[N],w[N];
set<int> z;unordered_map<ull,int> mp;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) w[i]=rand1();
    for(int i=1;i<=n*2;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i) a[i]=a[n+i]=i;
    for(int i=1;i<=n*2;++i)
    {int &t=nw[a[i]];if(t) b[i]=t,b[t]=i;t=i;}
    for(int i=1;i<=n*2;++i) s[i]=s[i-1]^w[a[i]];
    for(int i=1,t;i<=n*2;++i)
    {
        ++mp[s[i-1]];
        if(i<b[i]) z.insert(i);else z.erase(b[i]);
        if(!z.empty())
        {
            t=*prev(z.end());
            ans[t]+=mp[s[i]^w[a[t]]];
        }
    }
    z.clear();mp.clear();
    for(int i=n*2,t;i;--i)
    {
        ++mp[s[i]];
        if(i>b[i]) z.insert(i);else z.erase(b[i]);
        if(!z.empty())
        {            
            t=*z.begin();
            ans[t]+=mp[s[i-1]^w[a[t]]];
        }
    }
    for(int i=1;i<=n*2;++i) printf("%lld ",ans[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 10252kb

input:

2
1 1 2 2

output:

1 2 2 1 

result:

ok 4 tokens

Test #2:

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

input:

3
2 1 2 3 1 3

output:

1 1 2 2 1 1 

result:

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