QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#421 | #194135 | #7520. Monster Generator | zhaohaikun | ucup-team1447 | Failed. | 2023-11-04 16:33:11 | 2023-11-04 16:33:12 |
Details
Extra Test:
Accepted
time: 0ms
memory: 19388kb
input:
2 1 2 3 2 5 5 5 4 5
output:
15
result:
ok single line: '15'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#194135 | #7520. Monster Generator | ucup-team1447# | WA | 16ms | 21148kb | C++14 | 4.5kb | 2023-09-30 19:15:20 | 2023-11-04 18:36:27 |
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define int __int128
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f3f3f3f3f
/*
-a.fi +a.se
a.fi<a.se ::: a.fi xiaode
a.fi>a.se ::: a.se dade
*/
bool cmp(pii a,pii b){
if((a.fi<a.se)!=(b.fi<b.se))return a.fi<a.se;
return a.fi<a.se?a.fi<b.fi:a.se>b.se;
}
pii operator +(pii a,pii b){
return mkp(max(a.fi,b.fi-a.se),a.se+b.se);
}
int n,m;
struct line{
int k,b;
line(int x=0,int y=0){k=x,b=y;}
line operator +(line o){return line(k+o.k,b+o.b);}
line operator -(line o){return line(k-o.k,b-o.b);}
void add(int v){b+=k*v;}
int F(int x){return k*x+b;}
};
line inter(line a,line b,int&x){
if(a.k<b.k||(a.k==b.k&&a.b<b.b))swap(a,b);
if(a.b>=b.b)return a;
x=min(x,(b.b-a.b)/(a.k-b.k));
return b;
}
line a[maxn],b[maxn];
int t[maxn],len;
ull res;
int id[maxn];
pii qwq[maxn];
#define pll pair<line,line>
pll merge(pll a,pll b,int&t){
pll c;
c.se=a.se+b.se;
c.fi=inter(a.fi,b.fi-a.se,t);
return c;
}
void work(int l,int r)
{
// [l,r)
For(i,1,n)id[i]=i,qwq[i]=mkp(a[i].F(l),b[i].F(l));
auto cmpqwq=[&](int x,int y){
return cmp(qwq[x],qwq[y]);
};
sort(id+1,id+n+1,cmpqwq);
// cout<<"qwq "<<l<<" "<<r<<"\n";
// For(j,l,r){
// For(i,1,n)qwq[i]=mkp(a[i].F(j),b[i].F(j)-a[i].F(j));
// pii now={0,0};
// For(i,1,n)now=now+qwq[id[i]];
// res+=now.fi;
// }return;
int lstl=l;
while(l<=r){
int tim=inf;
pll now={{0,0},{0,0}};
For(i,1,n) {
line t1=a[id[i]]; t1.add(l);
line t2=(b[id[i]]-a[id[i]]); t2.add(l);
now=merge(now,{t1,t2},tim);
}
tim=min(tim,r-l);
// For(i,0,tim)res+=now.fi.k*i;
res+=(ull)now.fi.b*((ull)tim+1);
ull add=((__int128)tim*(tim+1)/2);
res+=(ull)now.fi.k*add;
// cout<<"l,tim "<<l<<" "<<tim<<" "<<r<<"\n";
l+=tim+1;
}
}
signed main()
{
// freopen("data.in","r",stdin);
n=read(),m=read();
t[++len]=0,t[++len]=m+1;
For(i,1,n){
a[i].b=read(),a[i].k=read(),b[i].b=read(),b[i].k=read();
// b[i].b-=a[i].b;
// b[i].k-=a[i].k;
int tmp=inf;
inter(a[i],b[i],tmp);
if(tmp<=m) t[++len]=tmp+1;
}
For(i,1,n)
For(j,i+1,n){
int tmp=inf;
inter(a[i],a[j],tmp);
if(tmp<=m) t[++len]=tmp+1;
tmp=inf;
inter(b[i],b[j],tmp);
if(tmp<=m) t[++len]=tmp+1;
}
sort(t+1,t+len+1),len=unique(t+1,t+len+1)-t;
// puts("QWQ");
For(i,1,len-1) work(t[i],t[i+1]-1);
cout<<res;
return 0;
}
/*
3 5
3 1 5 2
4 2 1 3
1 9 100 1
*/