QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#193816 | #7520. Monster Generator | ucup-team1004# | WA | 0ms | 3620kb | C++14 | 3.1kb | 2023-09-30 17:55:51 | 2023-09-30 17:55:51 |
Judging History
你现在查看的是测评时间为 2023-09-30 17:55:51 的历史记录
- [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 17:55:51]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e2+10,M=N*N*2;
const ll INF=2e18;
using ull=unsigned long long;
using LL=__int128;
const LL mod=(LL)1<<64;
ostream& operator << (ostream &out,LL x){
if(x<0)out<<'-',x=-x;
if(x>9)out<<x/10;
return out<<char(x%10+48);
}
int n,k;
ll m,a[N],ka[N],b[N],kb[N],c[M];
LL lower(LL x,LL y){
if(y<0)x=-x,y=-y;
if(x>=0)return x/y;
else return (x-y+1)/y;
}
LL upper(LL x,LL y){
if(y<0)x=-x,y=-y;
if(x>=0)return (x+y-1)/y;
else return x/y;
}
ull ans;
int cur[N];
LL A[N],B[N],p[N],q[N];
bool cmp(int x,int y){
int t1=A[x]<=B[x],t2=A[y]<=B[y];
if(t1^t2)return t1;
else if(t1)return A[x]<A[y];
else return B[x]>B[y];
}
int top,stk[N];
ull sum(ll l,ll r){
return LL(l+r)*(r-l+1)/2%mod;
}
void solve(ll l,ll r){
iota(cur,cur+1+n,0);
for(int i=1;i<=n;i++){
A[i]=a[i]+(LL)l*ka[i];
B[i]=b[i]+(LL)l*kb[i];
};
sort(cur+1,cur+1+n,cmp);
LL s1=0,s2=0;
p[0]=q[0]=0;
for(int x=1,i;i=cur[x],x<=n;x++){
q[i]=s1-A[i],p[i]=s2-ka[i];
s1+=B[i]-A[i],s2+=kb[i]-ka[i];
// debug(p[i],q[i]);
}
iota(cur,cur+1+n,0);
sort(cur,cur+1+n,[](int x,int y){
return p[x]^p[y]?p[x]>p[y]:q[x]<q[y];
});
auto calc=[&](int i,int j){
return lower(q[j]-q[i],p[i]-p[j]);
};
top=0;
for(int x=0,i;i=cur[x],x<=n;x++){
if(top&&p[i]==p[stk[top]])continue;
for(;top>1&&calc(stk[top-1],stk[top])>=calc(stk[top],i);top--);
stk[++top]=i;
}
// for(int i=1;i<=top;i++)debug(p[stk[i]],q[stk[i]]);
ll las=-1,lim=r-l;
// debug(l,r,ary(p,0,n),ary(q,0,n));
for(int i=1;i<=top;i++){
if(las>=lim)continue;
ll r=i<top?calc(stk[i],stk[i+1]):INF;
r=min(r,lim);
ll l=max(las+1,0ll);
if(l<=r){
int x=stk[i];
// debug(l,r,::calc(l,r),p[x]%mod,q[x]%mod,ans);
ans-=sum(l,r)*ull(p[x]%mod);
ans-=ull((r-l+1)%mod)*ull(q[x]%mod);
}
las=r;
}
// debug(r,ans);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i]>>ka[i]>>b[i]>>kb[i];
c[++k]=0;
for(int i=1;i<=n;i++){
if(a[i]<=b[i]&&ka[i]<kb[i]){
c[++k]=upper(b[i]-a[i]+1,kb[i]-ka[i]);
}else if(a[i]>b[i]&&ka[i]>kb[i]){
c[++k]=upper(a[i]-b[i],ka[i]-kb[i]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==j)continue;
if(a[i]<a[j]&&ka[i]>ka[j]){
c[++k]=upper(a[j]-a[i],ka[i]-ka[j]);
}else if(a[i]>a[j]&&ka[i]<ka[j]){
c[++k]=upper(a[i]-a[j],ka[j]-ka[i]);
}
if(b[i]<b[j]&&kb[i]>kb[j]){
c[++k]=upper(b[j]-b[i],kb[i]-kb[j]);
}else if(b[i]>b[j]&&kb[i]<kb[j]){
c[++k]=upper(b[i]-b[j],kb[j]-kb[i]);
}
}
}
sort(c+1,c+1+k);
for(;k&&c[k]>m;k--);
k=unique(c+1,c+1+k)-c-1;
c[k+1]=m+1;
for(int i=1;i<=k;i++){
solve(c[i],c[i+1]-1);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
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: 3620kb
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: 3568kb
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:
8596169764396037558
result:
wrong answer 1st lines differ - expected: '17883317185357051350', found: '8596169764396037558'