QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102466#5258. Mortgagefz_zsl#WA 5ms13000kbC++142.5kb2023-05-03 13:35:552023-05-03 13:36:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 13:36:00]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:13000kb
  • [2023-05-03 13:35:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2) 
#define LL long long
#define LD long double
#define DB double
#define UI unsigned int
#define N 200005
void cmax(int& a,int b){
	(a<b)&&(a=b);
}
void cmin(int& a,int b){
	(a>b)&&(a=b);
}
void Read(int& a){
	char c=a=0;
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')a=(a*10)+(c^'0'),c=getchar();
}
void cmin(LL& a,LL b){
	a>b&&(a=b);
}
bool Bar;
int n,m,l,r,mid,ans,Ans[N],Lim[N];
int top,A[N],s,e,Len[N],len;
LL sum,a,b,Sum[N],Pre[N];
vector<int>St[N],Ed[N];
struct V{
	LL x,y;
}Sk[N],tmp;
bool Ka;//real,imag
int Check(V a,V b,V c){
	return (a.y-b.y)*(c.x-b.x)<(c.y-b.y)*(a.x-b.x);
}
LL Get_b(int p,int k){
	return Sk[p].y-1ll*Sk[p].x*k;
}
LL Check(int k){
	int l=1,r=top-1,mid;
	LL res=Get_b(top,k);
//	printf("res:%lld %lld %lld\n",res+sum,Sk[top].x,Sk[top].y+sum);
	while(l<=r){
		mid=(l+r)>>1;
		if(Sk[mid].x>len){
			l=mid+1;
//			cerr<<"?"<<endl;
			continue;
		}
		a=Get_b(mid,k);
		b=Get_b(mid+1,k);
		cmin(res,a);
		cmin(res,b);
		if(b<=a)l=mid+1;
		else r=mid-1;
	}
	return res;
 }
int main() {
//	printf("%lf\n",(&Ka-&Bar)/1024.0/1024.0);
//	freopen("A.in","r",stdin);
//	freopen("A.out","w",stdout);
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&A[i]),Sum[i]=A[i]+Sum[i-1];
	for(int i=1;i<=m;++i){
		scanf("%d %d",&s,&Len[i]);
		e=s+Len[i]-1;
		St[s].push_back(i);
		Ed[n-e+1].push_back(i);
	}
	for(int i=n;i;--i){
		tmp=(V)<%i,-sum%>;
		while(top>1&&Check(tmp,Sk[top],Sk[top-1]))--top;
		Sk[++top]=tmp,sum+=A[i];
//		cerr<<top<<" "<<Sk[top].x<<" "<<Sk[top].y<<endl;
		for(int j:St[i]){
			len=Len[j]+i-1,ans=-1;
			l=0,r=1e9;
			while(l<=r){
				mid=(l+r)>>1;
				Pre[j]=Sum[len-1]-Sum[i-1];
				if(Check(mid)+sum+1ll*mid*(Lim[j]=i-1)>=0)ans=mid,l=mid+1;
				else r=mid-1;
			}
			Ans[j]=ans;
		}
	}
	top=0,sum=0;
	for(int l=1,r=n;l<r;++l,--r)swap(A[l],A[r]);
	for(int i=n;i;--i){
		tmp=(V)<%i-n-1,-sum%>;
		while(top>1&&Check(tmp,Sk[top],Sk[top-1]))--top;
		Sk[++top]=tmp,sum+=A[i];
		for(int j:Ed[i]){
			len=Len[j]+i-1-n-1,ans=-1;
			l=0,r=1e9;
//			cerr<<"Len:"<<len<<" "<<Sk[top].y+sum+Pre[j]+Sk[top].x*3<<endl;
//			exit(0);
			while(l<=r){
				mid=(l+r)>>1;
				if(Check(-mid)+sum+Pre[j]+1ll*mid*Lim[j]>=0)ans=mid,l=mid+1;
				else r=mid-1;
			}
			cmin(Ans[j],ans);
		}
	}
	for(int i=1;i<=m;++i){
		if(Ans[i]==-1)puts("stay with parents");
		else printf("%d\n",Ans[i]);
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 13000kb

input:

10 10
21 18 19 18 16 15 13 13 13 10
10 1
6 4
7 3
2 2
6 5
2 6
3 2
4 1
1 5
6 3

output:

10
13
13
18
12
16
18
18
18
13

result:

ok 10 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 13000kb

input:

1000 1000
196 207 195 207 200 203 202 204 205 191 190 188 203 198 201 188 203 198 196 196 200 195 200 206 193 198 186 196 200 185 202 195 203 199 185 199 202 191 184 194 195 194 193 195 184 197 189 193 186 187 193 193 196 186 195 193 186 192 188 188 187 197 179 188 195 196 197 186 194 183 189 185 19...

output:

158
16
110
64
160
118
169
63
172
128
93
82
118
119
86
32
174
145
139
84
149
120
133
155
108
110
65
178
90
99
118
91
133
85
151
76
130
51
91
99
95
78
110
87
119
141
68
81
172
82
112
139
136
81
79
16
51
31
104
116
108
38
75
176
156
55
165
112
146
74
68
172
112
159
94
177
111
166
110
112
98
155
109
155...

result:

wrong answer 38th lines differ - expected: '50', found: '51'