https://codeforces.com/contest/1933/problem/E
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef __int128 i128;
typedef pair<int,int> pii;
const int N=2e5+10,M=110;
int n,q;
int a[N];
ll s[N];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i];
cin>>q;
while(q--)
{
int L,u;
cin>>L>>u;
int l=L,r=n;
//cout<<l<<' '<<r<<endl;
while(l<r)
{
int mid=(r-l)/3;
//cout<<mid<<endl;
int m1=l+mid;
int m2=r-mid;
//cout<<m1<<' '<<m2<<endl;
ll s1=s[m1]-s[L-1];
ll s2=s[m2]-s[L-1];
ll sum1=2*s1*u+s1-s1*s1;
ll sum2=2*s2*u+s2-s2*s2;
if(sum1>=sum2) r=m2-1;
else l=m1+1;
}
cout<<l<<' ';
}
cout<<endl;
}
return 0;
}
标签:Turtle,typedef,Trainings,cout,int,vs,cin,Codeforces,Race
From: https://www.cnblogs.com/djhjojo/p/18332864