QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717860 | #9252. Penguins in Refrigerator | zyxawa | WA | 61ms | 96592kb | C++14 | 1.6kb | 2024-11-06 19:08:11 | 2024-11-06 19:08: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[i]),p[i]=n-p[i]+1,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: 4ms
memory: 83996kb
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: 83320kb
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: 3ms
memory: 83796kb
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: 12ms
memory: 83040kb
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: 61ms
memory: 96592kb
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: 50ms
memory: 94252kb
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:
236427755 2126 4067 5194 7897 11204 13655 23867 25144 26319 26501 28710 33176 35681 37825 50885 57578 58859 60458 64892 66474 67478 67718 70635 73256 76518 79326 87426 88363 89335 92390 92556 99165 12244 81095 72282 29952 11811 12286 14477 18290 19728 25502 34067 46675 49220 51062 58025 67861 83739 ...
result:
wrong answer 1st lines differ - expected: '524727018', found: '236427755'