QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19012#1877. Matryoshka Dolls123qwqWA 3ms5568kbC++141.3kb2022-01-27 18:22:132022-05-06 03:33:53

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 03:33:53]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5568kb
  • [2022-01-27 18:22:13]
  • 提交

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--)
	{
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 5568kb

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'