QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#799329 | #9853. Easy String Problem | quailty | WA | 0ms | 3724kb | C++23 | 1015b | 2024-12-05 11:04:10 | 2024-12-05 11:04:11 |
Judging History
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