QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760927 | #9252. Penguins in Refrigerator | wcyQwQ | WA | 9ms | 36328kb | C++14 | 1.6kb | 2024-11-18 20:13:12 | 2024-11-18 20:13:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, mod = 1e9 + 7;
int p[N], w[N], q[N], n, m, in[N];
vector<int> g[N];
struct Bs {
int t[N];
void add(int x) {
for (; x <= n; x += x & -x) t[x]++;
}
int ask(int x) {
int ans = 0;
for (; x; x -= x & -x) ans += t[x];
return ans;
}
int ask(int l, int r) { return ask(r) - ask(l - 1); }
} tr;
int main() {
// freopen("1.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> p[i];
for (int i = 1; i <= n; i++) cin >> w[i];
iota(q + 1, q + n + 1, 1);
sort(q + 1, q + n + 1, [&](int i, int j) { return w[p[i]] > w[p[j]]; });
int ans = 1;
set<int> s;
for (int i = 0; i <= n + 1; i++) s.insert(i);
int lst = 0;
for (int i = 1; i <= n; i++) {
if (w[p[i]] * 2 > m) {
if (lst) g[p[i]].emplace_back(p[lst]), in[q[lst]]++;
lst = i;
}
}
for (int i = 1, j = n; i <= n; i++) {
while (j && w[p[q[j]]] + w[p[q[i]]] <= m) s.erase(q[j--]);
if (w[p[q[i]]] * 2 > m) tr.add(q[i]);
else {
int L = *prev(s.lower_bound(q[i])), R = *s.upper_bound(q[i]);
if (L) g[p[q[i]]].emplace_back(p[L]), in[p[L]]++;
if (R <= n) g[p[R]].emplace_back(p[q[i]]), in[p[q[i]]]++;
ans = 1ll * ans * (tr.ask(L + 1, R - 1) + 1) % mod;
tr.add(q[i]);
}
}
cout << ans << '\n';
priority_queue<int, vector<int>, greater<int>> q;
for (int i = 1; i <= n; i++) if (!in[i]) q.emplace(i);
while (q.size()) {
int u = q.top();
q.pop();
cout << u << ' ';
for (int v : g[u]) if (!--in[v]) q.emplace(v);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 9ms
memory: 36328kb
input:
5 10 1 2 3 4 5 6 5 3 9 2
output:
3 5
result:
wrong answer 2nd lines differ - expected: '5 4 2 1 3', found: '5 '