QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19190#1877. Matryoshka DollsKubicCompile Error//C++141.9kb2022-01-28 14:09:102022-05-18 04:05:57

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:57]
  • 评测
  • [2022-01-28 14:09:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define LIM 1000005
#define ll long long
#define gc() (P1==P2 && (P2=(P1=buf)+fread(buf,1,LIM,stdin),P1==P2)?EOF:*P1++)
#define set(a,vl) memset(a,vl,sizeof(a))
char *P1,*P2,buf[LIM];
int n,m,B,a[N],rv[N],bl[N],L[N],R[N];ll nw,ans[N];bool vs[N];
struct Query {int id,l,r;}b[N];struct Node {int pr,sf;}ls[N];
int abs(int x) {return x<0?-x:x;}
int rd()
{
	int res=0;char c=0;while(!isdigit(c)) c=gc();
	while(isdigit(c)) res=res*10+c-48,c=gc();return res;
}
bool cmp(Query x,Query y) {return bl[x.l]==bl[y.l]?x.r>y.r:bl[x.l]<bl[y.l];}
void init()
{
	B=max(n/sqrt(m),1);
	for(int i=1;i<=n;++i)
	{bl[i]=(i-1)/B+1;if(bl[i]>bl[i-1]) L[bl[i]]=i;R[bl[i]]=i;}
}
void build(int x)
{
	int lst=0;nw=0;set(vs,0);for(int i=L[x];i<=n;++i) vs[a[i]]=1;
	for(int i=1;i<=n;++i) if(vs[i])
	{
		ls[i]=(Node) {0,0};
		if(lst) ls[lst].sf=i,ls[i].pr=lst,nw+=abs(rv[i]-rv[lst]);lst=i;
	}
}
void dlt(int x)
{
	int pr=ls[x].pr,sf=ls[x].sf;if(pr) ls[pr].sf=sf;if(sf) ls[sf].pr=pr;
	if(pr) nw-=abs(rv[x]-rv[pr]);if(sf) nw-=abs(rv[x]-rv[sf]);
	if(pr && sf) nw+=abs(rv[pr]-rv[sf]);
}
void rev(int x)
{
	int pr=ls[x].pr,sf=ls[x].sf;if(pr) ls[pr].sf=x;if(sf) ls[sf].pr=x;
	if(pr) nw+=abs(rv[x]-rv[pr]);if(sf) nw+=abs(rv[x]-rv[sf]);
	if(pr && sf) nw-=abs(rv[pr]-rv[sf]);
}
void slv(int x,int &y)
{
	int r=n;build(x);
	while(y<=m && bl[b[y].l]==x)
	{
		while(r>b[y].r) dlt(a[r--]);for(int i=L[x];i<b[y].l;++i) dlt(a[i]);
		ans[b[y].id]=nw;for(int i=b[y].l-1;i>=L[x];--i) rev(a[i]);++y;
	}
}
void print(ll x)
{if(x<10) {putchar(x+48);return;}print(x/10);putchar(x%10+48);}
int main()
{
	n=rd();m=rd();init();for(int i=1;i<=n;++i) a[i]=rd(),rv[a[i]]=i;
	for(int i=1;i<=m;++i) b[i].id=i,b[i].l=rd(),b[i].r=rd();
	sort(b+1,b+m+1,cmp);for(int i=1,j=1;i<=bl[n];++i) slv(i,j);
	for(int i=1;i<=m;++i) print(ans[i]),puts("");return 0;
}

详细

answer.code: In function ‘void init()’:
answer.code:20:14: error: no matching function for call to ‘max(__gnu_cxx::__enable_if<true, double>::__type, int)’
   20 |         B=max(n/sqrt(m),1);
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 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:20:14: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’)
   20 |         B=max(n/sqrt(m),1);
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 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:20:14: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’)
   20 |         B=max(n/sqrt(m),1);
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 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:20:14: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
   20 |         B=max(n/sqrt(m),1);
      |           ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/11/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 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:20:14: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
   20 |         B=max(n/sqrt(m),1);
      |           ~~~^~~~~~~~~~~~~