QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307781 | #8016. 不休陀螺 | jerry2007 | Compile Error | / | / | C++14 | 3.0kb | 2024-01-19 09:14:48 | 2024-01-19 09:14:48 |
Judging History
answer
# include<bits/stdc++.h>
# define lowbit(x) (x&(-x))
# define N 1000005
using namespace std;
int a[N],b[N];
long long sum1[N],sum2[N],maxa[N];
int n,E;
int ans;
bool mark[N];
struct BIT
{
long long sum[N],k;
void init(int x)
{
k=x;
for(int i=1;i<=x;i++)
sum[i]=0;
}
void add(int x,long long y)
{
for(int i=x;i<=k;i+=lowbit(i))
sum[i]+=y;
}
long long query(int x)
{
long long ans=0;
for(int i=x;i>0;i-=lowbit(i))
ans+=sum[i];
return ans;
}
}T;
struct node
{
int x,id;
}p[N],del[N];
int cnt;
int rk[N];
bool cmp(node x,node y)
{
return x.x<y.x;
}
void solve(int l,int r)
{
if(l==r)
{
ans+=a[l]<=E && b[l]>=a[l];
return ;
}
int mid=(l+r)>>1;
solve(l,mid);
solve(mid+1,r);
sum1[mid]=max(0,a[mid]-b[mid]);
sum1[mid+1]=max(0,a[mid+1]-b[mid+1]);
maxa[mid]=min(a[mid],b[mid]),maxa[mid+1]=min(a[mid+1],b[mid+1]);
for(int i=mid-1;i>=l;i--)
{
sum1[i]=sum1[i+1]+max(0,a[i]-b[i]);
maxa[i]=max(maxa[i+1],min(a[i],b[i]));
}
for(int i=mid+2;i<=r;i++)
{
sum1[i]=sum1[i-1]+max(0,a[i]-b[i]);
maxa[i]=max(maxa[i-1],min(a[i],b[i]));
}
cnt=0;
p[++cnt]=(node){sum2[l-1],l-1};
for(int i=l;i<=r;i++)
p[++cnt]=(node){sum2[i],i};
sort(p+1,p+1+cnt,cmp);
int now=0;
for(int i=1;i<=cnt;i++)
{
if(i==1 || p[i-1].x!=p[i].x)
now++;
rk[p[i].id]=now;
}
T.init(now);
for(int i=mid+1;i<=r;i++)
T.add(rk[i],1),mark[i]=1,del[i-mid]=(node){sum1[i]+maxa[i],i};
sort(del+1,del+r-mid+1,cmp);
int p1=mid+1,p2=r-mid,res=r-mid;
for(int i=mid;i>=l;i--)
{
while(p1<=r && maxa[p1]<maxa[i])
{
if(mark[p1]) T.add(rk[p1],-1),res--;
mark[p1]=0,p1++;
}
while(p2 && E-sum1[i]<del[p2].x)
{
int x=del[p2].id;
if(mark[x])
T.add(rk[x],-1),res--;
mark[x]=0;
p2--;
}
ans+=res-T.query(rk[i-1]-1);
}
T.init(now);
for(int i=l;i<=mid;i++)
T.add(rk[i-1],1),mark[i]=1,del[i-l+1]=(node){sum1[i]+maxa[i],i};
sort(del+1,del+1+mid-l+1,cmp);
p1=mid,p2=mid-l+1;
for(int i=mid+1;i<=r;i++)
{
while(p1>=l && maxa[p1]<=maxa[i])
{
if(mark[p1]) T.add(rk[p1-1],-1);
mark[p1]=0,p1--;
}
while(p2 && E-sum1[i]<del[p2].x)
{
int x=del[p2].id;
if(mark[x])
T.add(rk[x-1],-1);
mark[x]=0;
p2--;
}
ans+=T.query(rk[i]);
}
}
int main()
{
cin>>n>>E;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
sum2[i]=sum2[i-1]+b[i]-a[i];
solve(1,n);
cout<<ans<<endl;
return 0;
}
Details
answer.code: In function ‘void solve(int, int)’: answer.code:58:20: error: no matching function for call to ‘max(long long int&, const int&)’ 58 | maxa[i]=max(maxa[i+1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: answer.code:58:20: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 58 | maxa[i]=max(maxa[i+1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: answer.code:58:20: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 58 | maxa[i]=max(maxa[i+1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61: /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: answer.code:58:20: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 58 | maxa[i]=max(maxa[i+1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: answer.code:58:20: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 58 | maxa[i]=max(maxa[i+1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:63:20: error: no matching function for call to ‘max(long long int&, const int&)’ 63 | maxa[i]=max(maxa[i-1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: answer.code:63:20: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 63 | maxa[i]=max(maxa[i-1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’ 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algobase.h:303:5: note: template argument deduction/substitution failed: answer.code:63:20: note: deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’) 63 | maxa[i]=max(maxa[i-1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’ 5795 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5795:5: note: template argument deduction/substitution failed: answer.code:63:20: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 63 | maxa[i]=max(maxa[i-1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’ 5805 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/13/bits/stl_algo.h:5805:5: note: template argument deduction/substitution failed: answer.code:63:20: note: mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’ 63 | maxa[i]=max(maxa[i-1],min(a[i],b[i])); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:67:29: warning: narrowing conversion of ‘sum2[(l - 1)]’ from ‘long long int’ ...