QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#799329#9853. Easy String ProblemquailtyWA 0ms3724kbC++231015b2024-12-05 11:04:102024-12-05 11:04:11

Judging History

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

  • [2024-12-05 11:04:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3724kb
  • [2024-12-05 11:04:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100005;
const int B=320;
int a[MAXN],l[MAXN],r[MAXN],idx[MAXN];
int cntl[MAXN],cntr[MAXN];
ll res[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int q;
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
        scanf("%d%d",&l[i],&r[i]),idx[i]=i;
    sort(idx+1,idx+q+1,[](int x,int y){
        int xb=l[x]/B,yb=l[y]/B;
        return (xb==yb ? (xb&1 ? r[x]>r[y] : r[x]<r[y]) : xb<yb);
    });
    int cl=1,cr=n;
    ll now=0;
    for(int ii=1;ii<=q;ii++)
    {
        int i=idx[ii];
        while(cl>l[i])cl--,cntl[a[cl]]--,now-=cntr[a[cl]];
        while(cr<r[i])cr++,cntr[a[cr]]--,now-=cntl[a[cr]];
        while(cl<l[i])now+=cntr[a[cl]],cntl[a[cl]]++,cl++;
        while(cr>r[i])now+=cntl[a[cr]],cntr[a[cr]]++,cr--;
        res[i]=1LL*l[i]*(n-r[i]+1)-now;
    }
    for(int i=1;i<=q;i++)
        printf("%lld\n",res[i]);
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3724kb

input:

2
8 3
ababaaab
1 2 2 5 7 8 10 10
8 1
1 2
4 4
6 2
abcacb
4 7 9 10 13 49
4 2
6 3

output:


result:

wrong answer Answer contains longer sequence [length = 5], but output contains 0 elements