QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19003#1877. Matryoshka Dolls123qwqCompile Error//C++141.3kb2022-01-27 18:18:562022-05-18 04:05:35

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-18 04:05:35]
  • 评测
  • [2022-01-27 18:18:56]
  • 提交

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

详细

answer.code:27:8: error: ISO C++ forbids declaration of ‘find’ with no type [-fpermissive]
   27 | inline find(int l,int r,int x)
      |        ^~~~
answer.code: In function ‘int find(int, int, int)’:
answer.code:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^