QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200812 | #5123. Streets | 275307894a | TL | 0ms | 8924kb | C++14 | 2.3kb | 2023-10-04 20:30:19 | 2023-10-04 20:30:20 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=2.1e4+5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-6;const int INF=1e9+7;mt19937 rnd(263082);
int n,m,T,A[N],B[N],f[N];
pii X[N],Y[N];int Xh,Yh;
int fa[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
vector<int> S[N];int pre[N];
ll C;
ll dd(ll x,ll y){return (x+y-1)/y;}
void Add(int x,int ti){
int y=GF(x-1);if(!y) return;
if(1ll*X[x].se*X[y].fi>=1ll*X[y].se*X[x].fi) return;
ll w=dd(C*X[x].fi-C*X[y].fi,1ll*X[y].se*X[x].fi-1ll*X[x].se*X[y].fi);
if(w>Y[Yh].fi) return;
S[pre[w]].emplace_back(x);
}
void Solve(){
int i,j;scanf("%d%d%d",&n,&m,&T);
for(i=1;i<=n;i++) scanf("%d",&A[i]);for(i=1;i<=n;i++) scanf("%d",&B[i]);
Me(f,0x3f);for(i=1;i<=n;i++) for(j=i;j<=n;j++) f[A[j]-A[i]]=min(f[A[j]-A[i]],B[i]+B[j]);
for(i=1;i<=1e5;i++) if(f[i]<=1e8) X[++Xh]=make_pair(i,f[i]);
for(i=1;i<=m;i++) scanf("%d",&A[i]);for(i=1;i<=m;i++) scanf("%d",&B[i]);
Me(f,0x3f);for(i=1;i<=m;i++) for(j=i;j<=m;j++) f[A[j]-A[i]]=min(f[A[j]-A[i]],B[i]+B[j]);
for(i=1;i<=1e5;i++) if(f[i]<=1e8) Y[++Yh]=make_pair(i,f[i]);
cerr<<Xh<<' '<<Yh<<'\n';
for(i=1;i<=Yh;i++) fill(pre+Y[i-1].fi+1,pre+Y[i].fi+1,i);
while(T--){
scanf("%lld",&C);ll ans=0;
iota(fa+1,fa+Xh+1,1);for(i=1;i<=Yh;i++) S[i].clear();
for(i=2;i<=Xh;i++) Add(i,0);
for(i=1;i<=Yh;i++) {
for(int j=0;j<S[i].size();j++){
int p=S[i][j];if(fa[p]^p) continue;
int y=GF(p-1);if(!y) continue;
if((C-1ll*Y[i].fi*X[y].se)*X[p].fi>(C-1ll*Y[i].fi*X[p].se)*X[y].fi) continue;
fa[y]=y-1;Add(p,i);
}
int l=0,r=Xh+1,mid;
db p=-1e18;
while(l+1<r) mid=l+r>>1,(!GF(mid)||C-1ll*Y[i].fi*X[GF(mid)].se>=1ll*X[GF(mid)].fi*Y[i].se?l:r)=mid;
if(GF(l)) ans=max(ans,1ll*Y[i].fi*X[GF(l)].fi);
}
printf("%lld\n",ans);
if(n==4998&&T==50) exit(0);
}
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8924kb
input:
3 4 20 1 3 4 3 1 2 1 3 4 7 4 2 1 2 1 5 6 7 9 10 11 12 15 16 17 22 23 28 30 35 43 47 49 57
output:
0 0 1 1 1 2 2 3 3 4 4 6 6 9 9 12 12 12 18 18
result:
ok 20 numbers
Test #2:
score: -100
Time Limit Exceeded
input:
4995 4998 100 4 7 20 34 44 100 102 130 175 198 205 250 257 259 267 278 300 324 337 346 353 364 403 427 439 440 451 523 532 534 555 599 634 639 756 802 805 825 855 859 890 905 912 915 953 989 1014 1031 1052 1059 1097 1124 1183 1216 1297 1308 1337 1342 1361 1392 1400 1421 1451 1471 1523 1537 1542 1619...
output:
9991201920 9941157660 8387550150 9892186440 9803600290 9986903784 9928424616 9892186440 9831470090 9768930402 9831470090 9058876564 9803600290 9857548260 9944740920 9892186440 9885418060 9831470090 9857548260 9768930402 8671693002 9803600290 9911595765 9058876564 9803600290 9838238470 9024072106 980...