QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#144306 | #5710. Solar Flight | lmeowdn | 0 | 2ms | 13512kb | C++14 | 3.4kb | 2023-08-21 16:14:34 | 2023-08-21 16:14:41 |
Judging History
answer
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
template<typename T,typename U> T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U> T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S> bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S> bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=1e6+5;
const ld inf=1e18,eps=1e-11;
int n,X,k,m,s[N],id[N],tot,ans[N];
deque<pair<int,ld>> d[2005];
struct Line {int a,b,c,id;} a[N];
struct Opt {ld t; int x,y,id;} q[N*3];
bool operator < (const Line &a,const Line &b) {
return a.a<b.a;
}
bool operator < (const Opt &a,const Opt &b) {
return a.t==b.t?a.id>b.id:a.t<b.t;
}
void add(int x,int val,ld t) {
pair<int,ld> s=make_pair(val,inf);
while(d[x].size()&&d[x].back()<s) d[x].pop_back();
//cout<<"ADD "<<x<<" "<<val<<" "<<t<<endl;
if(d[x].size()) {
auto r=d[x].back(); d[x].pop_back();
chmin(r.se,t); d[x].push_back(r);
} d[x].push_back(s);
}
signed main() {
X=read(), k=read(), n=read(), m=read();
rep(i,1,n) {
a[i].a=read(), a[i].b=read();
a[i].c=read(), a[i].id=i;
}
sort(a+1,a+n+1);
rep(i,1,n) id[a[i].id]=i;
per(i,n,1) s[i]=s[i+1]+a[i+1].c;
//rep(i,1,n) cout<<a[i].a<<" "<<a[i].b<<" "<<a[i].c<<endl;
rep(i,1,n) rep(j,i+1,n) if(a[i].b>a[j].b) {
ld t=1.*X*(a[j].a-a[i].a)/(a[j].a-a[i].a+a[i].b-a[j].b);
q[++tot]={t,i,j,0};
//cout<<" "<<t<<" "<<i<<" "<<j<<endl;
}
rep(i,1,m) {
int x=read(), y=read();
q[++tot]={y+k,id[x],0,i};
//cout<<" "<<y<<" "<<y+k<<" "<<id[x]<<endl;
}
sort(q+1,q+tot+1);
rep(i,1,n) d[i].push_back(make_pair(s[i],inf));
rep(i,1,tot) {
//cout<<i<<" "<<q[i].id<<" "<<q[i].t<<endl;
if(!q[i].id) {
vi used; ld tt=q[i].t;
static int vst[2005];
while(!q[i].id&&q[i].t<tt+eps) {
s[q[i].x]-=a[q[i].y].c;
s[q[i].y]+=a[q[i].x].c;
if(!vst[q[i].x]) used.eb(q[i].x), vst[q[i].x]=1;
if(!vst[q[i].y]) used.eb(q[i].y), vst[q[i].y]=1;
i++;
}
//cout<<"MDF "<<tt<<endl;
for(int x:used) add(x,s[x],tt), vst[x]=0;
//for(int x:used) cout<<" "<<x<<" "<<s[x]<<endl;
}
while(q[i].id) {
int st=q[i].t-k, x=q[i].x;
//cout<<st<<endl;
//cout<<d[x][0].fi<<" "<<d[x][0].se<<endl;
while(d[x].size()&&d[x][0].se<=st+eps) d[x].pop_front();
//cout<<" QRY "<<d[x][0].fi<<" "<<d[x][0].se<<endl;
ans[q[i].id]=d[x][0].fi;
i++;
}
i--;
}
rep(i,1,m) printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 10
Accepted
time: 2ms
memory: 13512kb
input:
1000 200 200 1000 657 836 23 962 796 47 497 305 25 837 161 23 220 575 33 697 109 37 401 221 43 883 211 46 727 461 26 681 209 28 413 14 49 664 986 27 431 222 47 307 121 38 638 560 45 801 149 24 878 61 36 761 356 43 839 413 32 931 573 35 218 195 46 201 697 25 951 778 21 705 905 42 861 391 23 582 718 2...
output:
6049 5822 2542 5950 1152 2947 2697 2357 1219 3428 1366 6013 6215 3869 2344 2630 2619 2303 4412 6066 6597 1631 6657 3093 3199 1315 2441 1501 6146 2171 3160 1032 2914 4234 692 5058 3177 3283 5036 1702 3169 1024 6614 1568 5133 2269 4032 877 6458 4609 6270 1564 877 3155 2783 3172 6136 4958 2563 3579 602...
result:
ok 1000 lines
Test #2:
score: -10
Runtime Error
input:
10000 4000 800 1000 75657 83836 780 11962 49796 629 89497 1305 816 49837 85161 195 28220 87575 587 68697 54109 882 68401 71221 247 51883 49211 198 76727 74461 213 88681 89209 368 94413 98014 967 53664 32986 885 46431 19222 982 74307 9121 350 1638 41560 377 95801 76149 593 75878 8061 102 17761 83356 ...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%