QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717869 | #9252. Penguins in Refrigerator | zyxawa | WA | 53ms | 96516kb | C++14 | 1.6kb | 2024-11-06 19:09:10 | 2024-11-06 19:09:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,x,lst,p[2000001],w[2000001],a[2000001],b[2000001],L[2000001],R[2000001],st[2000001][21],t[2000001],ind[2000001];
long long s=1;
basic_string <int> G[2000001];
priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
const int mod=1e9+7;
int query(int l,int r){
int k=__lg(r-l+1);
return max(st[l][k],st[r-(1<<k)+1][k]);
}
bool cmp(int x,int y){
return w[x]>w[y];
}
void add(int i){
for(;i<=n;i+=i&-i) t[i]++;
}
int ask(int i){
int s=0;
for(;i;i-=i&-i) s+=t[i];
return s;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&p[n-i+1]);
for(int i=1;i<=n;i++) b[i]=i,a[p[i]]=i;
for(int i=1;i<=n;i++) scanf("%d",&x),w[a[i]]=x;
for(int i=1;i<=n;i++) st[i][0]=w[i];
for(int k=1;k<=20;k++) for(int i=1;i+(1<<k)-1<=n;i++) st[i][k]=max(st[i][k-1],st[i+(1<<k-1)][k-1]);
for(int i=1;i<=n;i++){
if(w[i]>m/2) continue;
int l=1,r=i;
while(l<r){
int mid=(l+r)/2;
if(query(mid,i-1)+w[i]>m) l=mid+1;
else r=mid;
}
L[i]=l-1,l=i,r=n;
while(l<r){
int mid=(l+r+1)/2;
if(query(i+1,mid)+w[i]>m) r=mid-1;
else l=mid;
}
R[i]=l+1,G[L[i]]+=i,G[i]+=R[i],ind[i]++,ind[R[i]]++;
}
sort(b+1,b+1+n,cmp);
for(int i=1;i<=n;i++){
if(w[i]>m/2) G[lst]+=i,lst=i,ind[i]++;
add(b[i]);
if(w[b[i]]<=m/2) s=s*(ask(R[b[i]]-1)-ask(L[b[i]]))%mod;
}
for(int i=0;i<=n;i++) if(!ind[i]) q.push({a[i],i});
printf("%lld\n",s);
while(q.size()){
auto [k,x]=q.top();
q.pop();
if(k) printf("%d ",k);
for(int y:G[x]) if(!--ind[y]) q.push({a[y],y});
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 82928kb
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: 3ms
memory: 83260kb
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: 84148kb
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: 7ms
memory: 83820kb
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: 50ms
memory: 96516kb
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: -100
Wrong Answer
time: 53ms
memory: 94128kb
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 145 11263 17870 19749 22066 23114 25774 27739 29095 47783 50271 70858 72899 76475 76601 25263 81713 69836 3538 4767 4801 7510 13275 20618 32558 40150 48270 48497 48518 56859 66976 71496 74905 82513 82635 87360 90020 90334 92000 92151 12092 314 4527 34163 38612 45369 69723 71021 78113 84293...
result:
wrong answer 2nd lines differ - expected: '1723 2800 15421 26278 31659 42...6 87226 93330 98177 26739 49668', found: '145 11263 17870 19749 22066 23...49 71291 836 76134 97875 98792 '