QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#194310 | #7520. Monster Generator | ucup-team191# | TL | 1ms | 3932kb | C++23 | 6.5kb | 2023-09-30 20:04:59 | 2023-11-04 18:36:29 |
Judging History
你现在查看的是最新测评结果
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-09-30 20:04:59]
- 提交
answer
//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcountll
#define all(a) begin(a),end(a)
//for kactl
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
cout<<w.size()<<en;
for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
if (w.size()) cout<<w[w.size()-1]<<en;
if (fl) cout<<flush;
}
void M998()
{
swap(MOD,MOD2);
}
ll raand()
{
ll a=rund();
a*=RAND_MAX;
a+=rund();
return a;
}
#define rand raand
ll raaand()
{
return raand()*(MOD-7)+raand();
}
template<class T>
vi compress(vector<T>&v)
{
set<T> s;
for (auto a: v) s.insert(a);
vector<T> o(all(s));
vi nv;
for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
return nv;
}
string to_upper(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
return a;
}
string to_lower(string a)
{
for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
return a;
}
ll sti(string a,int base=10)
{
ll k=0;
for (int i=0;i<(int)a.size();++i)
{
k*=base;
k+=a[i]-'0';
}
return k;
}
template<class T>
void eras(vector<T>& a,T b)
{
a.erase(find(a.begin(),a.end(),b));
}
string its(ll k,int base=10)
{
if (k==0) return "0";
string a;
while (k)
{
a.push_back((k%base)+'0');
k/=base;
}
reverse(a.begin(),a.end());
return a;
}
ll min(ll a,int b)
{
if (a<b) return a;
return b;
}
ll min(int a,ll b)
{
if (a<b) return a;
return b;
}
ll max(ll a,int b)
{
if (a>b) return a;
return b;
}
ll max(int a,ll b)
{
if (a>b) return a;
return b;
}
ll gcd(ll a,ll b)
{
if (b==0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
template<class T,class K>
pair<T,K> mp(T a,K b)
{
return make_pair(a,b);
}
inline int mult(ll a,ll b)
{
return (a*b)%MOD;
}
inline int pot(int n,int k)
{
if (k==0) return 1;
ll a=pot(n,k/2);
a=mult(a,a);
if (k%2) return mult(a,n);
else return a;
}
int divide(int a,int b)
{
return mult(a,pot(b,MOD-2));
}
inline int sub(int a,int b)
{
if (a-b>=0) return a-b;
return a-b+MOD;
}
inline int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
void ad(int&a,int b)
{
a+=b;
if (a>=MOD) a-=MOD;
}
void su(int&a,int b)
{
a-=b;
if (a<0) a+=MOD;
}
bool prime(ll a)
{
if (a==1) return 0;
for (int i=2;i<=round(sqrt(a));++i)
{
if (a%i==0) return 0;
}
return 1;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=310;
int n;
ll m,a[N],da[N],b[N],db[N],le[N][N];
__int128 jed=1;
bool man(pll a,pll b)
{
return a.x*jed*b.y<b.x*jed*a.y;
}
ll cei(pll a)
{
if (a.y==0) while(1);
if (a.x<0) return a.x/a.y;
else return (a.x+a.y-1)/a.y;
}
bool cmp(pair<pll,pii> a,pair<pll,pii> b)
{
return man(b.x,a.x);
}
int geMi(int a,int b)
{
if (le[a][b]) return a;
return b;
}
bool cmp2(pii a,pii b)
{
return le[geMi(a.x,a.y)][geMi(b.x,b.y)];
}
ull solvePos(ll poc,ll kra)
{
vector<pii> po;
for (int i=0;i<n;++i) po.pb({i*2,i*2+1});
sort(all(po),cmp2);
vi nap,nak;
for (auto x: po)
{
if (le[x.x][x.y]) nap.pb(x.x/2);
else nak.pb(x.x/2);
}
vi ord=nap;
reverse(all(nak));
for (auto x: nak) ord.pb(x);
//cout<<"order made"<<endl;
vector<pll> v;
ll ca=0,cb=0;
for (int i=0;i<n;++i)
{
ca+=da[ord[i]];
cb+=a[ord[i]];
v.pb({ca,cb});
ca-=db[ord[i]];
cb-=b[ord[i]];
}
sort(all(v));
vector<pll> nv;
for (int i=0;i<n;++i)
{
bool ok=1;
if (i<n-1 && v[i+1].x==v[i].x && v[i+1].y>v[i].y) ok=0;
if (ok) nv.pb(v[i]);
}
//for (auto x: nv) cout<<"UN"<<x.x<<' '<<x.y<<en;
//cout<<endl;
vector<pair<pll,pll>> no;
no.pb({nv[0],{-LLINF,1}});
for (int i=1;i<(int)nv.size();++i)
{
pll inte={no.back().x.y-nv[i].y,nv[i].x-no.back().x.x};
while (no.size() && man(inte,no.back().y))
{
no.pop_back();
inte={no.back().x.y-nv[i].y,nv[i].x-no.back().x.x};
}
no.pb({nv[i],inte});
}
ull od=0;
for (int i=0;i<(int)no.size();++i)
{
ll po=cei(no[i].y),kr;
if (i<(int)no.size()-1) kr=cei(no[i+1].y)-1;
else kr=m;
po=max(po,0ll);
po=max(po,poc);
kr=min(kr,m);
kr=min(kr,kra);
if (po>kr) continue;
ull a=kr-po+1,b=kr+po;
od+=a*ull(no[i].x.y);
if (a%2) b/=2;
else a/=2;
od+=a*b*ull(no[i].x.x);
}
return od;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
cin>>n>>m;
//n=100;
//m=1e18;
vector<pair<pll,int>> bro;
uniform_int_distribution<ll> ud(0,1e15);
for (int i=0;i<n;++i)
{
cin>>a[i]>>da[i]>>b[i]>>db[i];
//a[i]=ud(rng);
//b[i]=ud(rng);
//da[i]=ud(rng);
//db[i]=ud(rng);
bro.pb({{da[i],a[i]},i*2});
bro.pb({{db[i],b[i]},i*2+1});
}
vector<pair<pll,pii>> inter;
sort(all(bro));
for (int i=0;i<2*n;++i) for (int j=i+1;j<2*n;++j)
{
if (bro[i].x.x!=bro[j].x.x) inter.pb({{bro[i].x.y-bro[j].x.y,bro[j].x.x-bro[i].x.x},{i,j}});
le[bro[i].y][bro[j].y]=1;
le[bro[j].y][bro[i].y]=0;
}
sort(all(inter),cmp);
ull od=0;
if (inter.empty()) od+=solvePos(-LLINF,LLINF);
else
{
od+=solvePos(cei(inter[0].x),LLINF);
//cout<<"U"<<endl;
for (int i=0;i<(int)inter.size();++i)
{
int p1=inter[i].y.x,p2=inter[i].y.y;
le[bro[p1].y][bro[p2].y]^=1;
le[bro[p2].y][bro[p1].y]^=1;
ll poc;
if (i<(int)inter.size()-1) poc=cei(inter[i+1].x);
else poc=-LLINF;
//cout<<poc<<' '<<cei(inter[i].x)-1<<' '<<od<<endl;
//cout<<p1<<' '<<p2<<en;
if (poc<=cei(inter[i].x)-1)
{
//cout<<"WO"<<en;
od+=solvePos(poc,cei(inter[i].x)-1);
}
}
}
cout<<od<<en;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3804kb
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: 0
Accepted
time: 0ms
memory: 3932kb
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:
17883317185357051350
result:
ok single line: '17883317185357051350'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
10 1000000000000 519946 5 967590 4 367668 9 772494 6 635694 5 932710 1 260259 2 627580 1 84994 3 52124 6 447095 4 705749 6 427312 2 977458 7 540121 1 292993 5 556831 6 321679 4 567919 4 609512 4
output:
1542003553318518337
result:
ok single line: '1542003553318518337'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
10 1000000000000000000 972703917532605 2 524956306619424 679 644953227221677 4 562488807303931 696 726248880302017 2 678581164692315 811 63290732871341 4 2359762326353 451 355584232678496 3 295959529542702 895 982076563374348 4 315626935294595 161 202583559712801 1 987516708328993 170 26590404960673...
output:
4582284981606185217
result:
ok single line: '4582284981606185217'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
10 1000000000000000000 915236950983 25 924829121702 314 142125786492 33 125091250839 71 702305171043 11 468800042449 438 449646370235 9 56198959092 472 246955215365 12 950417123809 62 646952653060 4 858914642874 441 693754630072 34 490226765023 91 273330383457 25 749838451697 371 635897703553 24 847...
output:
18304932886689493500
result:
ok single line: '18304932886689493500'
Test #7:
score: -100
Time Limit Exceeded
input:
100 1000000000000000000 839671173511709 107 620743247548148 134 338569457755976 9 455191878916920 157 56529874788057 33 993208347666256 99 553193266380324 120 589361808163439 126 866467572275902 19 13931460152331 210 630774124991101 56 253227140072409 133 970610042608501 106 332792633317838 252 8813...