QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#420#191101#7520. Monster Generatorzhaohaikunucup-team055Success!2023-11-04 16:28:082023-11-04 16:28:09

详细

Extra Test:

Wrong Answer
time: 0ms
memory: 3776kb

input:

2 0
3 4 1 1
3 2 3 2

output:

0

result:

wrong answer 1st lines differ - expected: '3', found: '0'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#191101#7520. Monster Generatorucup-team055#WA 585ms4264kbC++172.9kb2023-09-29 17:56:062023-11-04 18:36:01

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(p) p.begin(),p.end()
using ll =long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

void solve(){
    ll N,M;
    cin>>N>>M;
    vector<ll> A(N),B(N),C(N),D(N);
    rep(i,0,N) cin>>A[i]>>B[i]>>C[i]>>D[i];
    set<ll> s;
    rep(i,0,N){
        if(B[i]==D[i]) continue;
        ll X=A[i]-C[i],Y=D[i]-B[i];
        if(Y<0) X*=-1,Y*=-1;
        if(X<0||Y==0) continue;
        s.insert(X/Y);
        s.insert(X/Y+1);
    }
    rep(rp,0,2){
        swap(A,C),swap(B,D);
        rep(i,0,N) rep(j,i+1,N){
            ll X=A[i]-A[j],Y=B[j]-B[i];
            if(Y<0) X*=-1,Y*=-1;
            if(X<0||Y==0) continue;
            s.insert(X/Y);
            s.insert(X/Y+1);
        }
    }
    s.insert(M+1);
    s.insert(0);
    using l8=__int128;
    l8 ans=0;
    while(true){
        ll L=(*s.begin());
        s.erase(L);
        if(L<0) continue;
        if(L==M+1) break;
        ll R=(*s.begin());
        vector<int> order(N);
        rep(i,0,N) order[i]=i;
        vector<l8> S(N),T(N);
        rep(i,0,N){
            S[i]=(l8)(A[i])*(l8)(2)+(l8)(B[i])*(l8)(L+R-1);
            T[i]=(l8)(C[i])*(l8)(2)+(l8)(D[i])*(l8)(L+R-1);
        }
        sort(all(order),[&](int l,int r){
            if((-S[l]+T[l]>=0)^(-S[r]+T[r]>=0)){
                return (-S[l]+T[l]>=0);
            }
            if(-S[l]+T[l]>=0){
                return S[l]<S[r];
            }
            return T[l]>T[r];
        });
        vector<l8> X(N),Y(N);
        rep(i,0,N){
            int a=order[i];
            X[i]-=A[a];
            Y[i]-=B[a];
            if(i!=N-1){
                X[i+1]=X[i]+C[a];
                Y[i+1]=Y[i]+D[a];
            }
        }
        rep(i,0,N){
            l8 l=L,r=R;
            rep(j,0,N){
                if(i==j) continue;
                l8 tmp1=X[j]-X[i],tmp2=Y[i]-Y[j];
                if(tmp2==0){
                    if(tmp1==0&&j<i) r=-1;
                    if(tmp1<0) r=-1;
                }
                else if(tmp2>0){
                    if(tmp1<=0) r=-1;
                    else{
                        r=min(r,(tmp1-(l8)(j<i))/tmp2+1);
                    }
                }
                else{
                    tmp1*=-1,tmp2*=-1;
                    if(tmp1>0||(tmp1==0&&j<i)){
                        l=max(l,(tmp1-(l8)(j>i))/tmp2+1);
                    }
                }
            }
            if(l<r){
                ans-=(((r-l)*(r-1+l))/2)*Y[i]+X[i]*(r-l);
            }
        }
    }
    unsigned long long out=0;
    rep(i,0,64){
        if(ans&((l8)(1)<<i)) out+=(1ULL<<i);
    }
    cout<<out<<"\n";
}
/*
 *
3 5
3 1 5 2
4 2 1 3
1 9 100 1
 *
 */
int main(){
    solve();
}