QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#422575#7520. Monster GeneratorTx_LcyWA 2ms3888kbC++142.9kb2024-05-27 16:36:382024-05-27 16:36:39

Judging History

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

  • [2024-05-27 16:36:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3888kb
  • [2024-05-27 16:36:38]
  • 提交

answer

//A tree without skin will surely die.
//A man without face is invincible.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mid ((l+r)>>1)
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
#define ull unsigned long long
int const N=105;
int n,m,top,stk[N],id[N],a[N],da[N],b[N],db[N],A[N],B[N];
__int128 k[N],bb[N];
ull sm;
inline vector<int> get(int x){
	vector<int>V;
	rep(i,1,n) A[i]=a[i]+da[i]*x,B[i]=b[i]+db[i]*x;
	vector<int>a,b;
	rep(i,1,n)
		if (A[i]<=B[i]) a.push_back(i);
		else b.push_back(i);
	sort(all(a),[](int x,int y){return A[x]<A[y];});
	sort(all(b),[](int x,int y){return B[x]>B[y];});
	for (auto i:a) V.push_back(i);
	for (auto i:b) V.push_back(i);
	return V;
}
double const eps=1e-12;
inline double jiao(int x,int y){
    return 1.0*(bb[y]-bb[x])/(k[x]-k[y]);
}
inline int dcmp(double x){
    if (x>eps) return 1;
    if (x<-eps) return -1;
    return 0;
}
void solve(){
	cin>>n>>m;
    // cerr<<n<<" ?S?DF?\n";
	rep(i,1,n) cin>>a[i]>>da[i]>>b[i]>>db[i];
    // cerr<<"over?\n";
    vector<int>V=get(0);
    __int128 Sm=0,mx=0;int la=0;
    for (auto i:V) Sm+=a[i]-b[la],mx=max(mx,Sm),la=i;
    sm=mx;
	rep(i,1,m){
		int l=i,r=m,ans=0;
		vector<int>V=get(i);
		while (l<=r)
			if (get(mid)==V) l=(ans=mid)+1;
			else r=mid-1;
		int ct=0,la=0;
		for (auto x:V){
			++ct;
			k[ct]=k[ct-1]+da[x]-db[la];
			bb[ct]=bb[ct-1]+a[x]-b[la];
			la=x;
		}
        rep(i,1,n) id[i]=i;
        sort(id+1,id+n+1,[](int x,int y){return (k[x]^k[y])?(k[x]<k[y]):(bb[x]>bb[y]);});
        top=0;
        rep(i,1,n){
            if (i>1 && k[id[i]]==k[id[i-1]]) continue;
            while (top>1 && dcmp(jiao(stk[top],stk[top-1])-jiao(id[i],stk[top-1]))>=0) --top;
            stk[++top]=id[i];
        }
        la=i;
        rep(i,1,top){
            int X=stk[i],Y=stk[i+1],l=0,r=ans,res=0;
            if (i==top) res=ans;
            else{
                while (l<=r)
                    if (k[X]*mid+bb[X]>=k[Y]*mid+bb[Y]) l=(res=mid)+1;
                    else r=mid-1;
            }
            if (la<=res){
                sm+=1ull*((__int128)(la+res)*(res-la+1)/2)*k[X]+1ull*bb[X]*(res-la+1);
                // cout<<la<<','<<res<<" -> "<<i<<" zhuanyi!\n";
                // rep(p,la,res)
                    // sm+=1ull*k[X]*p+1ull*bb[X];
                la=res+1;
            }
        }
        // cout<<top<<" :\n";
		// rep(g,i,ans){
		// 	__int128 mx=0;
        //     rep(i,1,n)
		// 		mx=max(mx,(__int128)k[i]*g+bb[i]);
        //     // rep(i,1,ct)
		// 		// if ((__int128)k[i]*g+bb[i]==mx) cout<<i<<' ';
		// 	sm+=mx;
		// }
        // cout<<'\n';
		i=ans;
	}
	cout<<sm<<'\n';
}
signed main(){
    // freopen("yuanshen.in","r",stdin);
    // freopen("yuanshen.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int t=1;
	// cin>>t;
	while (t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

3 5
3 1 5 2
4 2 1 3
1 9 100 1

output:

113

result:

ok single line: '113'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

3 100000000
3 1 5 2
4 2 1 3
1 9 100 1

output:

35000000549999998

result:

ok single line: '35000000549999998'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3648kb

input:

10 1000000000000000000
776874380544333 197 471391764744275 33
159838820333814 107 677112662750393 41
962335658276824 48 255593531071176 11
127404116579775 209 268525254990127 34
647620110614714 76 897947476313307 13
146196843402516 221 772928712898807 39
637929916804442 2 716937021892338 15
64200226...

output:

9063007984388543404

result:

wrong answer 1st lines differ - expected: '17883317185357051350', found: '9063007984388543404'