QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19291 | #1877. Matryoshka Dolls | Forza_Ferrari | Compile Error | / | / | C++14 | 2.9kb | 2022-01-28 22:49:47 | 2022-05-18 04:06:32 |
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:06:32]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2022-01-28 22:49:47]
- 提交
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,a[500001],p[500001],block,pos[500001],s[500001],pre[500001],nxt[500001],sum[500001],h[500001][2];
long long ans[500001],res;
struct element
{
int l,r,id;
bool operator <(const element &other) const
{
return pos[l]^pos[other.l]? pos[l]<pos[other.l]:r>other.r;
}
}q[500001];
inline int read()
{
int x=0;
char c=getchar();
while(c<'0'||c>'9')
c=getchar();
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x;
}
inline void print(long long x)
{
if(x>=10)
print(x/10);
putchar(x%10+'0');
}
inline int Abs(int x)
{
return x>=0? x:-x;
}
inline void insert(int x)
{
++sum[x];
}
inline void del(int x)
{
--sum[x];
if(pre[x])
{
res-=Abs(p[pre[x]]-p[x]);
nxt[pre[x]]=nxt[x];
}
if(nxt[x])
{
res-=Abs(p[nxt[x]]-p[x]);
pre[nxt[x]]=pre[x];
}
if(pre[x]&&nxt[x])
res+=Abs(p[pre[x]]-p[nxt[x]]);
pre[x]=nxt[x]=0;
}
int main()
{
n=read(),m=read();
block=max(n/sqrt(m),1);
for(int i=1;i<=n;++i)
{
p[a[i]=read()]=i;
pos[i]=(i-1)/block+1;
if(pos[i]^pos[i-1])
s[pos[i]]=i;
}
for(int i=1;i<=m;++i)
{
q[i].l=read(),q[i].r=read();
q[i].id=i;
}
sort(q+1,q+m+1);
for(int i=1,l=1,r=0,lst=0;i<=m;++i)
{
if(lst^pos[q[i].l])
{
lst=pos[q[i].l];
for(;l>s[pos[q[i].l]];--l)
insert(a[l-1]);
for(;r<n;++r)
insert(a[r+1]);
for(;l<s[pos[q[i].l]];++l)
del(a[l]);
int k=0;
res=0;
for(int j=1;j<=n;++j)
{
pre[j]=nxt[j]=0;
if(sum[j])
{
pre[j]=k;
if(k)
{
nxt[k]=j;
res+=Abs(p[j]-p[k]);
}
k=j;
}
}
}
for(;r>q[i].r;--r)
del(a[r]);
long long tmp=res;
for(int j=l;j<q[i].l;++j)
{
h[j][0]=pre[a[j]];
h[j][1]=nxt[a[j]];
}
for(;l<q[i].l;++l)
del(a[l]);
ans[q[i].id]=res;
for(;l>s[pos[q[i].l]];--l)
{
pre[a[l-1]]=h[l-1][0];
nxt[a[l-1]]=h[l-1][1];
if(pre[a[l-1]])
nxt[pre[a[l-1]]]=a[l-1];
if(nxt[a[l-1]])
pre[nxt[a[l-1]]]=a[l-1];
h[l-1][0]=h[l-1][1]=0;
insert(a[l-1]);
}
res=tmp;
}
for(int i=1;i<=m;++i)
{
print(ans[i]);
putchar('\n');
}
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:63:14: error: no matching function for call to ‘max(__gnu_cxx::__enable_if<true, double>::__type, int)’ 63 | block=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/ostream:38, from /usr/include/c++/11/iostream:39, 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:63:14: note: deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’) 63 | block=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/ostream:38, from /usr/include/c++/11/iostream:39, 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:63:14: note: deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘int’) 63 | block=max(n/sqrt(m),1); | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/11/algorithm:62, from answer.code:3: /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:63:14: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘double’ 63 | block=max(n/sqrt(m),1); | ~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/11/algorithm:62, from answer.code:3: /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:63:14: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘double’ 63 | block=max(n/sqrt(m),1); | ~~~^~~~~~~~~~~~~