QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#68037 | #4583. Concerto de Pandemic | karuna | WA | 2ms | 3536kb | C++17 | 3.8kb | 2022-12-14 09:40:12 | 2022-12-14 09:40:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 202020;
int n, m, k, P, a[N], b[N], g[N], vis[N];
pair<int, int> c[N], d[2 * N];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> m >> k >> P;
for (int i = 0; i < m; i++) {
int x; cin >> x;
cin >> a[x - 1];
}
for (int i = 0; i < k; i++) {
int x; cin >> x;
b[x - 1] = 1;
}
auto go = [&](int x) {
return (x == n - 1) ? 0 : x + 1;
};
auto rev = [&](int x) {
return (x == 0) ? n - 1 : x - 1;
};
auto dist = [&](int i, int j) {
return (j >= i) ? j - i : n + j - i;
};
ll L = 0, R = 2e10;
while (L < R) {
ll M = (L + R) / 2;
ll s = 0, p = 0, sz = 0;
for (int i = 0, j = 0; i < n; i++) {
if (i == j) {
if (!a[j]) p = j;
j = go(j);
s += a[j] + 1;
}
while (i != j && s <= M) {
if (!a[j]) p = j;
j = go(j);
s += a[j] + 1;
}
if (b[i]) c[sz++].second = p;
if (i != n - 1) {
s -= a[go(i)] + 1;
}
}
s = 0; p = 0;
for (int i = n - 1, j = n - 1; i >= 0; i--) {
if (i == j) {
if (!a[j]) p = j;
j = rev(j);
s += a[j] + 1;
}
while (i != j && s <= M) {
if (!a[j]) p = j;
j = rev(j);
s += a[j] + 1;
}
if (b[i]) c[--sz].first = p;
if (i != 0) {
s -= a[rev(i)] + 1;
}
}
sz = 0; int tz = 0;
for (int i = 0; i < n; i++) if (b[i]) {
auto [l, r] = c[sz++];
if (dist(i, r) + dist(l, i) >= n - 1) {
continue;
}
swap(c[tz++], c[sz - 1]);
}
if (tz == 0) {
R = M;
continue;
}
sz = 0;
for (int i = 0; i < tz; i++) {
while (i && c[i].first < c[i - 1].first) {
c[i].first += n;
c[i].second += n;
}
while (c[i].second < c[i].first) {
c[i].second += n;
}
while (sz && c[i].second <= d[sz - 1].second) {
--sz;
}
d[sz++] = c[i];
}
for (int i = 0; i < sz; i++) {
d[i + sz] = d[i];
d[i + sz].first += n;
d[i + sz].second += n;
}
for (int i = 0, j = 0; i < sz; i++) {
if (i == j) ++j;
while (j < 2 * sz && d[j].first <= d[i].second) {
++j;
}
g[i] = j;
}
bool f = false;
for (int i = 0; i < sz; i++) {
if (i == g[i] % sz) f = true;
if (d[i].first + n <= d[g[i]].second) f = true;
}
if (f) {
R = M;
continue;
}
int y = -1;
fill(vis, vis + sz, 0);
for (int i = 0; i < sz; i++) {
if (vis[i]) continue;
int x = i;
while (!vis[x]) {
vis[x] = 1;
x = g[x] % sz;
if (vis[x] == 1) {
y = x;
}
}
x = i;
while (vis[x] == 1) {
vis[x] = 2;
x = g[x] % sz;
}
}
int ans = 1, x = y;
while (y != x && d[y].first + n > d[g[x]].second) {
++ans;
x = g[x];
}
if (ans <= P) R = M;
else L = M + 1;
}
cout << L;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3536kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
0
result:
wrong answer 1st lines differ - expected: '4', found: '0'