QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19187#1877. Matryoshka Dolls123qwqWA 5ms7152kbC++141.3kb2022-01-28 14:06:292022-05-06 04:23:58

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 04:23:58]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7152kb
  • [2022-01-28 14:06:29]
  • 提交

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'