QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19187 | #1877. Matryoshka Dolls | 123qwq | WA | 5ms | 7152kb | C++14 | 1.3kb | 2022-01-28 14:06:29 | 2022-05-06 04:23:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int a[500010],b[500010];
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void print(int x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar(x%10+'0');
}
inline int find(int l,int r,int x)
{
for(int i=l;i<=r;i++)
if(a[i]==x)
return i;
}
inline void qsort(int l,int r)
{
int mid=b[(l+r)>>1],i=l,j=r;
do
{
while(b[i]<mid)i++;
while(b[j]>mid)j--;
if(i<=j)
{
b[i]^=b[j]^=b[i]^=b[j];
i++;
j--;
}
}while(i<=j);
if(l<j)qsort(l,j);
if(i<r)qsort(i,r);
}
int main()
{
//freopen("rrads.in","r",stdin);
//freopen("rrads.out","w",stdout);
int n=read(),m=read();
for(register int i=1;i<=n;++i)a[i]=read();
while(m--)
{
memset(b,0,sizeof(b));
int l=read(),r=read(),ans=0;
for(register int i=l;i<=r;++i)
b[i]=a[i];
qsort(l,r);
for(register int i=l;i<r;++i)
ans+=abs(find(l,r,b[i])-find(l,r,b[i+1]));
print(ans);
puts("");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 7152kb
input:
5 5 1 5 2 4 3 1 5 1 4 1 3 1 2 1 1
output:
10 6 4 4 0
result:
wrong answer 1st numbers differ - expected: '7', found: '10'