QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18876#1877. Matryoshka DollsgshCompile Error//C++202.5kb2022-01-27 14:18:202022-05-18 04:05:21

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:21]
  • 评测
  • [2022-01-27 14:18:20]
  • 提交

answer

#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
#define ll long long
#define For(i,l,r) for(int i=l;i<=r;i++)
#define FOR(i,l,r) for(int i=l;i>=r;i--)
#define MAXN 500001
int N,M,B,p[MAXN],q[MAXN],d[MAXN];ll ans[MAXN];struct que{int l,r,id;}a[MAXN];
int get(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
int solve1()
{
	For(i,2,N)d[i]=abs(q[i]-q[i-1]);For(i,2,N)d[i]+=d[i-1];
	For(i,1,M)
	{
		int l=get(),r=get();
		if(r-l<=60){int pre=-1,sum=0;For(i,max(l-20,1),min(r+20,N))if(q[i]>=l&&q[i]<=r){if(pre!=-1)sum+=abs(q[i]-pre);pre=q[i];}cout<<sum<<'\n';}
		else
		{
			int sum=0,pre=-1;
			For(i,max(l-20,1),l+20)if(q[i]>=l&&q[i]<=r){if(pre!=-1)sum+=abs(q[i]-pre);pre=q[i];}
			pre=-1;
			For(i,r-20,min(r+20,N))if(q[i]>=l&&q[i]<=r){if(pre!=-1)sum+=abs(q[i]-pre);pre=q[i];}
			cout<<sum+d[r-20]-d[l+20]<<'\n';
		}
	}
	return 0;
}
int main()
{
	N=get(),M=get();For(i,1,N)q[p[i]=get()]=i;bool flag=1;For(i,1,N)flag&=abs(i-p[i])<=10;if(flag)return solve1();
	For(i,1,M)a[i].l=get(),a[i].r=get(),a[i].id=i;
	B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
	int l=1,r=0;ll sum=0;set<int>s;
	For(i,1,M)
	{
		while(r<a[i].r)
		{
			r++;auto tmp=s.lower_bound(p[r]);
			if(tmp!=s.end()&&tmp!=s.begin()){int x=*tmp,y=*--tmp;sum-=abs(q[x]-q[y]);sum+=abs(q[x]-r)+abs(q[y]-r);}
			else if(tmp!=s.end())sum+=abs(q[*tmp]-r);else if(tmp!=s.begin())sum+=abs(q[*--tmp]-r);s.insert(p[r]);
		}
		while(l>a[i].l)
		{
			l--;auto tmp=s.lower_bound(p[l]);
			if(tmp!=s.end()&&tmp!=s.begin()){int x=*tmp,y=*--tmp;sum-=abs(q[x]-q[y]);sum+=abs(q[x]-l)+abs(q[y]-l);}
			else if(tmp!=s.end())sum+=abs(q[*tmp]-l);else if(tmp!=s.begin())sum+=abs(q[*--tmp]-l);s.insert(p[l]);
		}
		while(r>a[i].r)
		{
			s.erase(p[r]);auto tmp=s.lower_bound(p[r]);
			if(tmp!=s.end()&&tmp!=s.begin()){int x=*tmp,y=*--tmp;sum+=abs(q[x]-q[y]);sum-=abs(q[x]-r)+abs(q[y]-r);}
			else if(tmp!=s.end())sum-=abs(q[*tmp]-r);else if(tmp!=s.begin())sum-=abs(q[*--tmp]-r);r--;
		}
		while(l<a[i].l)
		{
			s.erase(p[l]);auto tmp=s.lower_bound(p[l]);
			if(tmp!=s.end()&&tmp!=s.begin()){int x=*tmp,y=*--tmp;sum+=abs(q[x]-q[y]);sum-=abs(q[x]-l)+abs(q[y]-l);}
			else if(tmp!=s.end())sum-=abs(q[*tmp]-l);else if(tmp!=s.begin())sum-=abs(q[*--tmp]-l);l++;
		}
		ans[a[i].id]=sum;
	}
	For(i,1,M)cout<<ans[i]<<'\n';return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:36:14: error: no matching function for call to ‘max(__gnu_cxx::__enable_if<true, double>::__type, int)’
   36 |         B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:61,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
answer.code:36:14: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’)
   36 |         B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:61,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
answer.code:36:14: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’)
   36 |         B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)’
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
answer.code:36:14: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
   36 |         B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)’
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
answer.code:36:14: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
   36 |         B=max(N/sqrt(M),1);sort(a+1,a+M+1,[&](const que&a,const que&b){return a.l/B<b.l/B||a.l/B==b.l/B&&a.r<b.r;});
      |           ~~~^~~~~~~~~~~~~