QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196951 | #7520. Monster Generator | ucup-team134 | WA | 0ms | 3860kb | C++14 | 3.4kb | 2023-10-02 05:02:29 | 2023-10-02 05:02:29 |
Judging History
你现在查看的是测评时间为 2023-10-02 05:02:29 的历史记录
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-10-02 05:02:29]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define ull uint64_t
#define ll int64_t
#define pb push_back
const int N=105;
ll a[N],da[N],b[N],db[N];
int n;
ll m;
ll whenOne[N],whenTwo[N][N];
ll L;
bool cmp(int i,int j){
if(a[i]<a[j] || (a[i]==a[j] && i<j)){
if(whenTwo[i][j]<=L)return false;
return true;
}else{
if(whenTwo[i][j]<=L)return true;
return false;
}
}
ll When(array<ll,2> f1,array<ll,2> f2){
ll p=f1[0]-f2[0];
ll q=f2[1]-f1[1];
if(q<0)q=-q,p=-p;
if(p>=0)return (p+q-1)/q;
return p/q;
}
ull S2(ll x){
ull a=x;
ull b=x+1;
if(a%2==0)a/=2;
else b/=2;
return a*b;
}
ull ans=0;
void Solve(ll L,ll R){
::L=L;
vector<int> fir,sec,ord;
for(int i=1;i<=n;i++){
if(a[i]<=b[i]){
if(whenOne[i]<=L){
sec.pb(i);
}else{
fir.pb(i);
}
}else{
if(whenOne[i]<=L){
fir.pb(i);
}else{
sec.pb(i);
}
}
}
sort(fir.begin(),fir.end(),cmp);
sort(sec.begin(),sec.end(),cmp);
//reverse(sec.begin(),sec.end());
for(int i:fir)ord.pb(i);
for(int i:sec)ord.pb(i);
//printf("Solve %lld - %lld\n",L,R);
//for(int i:ord)printf("%i ",i);
//printf("\n");
vector<array<ll,2>> func(n);
ll sumA=0,sumDA=0,sumB=0,sumDB=0;
for(int i=0;i<n;i++){
sumA+=a[ord[i]];
sumDA+=da[ord[i]];
func[i]={sumA-sumB,sumDA-sumDB};
//printf("%lld + k * %lld\n",func[i][0],func[i][1]);
sumB+=b[ord[i]];
sumDB+=db[ord[i]];
}
sort(func.begin(),func.end(),[&](array<ll,2> a,array<ll,2> b){return a[1]<b[1];});
vector<array<ll,2>> hull;
for(array<ll,2> f:func){
if(hull.size() && hull.back()[1]==f[1]){
if(hull.back()[0]<f[0]){
hull.pop_back();
}else{
continue;
}
}
while(hull.size()>1){
int sz=hull.size();
if(When(hull[sz-1],f)<=When(hull[sz-2],hull[sz-1])){
hull.pop_back();
}else{
break;
}
}
hull.pb(f);
}
ll last=L;
for(int i=0;i<hull.size();i++){
ll now;
if(i+1==hull.size()){
now=R;
}else{
now=When(hull[i],hull[i+1])-1;
}
if(max(L,last)<=min(R,now)){
ll l=max(L,last);
ll r=min(R,now);
ans+=(ull)(r-l+1)*((ull)hull[i][0]);
ans+=(S2(r)-S2(l-1))*((ull)hull[i][1]);
//printf("Best at %lld - %lld\n",l,r);
//printf("%lld + k * %lld\n",hull[i][0],hull[i][1]);
//printf("ans: %llu\n",ans);
}
last=now+1;
}
}
int main(){
scanf("%i %lld",&n,&m);
vector<ll> evs;
for(int i=1;i<=n;i++){
scanf("%lld %lld %lld %lld",&a[i],&da[i],&b[i],&db[i]);
whenOne[i]=m+1;
if(a[i]<=b[i]){
if(da[i]>db[i]){
ll p=b[i]-a[i];
ll q=da[i]-db[i];
evs.pb((p+q)/q);
whenOne[i]=evs.back();
}
}else{
if(da[i]<db[i]){
ll p=a[i]-b[i];
ll q=db[i]-da[i];
evs.pb((p+q-1)/q);
whenOne[i]=evs.back();
}
}
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
whenTwo[i][j]=whenTwo[j][i]=m+1;
if(a[i]<=a[j]){
if(da[i]>da[j]){
ll p=a[j]-a[i];
ll q=da[i]-da[j];
evs.pb((p+q)/q);
whenTwo[i][j]=whenTwo[j][i]=evs.back();
}
}else{
if(da[i]<da[j]){
ll p=a[i]-a[j];
ll q=da[j]-da[i];
evs.pb((p+q-1)/q);
whenTwo[i][j]=whenTwo[j][i]=evs.back();
}
}
}
}
evs.pb(0);
sort(evs.begin(),evs.end());
evs.erase(unique(evs.begin(),evs.end()),evs.end());
while(evs.back()>m)evs.pop_back();
evs.pb(m+1);
for(int i=0;i+1<evs.size();i++){
Solve(evs[i],evs[i+1]-1);
}
printf("%llu\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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: 3768kb
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: 0ms
memory: 3860kb
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:
14699092849019022070
result:
wrong answer 1st lines differ - expected: '17883317185357051350', found: '14699092849019022070'