QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751415#9252. Penguins in RefrigeratorxxzxWA 7ms62932kbC++142.9kb2024-11-15 18:34:442024-11-15 18:34:52

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 18:34:52]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:62932kb
  • [2024-11-15 18:34:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define clo 1000.*clock()/CLOCKS_PER_SEC
#ifndef xxzx
#define endl '\n'
#endif
using ll=long long;
using PII=pair<int,int>;
const int N=1e6+10;
const ll Mod=1e9+7;
bool memory1;
int n,W,p[N],a[N],b[N],s[N];
int st[N],top,L[N],R[N];
vector<int> eg[N],g[N];
int vis[N],sz[N],deg[N];
void dfs(int x) {
    sz[x]=vis[x]=1;
    for(auto y:eg[x]) dfs(y),sz[x]+=sz[y];
}
bool memory2;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    cin>>n>>W;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    for(int i=1;i<=n;i++) a[i]=b[p[i]];
    // for(int i=1;i<=n;i++) cerr<<a[i]<<" ";
    // cerr<<endl;
    st[++top]=0;
    for(int i=1,lst=0;i<=n;i++) {
        s[i]=s[i-1]+(a[i]>W/2);
        if(a[i]<=W/2) {
            int l=1,r=top+1;
            while(l+1<r) {
                int mid=(l+r)>>1;
                if(a[st[mid]]+a[i]>W) l=mid;
                else r=mid;
            }
            L[i]=st[l];
        }
        else {
            while(top>1&&a[st[top]]<a[i]) top--;
            st[++top]=i;
            g[p[lst]].push_back(p[i]),deg[p[i]]++;
            lst=i;
        }
    }
    s[n+1]=s[n]+1;
    top=0;
    st[++top]=n+1;
    for(int i=n;i>=1;i--) {
        if(a[i]<=W/2) {
            int l=1,r=top+1;
            while(l+1<r) {
                int mid=(l+r)>>1;
                if(a[st[mid]]+a[i]>W) l=mid;
                else r=mid;
            }
            R[i]=st[l];
        }
        else {
            while(top>1&&a[st[top]]<a[i]) top--;
            st[++top]=i;
        }
    }
    vector<PII> seg;
    for(int i=1;i<=n;i++) if(a[i]<=W/2) seg.emplace_back(L[i],R[i]);
    sort(seg.begin(),seg.end(),[](const PII &x,const PII &y) {
        return (x.second==y.second)? x.first>y.first:x.second<y.second;
    });
    top=0;
    for(int i=0;i<(int)seg.size();i++) {
        while(top&&seg[st[top]].first>=seg[i].first) eg[i].push_back(st[top--]);
        st[++top]=i;
    }
    for(int i=(int)seg.size()-1;i>=0;i--) if(!vis[i]) dfs(i);
    ll ans=1;
    for(int i=0;i<(int)seg.size();i++) {
        int len=s[seg[i].second]-s[seg[i].first]-1+sz[i];
        // cerr<<seg[i].first<<" "<<seg[i].second<<" "<<sz[i]<<" "<<len<<endl;
        ans=ans*len%Mod;
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;i++) if(a[i]<=W/2) {
        g[p[L[i]]].push_back(p[i]),deg[p[i]]++;
        g[p[i]].push_back(p[R[i]]),deg[p[R[i]]]++;
    }
    priority_queue<int,vector<int>,greater<int>> q;
    q.push(0);
    while(q.size()) {
        int x=q.top(); q.pop();
        if(x) cout<<x<<" ";
        for(auto y:g[x]) {
            deg[y]--;
            if(!deg[y]) q.push(y);
        }
    }
    cout<<endl;

    #ifdef xxzx
    cerr<<"Time: "<<clo<<"MS"<<endl;
    cerr<<"Memory: "<<abs(&memory1-&memory2)/1024./1024.<<"MB"<<endl;
    #endif
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 62932kb

input:

5 10
1 2 3 4 5
6 5 3 9 2

output:

3
1 2 3 4 5 

result:

wrong answer 2nd lines differ - expected: '5 4 2 1 3', found: '1 2 3 4 5 '