QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305716#8016. 不休陀螺oscaryangCompile Error//C++201.9kb2024-01-15 21:07:312024-01-15 21:07:32

Judging History

你现在查看的是最新测评结果

  • [2024-01-15 21:07:32]
  • 评测
  • [2024-01-15 21:07:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 1000010
int n;
int a[MAXN],b[MAXN];
ll S[MAXN];
int E;
#define ls p<<1
#define rs p<<1|1
struct node {
	ll sum;
	int mx;
	node operator +(node _b){
		return (node){sum+_b.sum,max(mx,_b.mx)};
	}
	inline ll w(){
		return sum+mx;
	}
}data[MAXN<<2];
inline void push_up(int p){
	data[p]=data[ls]+data[rs];
}
void build(int l,int r,int p){
	if(l==r){
		if(a[l]>b[l]) data[p]=(node){a[l]-b[l],b[l]};
		else data[p]=(node){0,a[l]};
		return ;
	}
	int mid=l+r>>1;
	build(l,mid,ls);
	build(mid+1,r,rs);
	push_up(p);
}
int R;
void find(int l,int r,int p,node pre){
	if(l==r){
		if((data[p]+pre).w()>E) R=l;
		return ;
	}
	int mid=l+r>>1;
	if((data[ls]+pre).w()>E) find(l,mid,ls,pre);
	else if((data[ls]+pre+data[rs]).w()>E) find(mid+1,r,rs,pre+data[ls]);
}
node get(int l,int r,int x,int p,node pre){
	if(R) return pre;
	if(x<=l){
		find(l,r,p,pre);
		return data[p];
	}
	int mid=l+r>>1;
	if(mid<x) return get(mid+1,r,x,rs,pre);
	node rec=get(l,mid,x,ls,pre);
	rec=rec+get(mid+1,r,x,rs,pre+rec);
	return rec;
}
ll W[MAXN],M;
vector<int> upd[MAXN];
int sum[MAXN];
inline void add(int p,int k){
	for(;p<=M;p+=-p&p) sum[p]+=k;
}
inline int ask(int p){
	int rec=0;
	for(;p;p^=-p&p) rec+=sum[p];
	return rec;
}
signed main(){
	scanf("%d%d",&n,&E);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) {
		scanf("%d",&b[i]);
		W[++M]=S[i]=S[i-1]+b[i]-a[i];
	}
	W[++M]=0;
	sort(W+1,W+M+1);
	M=unique(W+1,W+M+1)-W-1;
	S[0]=lower_bound(W+1,W+M+1,S[0])-W;
	add(S[0],1);
	build(1,n,1);
	ll ans=1ll*n*(n+1)/2;
	for(int i=1;i<=n;i++) {
		S[i]=lower_bound(W+1,W+M+1,S[i])-W;
		for(int v:upd[i]) add(v,-1);
		add(S[i],1);
		ans-=ask(M)-ask(S[i]);
		R=0;
		get(1,n,i,1,(node){0,0});
		if(!R) continue ;
		upd[R].push_back(S[i-1]);
		ans-=n-R+1;
	}
	printf("%lld",ans);
	return 0;
}

Details

answer.code: In function ‘void push_up(int)’:
answer.code:22:9: error: reference to ‘data’ is ambiguous
   22 |         data[p]=data[ls]+data[rs];
      |         ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 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/range_access.h:319:5: note: candidates are: ‘template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)’
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])’
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)’
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)’
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
answer.code:20:2: note:                 ‘node data [4000040]’
   20 | }data[MAXN<<2];
      |  ^~~~
answer.code:22:17: error: reference to ‘data’ is ambiguous
   22 |         data[p]=data[ls]+data[rs];
      |                 ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 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/range_access.h:319:5: note: candidates are: ‘template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)’
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])’
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)’
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)’
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
answer.code:20:2: note:                 ‘node data [4000040]’
   20 | }data[MAXN<<2];
      |  ^~~~
answer.code:22:26: error: reference to ‘data’ is ambiguous
   22 |         data[p]=data[ls]+data[rs];
      |                          ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 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/range_access.h:319:5: note: candidates are: ‘template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)’
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 ‘template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])’
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 ‘template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)’
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 ‘template<class _Container> co...