QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#144336 | #5710. Solar Flight | lmeowdn | 0 | 416ms | 152964kb | C++14 | 3.0kb | 2023-08-21 16:19:22 | 2023-08-21 16:19:24 |
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();
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) 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};
}
rep(i,1,m) {
int x=read(), y=read();
q[++tot]={y+k,id[x],0,i};
}
sort(q+1,q+tot+1);
rep(i,1,n) d[i].push_back(make_pair(s[i],inf));
rep(i,1,tot) {
if(!q[i].id) {
vi used; ld tt=q[i].t;
static int vst[2005];
while(i<=tot&&!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++;
}
for(int x:used) add(x,s[x],tt), vst[x]=0;
}
while(i<=tot&&q[i].id) {
int st=q[i].t-k, x=q[i].x;
while(d[x].size()&&d[x][0].se<=st+eps) d[x].pop_front();
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
Time Limit Exceeded
Test #1:
score: 10
Accepted
time: 5ms
memory: 11588kb
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: 0
Accepted
time: 30ms
memory: 22128kb
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:
66998 372651 71882 230931 117149 150398 355375 284731 10168 280887 314284 339928 385864 37803 408137 106909 273581 236358 396850 199550 414114 154206 241347 242637 89623 303605 301758 406078 286813 367590 279934 316532 315289 368177 294903 60588 306179 175416 178653 73606 123438 53572 263464 367797 ...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 223ms
memory: 83348kb
input:
100000 70000 2000 1000 75657 83836 2448100 11962 49796 1600996 89497 1305 2781211 49837 85161 1601062 28220 87575 1329028 68697 54109 2237292 68401 71221 2499307 51883 49211 1775046 76727 74461 2974020 88681 89209 2445860 94413 98014 1700919 53664 32986 2402956 46431 19222 1747481 74307 9121 1615935...
output:
2934379373 2922891391 3515422029 1450321827 1129612500 3943378704 2626723334 2565897601 3834435831 2545857081 2191434562 2238840383 3935335833 2981615579 706657489 2832999972 3381170831 2019351908 2449239345 3300400809 3012385670 3834105878 3707015903 3470161116 985251429 3822861893 596146397 918148...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 416ms
memory: 152964kb
input:
10000001 3000003 2000 1000 50 999947 783585127 95 999907 794505200 164 999891 680508956 229 999861 543263639 244 999849 889154272 325 999780 588428698 394 999749 596808712 460 999691 512172704 521 999670 646367223 592 999658 705991625 678 999565 664968144 767 999558 972852236 848 999494 964463766 93...
output:
1240513824931 1173388781740 824850620980 712840060845 1318911118904 39152826164 763158769681 1217277671244 576924223978 549671580423 1150059359951 66314878130 1337783770468 534664640455 1352506482924 1177552008572 905271273726 320514241628 867265875305 1235343030806 1118906688022 1093648045220 11305...
result:
ok 1000 lines
Test #5:
score: -10
Time Limit Exceeded
input:
1000000000 543212345 2000 1000 999951415 107406 176163935 999914991 275150 745519734 999832082 425326 314874995 999729085 466864 118662252 999611779 501976 207009093 999475536 573247 57066144 999357075 589628 279583004 999163538 761929 797445536 999152542 961710 723813350 998964573 970121 361676627 ...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%