QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164189#3276. 出题高手yyyyxh0 0ms0kbC++172.9kb2023-09-04 20:36:092023-09-04 20:36:09

Judging History

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

  • [2023-09-04 20:36:09]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-09-04 20:36:09]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <algorithm>
#define lc (p<<1)
#define rc (p<<1|1)
using namespace std;
typedef long long ll;
int read(){
	char c=getchar();int x=0;bool f=0;
	while(c<48||c>57) f|=(c=='-'),c=getchar();
	do x=(x<<1)+(x<<3)+(c^48),c=getchar();
	while(c>=48&&c<=57);
	if(f) return -x;
	return x;
}
ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}
struct Frac{
	ll a;int b;
	Frac(ll A=0,int B=1):a(A),b(B){}
	friend bool operator<(const Frac x,const Frac y){
		return x.a*y.b<y.a*x.b;
	}
	void chmx(Frac v){if(*this<v) *this=v;}
	void show(){
		ll g=gcd(a,b);
		a/=g;b/=g;
		printf("%lld %d\n",a,b);
	}
};
const int N=500003,M=300003,T=500003;
Frac res[M],ans[N<<2];
int s[T],n,m;
Frac calc(int x,int y){return Frac((ll)(s[y]-s[x])*(s[y]-s[x]),x-y);}
int ql[M],qr[M];
vector<int> vec[N<<2],nd[N<<2],vv[N];
bool cmp(int x,int y){return ql[x]>ql[y];}
int stk[N],tp;
Frac lis[N];
void hang(int p,int l,int r,int x){
	if(ql[x]<=l&&r<=qr[x]){nd[p].emplace_back(x);return;}
	int mid=(l+r)>>1;
	if(qr[x]<=mid) return hang(lc,l,mid,x);
	if(ql[x]>mid) return hang(rc,mid+1,r,x);
	vec[p].emplace_back(x);
	hang(lc,l,mid,x);
	hang(rc,mid+1,r,x);
}
void solve(int p,int l,int r){
	if(l==r){ans[p]=Frac();return;}
	int mid=(l+r)>>1;
	solve(lc,l,mid);
	solve(rc,mid+1,r);
	ans[p]=max(ans[lc],ans[rc]);
	tp=0;
	for(int i=l;i<=mid;++i){
		while(tp&&s[stk[tp]]<=s[i]) --tp;
		stk[++tp]=i;
	}
	for(int i=1;i<=tp+1;++i) lis[i]=Frac();
	for(int x:vec[p]){
		if(qr[x]>r) vv[r].emplace_back(x);
		else vv[qr[x]].emplace_back(x);
	}
	for(int i=mid+1;i<=r;++i){
		int p=0,len=vv[i].size();
		Frac cur=Frac();
		for(int t=tp;t;--t){
			while(p<len&&ql[vv[i][p]]>stk[t]) res[vv[i][p++]].chmx(lis[t+1]);
			if(s[stk[t]]<=s[i]) continue;
			cur.chmx(calc(i,stk[t]));
			lis[t].chmx(cur);
		}
		while(p<len) res[vv[i][p++]].chmx(lis[1]);
		vv[i].clear();
	}
	ans[p].chmx(lis[1]);
	for(int x:nd[p]) res[x].chmx(ans[p]);
}
int seq[M];
int s1[T],t1;
int s2[T],t2;
const int B=1000;
int main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i) s[i]=s[i-1]+read();
	m=read();
	for(int i=1;i<=m;++i){ql[i]=read()-1;qr[i]=read();seq[i]=i;}
	if(m==1){
		Frac rr=Frac();
		for(int tl=ql[1],tr=ql[1]+B-1;tl<=qr[1];tl+=B,tr+=B){
			if(tr>qr[1]) tr=qr[1];
			t1=t2=0;
			for(int i=tl;i<=tr;++i){
				bool f1=1,f2=1;
				for(int j=1;j<=t1;++j)
					if(s[i]<s[s1[j]]) rr.chmx(calc(i,s1[j]));
					else{s1[t1=j]=i;f1=0;break;}
				if(f1) s1[++t1]=i;
				for(int j=1;j<=t2;++j)
					if(s[i]>s[s2[j]]) rr.chmx(calc(i,s2[j]));
					else{s2[t2=j]=i;f2=0;break;}
				if(f2) s2[++t2]=i;
			}
		}
		rr.show();
		return 0;
	}
	sort(seq+1,seq+m+1,cmp);
	for(int i=1;i<=m;++i) hang(1,0,n,seq[i]);
	solve(1,0,n);
	for(int i=1;i<=n;++i) s[i]=-s[i];
	solve(1,0,n);
	for(int i=1;i<=m;++i) res[i].show();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

2000
-113 314 -664 697 211 -199 -38 -190 8 -661 910 -811 -113 942 77 433 -261 -368 129 -525 968 -608 -21 38 -562 438 -935 -228 220 333 985 -430 916 586 764 476 794 664 383 503 206 -60 380 -130 -988 -904 -996 -304 -286 31 114 119 850 -942 714 -369 -842 250 -192 -462 -727 -427 -602 126 231 718 121 559...

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #6:

score: 0
Dangerous Syscalls

input:

100000
754 792 -680 426 425 347 481 -690 530 378 73 -907 -431 45 -530 -552 440 -890 -15 712 695 -679 -310 13 718 805 193 -291 -877 -74 -355 511 -679 -395 166 -710 -657 -19 874 26 832 507 854 -289 700 -404 472 -302 -977 8 -698 40 766 705 369 838 700 -964 552 -535 -75 -608 -181 -503 468 447 772 904 -2...

output:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #11:

score: 0
Dangerous Syscalls

input:

500000
794 -75 -596 -322 -945 -908 -609 -164 488 626 -877 -710 140 -120 -475 -837 738 669 634 -643 -682 667 816 -785 -608 -836 -860 -932 242 70 -620 268 -121 288 209 -392 732 750 558 -480 565 327 -217 -891 767 211 -690 -66 813 -889 952 615 432 19 411 800 678 718 522 422 940 -510 -544 449 -357 640 40...

output:


result:


Subtask #4:

score: 0
Dangerous Syscalls

Test #16:

score: 0
Dangerous Syscalls

input:

100000
-496 -233 354 -632 -196 177 -878 -255 -19 -636 685 -70 101 -975 -406 -988 -965 -205 563 -766 763 511 -116 -746 -129 14 106 928 -457 -257 -283 226 3 899 -359 -792 615 490 -57 986 -243 624 -239 931 -555 -821 -72 -611 -380 -397 248 -132 956 -195 -322 -231 319 -214 837 -379 -931 -301 -4 -673 280 ...

output:


result:


Subtask #5:

score: 0
Dangerous Syscalls

Test #31:

score: 0
Dangerous Syscalls

input:

100000
139 -485 -497 -818 254 169 -560 22 377 -67 -243 -75 743 -788 -676 -26 -775 371 576 -303 54 733 422 800 445 687 479 -16 -288 259 783 -586 912 616 439 -416 676 -555 172 659 501 -868 337 22 -60 260 603 -982 -149 466 769 -595 -117 949 -544 904 753 20 776 175 -888 937 -792 -647 -615 59 -298 452 -6...

output:


result: