QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640481 | #9252. Penguins in Refrigerator | ucup-team4153 | RE | 86ms | 38100kb | C++20 | 3.4kb | 2024-10-14 13:29:51 | 2024-10-14 13:29:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;using i128=__int128;using ull=unsigned long long;using ld=long double;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pdd=pair<ld,ld>;
const int M=1e9+7,N=1e6+10;const ll inf=1e17;const ld eps=1e-10;
clock_t ct;bool ot;int tct=0;
void oT(char c='.'){cout<<c<<"Time:"<<double(clock()-ct)<<'\n';}
struct calcC{//precal needed
ll poww(ll bs,ll x){ll res=1;for(bs=(bs%M+M)%M;x;x>>=1,(bs*=bs)%=M)if(x&1)(res*=bs)%=M;return res;}
ll invv(ll bs){return poww(bs,M-2);}vector<ll>mul,inv;
void precal(int P){mul.resize(P+1);mul[0]=1;for(int i=1;i<=P;i++)mul[i]=mul[i-1]*i%M;
inv.resize(P+1);inv[P]=invv(mul[P]);for(int i=P;i;i--)inv[i-1]=inv[i]*i%M;}
ll C(int n,int m){if(n<m||m<0)return 0;return mul[n]*inv[m]%M*inv[n-m]%M;}
ll A(int n,int m){if(n<m||m<0)return 0;return mul[n]*inv[n-m]%M;}
}xC;
struct S
{
int n,lim,pt=0;set<int>xS;ll res=1;
vector<int>h,l,r,f,rk,toseg;vector<vector<int>>es,sd,spe;
vector<int>cc;
void Ade(int u,int v)
{
u=rk[u],v=rk[v];
//cout<<u<<"->"<<v<<'\n';
spe[u].push_back(v);cc[v]++;
}
void gnew(int u,int _l,int _r)
{
es[u].push_back(++pt);f[pt]=u;
l[pt]=_l;r[pt]=_r;toseg[_r]=pt;
}
int spr(int x)
{
sort(es[x].begin(),es[x].end(),[&](int a,int b){return r[a]<r[b];});
int esz=es[x].size();
if(esz)
{
//for(int i=0;i<esz-1;i++)if(r[es[x][i]]^l[es[x][i+1]])
{
//cout<<x<<'/'<<l[x]<<','<<r[x]<<'\n';
//exit(1);
}
if(l[es[x][0]]!=l[x])
{
int y=es[x][0];
cout<<x<<'/'<<l[x]<<','<<r[x]<<"(L)"<<y<<'/'<<l[y]<<','<<r[y]<<"\n";
}
if(r[es[x].back()]!=r[x])
{
int y=es[x].back();
cout<<x<<'/'<<l[x]<<','<<r[x]<<"(R)"<<y<<'/'<<l[y]<<','<<r[y]<<"\n";
}
}
int spz=sd[x].size(),siz=bool(es[x].size());for(auto&k:es[x])siz+=spr(k);siz+=spz;
//cout<<x<<":"<<"["<<l[x]<<","<<r[x]<<"]"<<"&"<<f[x]<<"&"<<siz<<'/'<<spz<<"\n";
(res*=xC.A(siz,spz))%=M;return siz;
}
void ini()
{
cin>>n>>lim;vector<int>g(n+2,0);l=r=f=toseg=rk=h=cc=g;es.resize(n+2);sd=spe=es;
for(int i=n,x;i;i--)cin>>rk[i];for(int i=1;i<=n;i++)cin>>g[i];
for(int i=n,x;i;i--)x=rk[i],h[i]=g[x];h[0]=h[n+1]=M;
//cout<<"rk:";for(int i=1;i<=n;i++)cout<<rk[i]<<".\n"[i==n];
//cout<<"h:";for(int i=1;i<=n;i++)cout<<h[i]<<".\n"[i==n];
pt=0;l[0]=rk[0]=0,r[0]=rk[n+1]=n+1,f[0]=0;xS.insert(0);xS.insert(n+1);toseg[n+1]=0;
for(int i=1,lst=0;i<=n+1;i++)if(h[i]*2>lim)Ade(lst,i),lst=i;
priority_queue<pii>Q;
for(int i=1,lst=0;i<=n;i++)
{
if(h[i]*2<=lim)Q.push({(lim-h[i])*2+1,i});
else Q.push({h[i]*2,i});
}
while(!Q.empty())
{
auto[_,x]=Q.top();Q.pop();int sp=abs(_)&1;
auto ite=xS.lower_bound(x);int rd=*ite,sg=toseg[rd];
//cout<<x<<"^"<<sp<<','<<rd<<'/'<<sg<<'\n';
if(sp){sd[sg].push_back(x);Ade(x,rd);Ade(*--ite,x);continue;}
xS.insert(x);gnew(sg,l[sg],x),gnew(sg,x,r[sg]);
}
spr(0);cout<<res<<"\n";
}
void solve()
{
priority_queue<int>Q;Q.push(0);vector<int>res;
while(!Q.empty())
{
auto x=Q.top();Q.pop();x=-x;res.push_back(x);
for(auto&k:spe[x])if(!--cc[k])Q.push(-k);
}
for(int i=1;i<=n;i++)cout<<res[i]<<" \n"[i==n];
}
};
void precal(){xC.precal(N);}
int main()
{
//freopen("1.in","r",stdin);
//cout<<fixed<<setprecision(12);
ct=clock();
ios::sync_with_stdio(0);cin.tie(0);precal();
int t=1;//cin>>t;
//clock_t a=clock();
while(t--){tct++;S SS;SS.ini();SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 18732kb
input:
5 10 1 2 3 4 5 6 5 3 9 2
output:
3 5 4 2 1 3
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 8ms
memory: 18816kb
input:
5 10 1 2 3 4 5 2 4 3 3 8
output:
30 1 5 2 3 4
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 11ms
memory: 18804kb
input:
5 10 1 2 3 4 5 2 3 4 5 1
output:
120 1 2 3 4 5
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 11ms
memory: 18856kb
input:
5 10 1 2 3 4 5 2 3 4 5 6
output:
60 1 2 3 5 4
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 55ms
memory: 33800kb
input:
100000 96 1996 78922 45321 68844 32404 82013 66552 81163 17216 48170 35495 56660 13480 43118 23173 47257 50168 87069 26167 67231 31758 25694 61063 56642 8923 7727 54528 96554 38964 7604 6822 16256 45300 58869 31359 48638 87645 14779 81505 59585 89293 9291 7002 31810 84701 77648 78295 42595 11394 479...
output:
457992974 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
result:
ok 2 lines
Test #6:
score: 0
Accepted
time: 68ms
memory: 35708kb
input:
100000 84 93330 3894 94859 22134 49668 30606 26739 82976 76701 56323 75537 7626 87226 20857 98177 21811 70827 75898 8111 48223 26186 64222 63002 79024 19126 41638 1048 43857 25379 19764 60207 27675 77665 66327 6274 34861 30287 13449 64505 51490 5804 65843 49014 85795 12365 31565 34411 71697 66568 28...
output:
524727018 1723 2800 15421 26278 31659 42502 42606 56945 60694 62369 70160 73990 80586 88502 89122 59690 27661 33622 94788 14089 1146 2690 3632 4491 5439 8588 17476 17922 18136 20123 24857 39523 18825 28520 30999 32947 36013 41413 43842 43919 54502 58104 60783 65767 69064 71878 74728 75343 76546 7807...
result:
ok 2 lines
Test #7:
score: 0
Accepted
time: 86ms
memory: 38100kb
input:
100000 87 300 88662 44078 62834 3753 7407 33249 23452 84415 76976 83633 97611 16701 2788 75559 56876 65161 78422 41095 40238 89019 95291 81242 34629 35820 2766 266 62909 53458 60609 92867 7751 43644 89656 46268 73554 29490 91474 42521 66646 22973 36675 3527 66659 6283 65870 56067 93748 94932 45445 3...
output:
474454223 16291 67920 66350 36657 80297 50836 75962 67504 74275 82684 44748 18794 20817 23451 67820 94633 35098 26272 62387 64130 97543 95388 6171 41925 9995 21720 51796 81891 29780 53247 63390 78398 10287 31830 44454 46864 63394 76771 87042 17437 8412 58246 18774 97383 36854 4632 32575 64180 48940 ...
result:
ok 2 lines
Test #8:
score: -100
Runtime Error
input:
100000 100 55629 14377 79945 51098 90204 3853 3177 32017 78776 91382 20382 74435 13483 67713 43513 69929 15961 6388 48752 94868 14114 90543 87776 22290 94148 14665 67822 15542 37889 31214 53405 58817 74349 80153 50913 24099 84889 86056 59976 40327 59231 97231 45030 99883 57171 7168 60283 46638 6697 ...