QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103263 | #2211. IOI Problem Revised | Unique_Hanpi | AC ✓ | 622ms | 31548kb | C++14 | 4.7kb | 2023-05-04 21:42:12 | 2025-02-07 14:38:26 |
Judging History
This is the latest submission verdict.
- [2025-02-07 14:35:59]
- hack成功,自动添加数据
- (/hack/1532)
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-05-04 21:42:12]
- Submitted
answer
//路径交错
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 4e5+5;
const int Mod = 998244353;
int n, k;
int p[N * 2];
ll L, a[N], s[N], mn, f[N];
vector<int> x;
vector<ll> ans;
inline ll w(int l, int r) {
int m1 = (l + r) >> 1;
int m2 = (l + r - 1) >> 1;
return s[r] - s[m1] - s[m2] + s[l - 1];
}
namespace wqs {
int head, tail;
ll g[N], c[2][N];
struct info {
int l, r, p;
} Q[N];
inline bool cmp(int i, int j, int k, bool t) {
ll fi = g[i] + w(i + 1, k), fj = g[j] + w(j + 1, k);
return fi < fj || (!t && fi == fj);
}
inline int chk(ll v, bool t) {
Q[head = tail = 1] = (info) { 1, n, 0 };
for (int i = 1; i <= n; i++) {
g[i] = g[Q[head].p] + v + w(Q[head].p + 1, i);
c[t][i] = c[t][Q[head].p] + 1;
if (Q[head].r < i + 1) head++;
Q[head].l = i + 1;
while (head <= tail && !cmp(Q[tail].p, i, Q[tail].l, t)) tail--;
if (head > tail) {
Q[++tail] = (info) { i + 1, n, i };
} else {
int L = Q[tail].l + 1, R = Q[tail].r, ans = R + 1;
while (L <= R) {
int mid = (L + R) >> 1;
if (!cmp(Q[tail].p, i, mid, t)) ans = mid, R = mid - 1;
else L = mid + 1;
}
Q[tail].r = ans - 1;
if (ans <= n) Q[++tail] = (info) { ans, n, i };
}
}
return c[0][n];
}
inline void work() {
ll L = 0, R = 1e18, ans = R + 1;
while (L <= R) {
ll mid = (L + R) >> 1;
if (chk(mid, 0) <= k) ans = mid, R = mid - 1;
else L = mid + 1;
}
chk(ans, 0);
chk(ans, 1);
mn = g[n] - ans * k;
//构造方案
int cur = 0, lst = n;
for (int i = n - 1; ~i; i--)
if (g[i] + ans + w(i + 1, lst) == g[lst] && cur + 1 + c[0][i] <= k && k <= cur + 1 + c[1][i])
cur++, x.pb(lst = i);
reverse(x.begin(), x.end());
x.pb(n);
}
}
void solve(int l, int r, int L, int R, int d) {
if (l > r) return;
int mid = (l + r) >> 1;
ll g = 1e18;
for (int i = L; i <= min(mid, R); i++) {
ll tmp = f[i] + w(i + 1, mid);
if (tmp <= g) g = tmp, p[mid + d] = i;
}
solve(mid + 1, r, p[mid + d], R, d);
solve(l, mid - 1, L, p[mid + d], d);
f[mid] = g;
}
void solve(vector<int> L, vector<int> R) {
if (L[0] > R[0]) return;
int mid = (L[0] + R[0]) >> 1;
for (int i = L[1]; i <= R[1]; i++) f[i] = w(mid + 1, i), p[i + 1] = mid;
for (int i = 2; i < k; i++) solve(L[i], R[i], L[i - 1], R[i - 1], i);
solve(mid + n, mid + n, L[k - 1], R[k - 1], k);
vector<int> md(0);
int cur = mid + n, ck = k;
while (ck--) md.pb(cur = p[cur + ck + 1]);
reverse(md.begin(), md.end());
md.pb(mid + n);
// puts("-----------");
// printf("%lld\n", f[mid + n]);
// for (int i : md) printf("%d ", i);
// puts("\n------------");
if (f[mid + n] < mn) {
mn = f[mid + n];
x = md;
}
md[0]--;
solve(L, md);
md[0] += 2;
solve(md, R);
}
int main() {
scanf("%d%d%lld", &n, &k, &L);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), s[i] = s[i - 1] + a[i];
for (int i = n + 1; i <= 2 * n; i++) a[i] = a[i - n] + L, s[i] = s[i - 1] + a[i];
if (k == 1) {
int ans = 1;
for (int i = 2; i <= n; i++) if (w(i, i + n - 1) < w(ans, ans + n - 1)) ans = i;
printf("%lld\n", w(ans, ans + n - 1));
printf("%lld", a[ans + (n - 1) / 2] % L);
return 0;
}
wqs::work();
// printf("%lld\n", mn);
// for (int i : x) printf("%d ", i); puts("");
int id = 1;
for (int i = 1; i <= k; i++)
if (x[i] - x[i - 1] < x[id] - x[id - 1]) id = i;
vector<int> tl(k + 1), tr(k + 1);
tl[0] = x[id - 1] + (id == 1);
tr[0] = x[id];
for (int i = id + 1; i <= k; i++) tl[i - id] = x[i - 1], tr[i - id] = x[i];
for (int i = 1; i < id; i++) tl[k - id + i] = x[i - 1] + n, tr[k - id + i] = x[i] + n;
// for (int i : tl) printf("%d ", i); puts("");
// for (int i : tr) printf("%d ", i); puts("");
solve(tl, tr);
printf("%lld\n", mn);
for (int i = 1; i <= k; i++) ans.pb(a[(x[i] + x[i - 1] + 1) >> 1] % L);
sort(ans.begin(), ans.end());
for (ll i : ans) printf("%lld ", i);
return 0;
}
/*
5 3 10
0 1 3 7 9
*/
这程序好像有点Bug,我给组数据试试?
Details
Test #1:
score: 100
Accepted
time: 0ms
memory: 10060kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 10064kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 10064kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 9936kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 10060kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 10064kb
Test #7:
score: 0
Accepted
time: 1ms
memory: 9936kb
Test #8:
score: 0
Accepted
time: 1ms
memory: 10064kb
Test #9:
score: 0
Accepted
time: 7ms
memory: 10196kb
Test #10:
score: 0
Accepted
time: 4ms
memory: 10188kb
Test #11:
score: 0
Accepted
time: 79ms
memory: 11472kb
Test #12:
score: 0
Accepted
time: 67ms
memory: 11856kb
Test #13:
score: 0
Accepted
time: 84ms
memory: 13504kb
Test #14:
score: 0
Accepted
time: 68ms
memory: 13392kb
Test #15:
score: 0
Accepted
time: 79ms
memory: 13336kb
Test #16:
score: 0
Accepted
time: 455ms
memory: 26940kb
Test #17:
score: 0
Accepted
time: 499ms
memory: 27500kb
Test #18:
score: 0
Accepted
time: 499ms
memory: 28572kb
Test #19:
score: 0
Accepted
time: 571ms
memory: 23780kb
Test #20:
score: 0
Accepted
time: 448ms
memory: 27708kb
Test #21:
score: 0
Accepted
time: 455ms
memory: 30092kb
Test #22:
score: 0
Accepted
time: 437ms
memory: 30176kb
Test #23:
score: 0
Accepted
time: 529ms
memory: 27312kb
Test #24:
score: 0
Accepted
time: 509ms
memory: 26892kb
Test #25:
score: 0
Accepted
time: 491ms
memory: 28564kb
Test #26:
score: 0
Accepted
time: 532ms
memory: 26468kb
Test #27:
score: 0
Accepted
time: 529ms
memory: 24828kb
Test #28:
score: 0
Accepted
time: 490ms
memory: 27692kb
Test #29:
score: 0
Accepted
time: 545ms
memory: 23300kb
Test #30:
score: 0
Accepted
time: 409ms
memory: 29324kb
Test #31:
score: 0
Accepted
time: 473ms
memory: 29408kb
Test #32:
score: 0
Accepted
time: 451ms
memory: 27744kb
Test #33:
score: 0
Accepted
time: 448ms
memory: 29704kb
Test #34:
score: 0
Accepted
time: 485ms
memory: 28248kb
Test #35:
score: 0
Accepted
time: 460ms
memory: 26980kb
Test #36:
score: 0
Accepted
time: 420ms
memory: 31548kb
Test #37:
score: 0
Accepted
time: 471ms
memory: 29920kb
Test #38:
score: 0
Accepted
time: 443ms
memory: 31544kb
Test #39:
score: 0
Accepted
time: 573ms
memory: 23588kb
Test #40:
score: 0
Accepted
time: 431ms
memory: 30244kb
Test #41:
score: 0
Accepted
time: 579ms
memory: 22568kb
Test #42:
score: 0
Accepted
time: 461ms
memory: 28056kb
Test #43:
score: 0
Accepted
time: 563ms
memory: 25124kb
Test #44:
score: 0
Accepted
time: 436ms
memory: 29968kb
Test #45:
score: 0
Accepted
time: 419ms
memory: 30708kb
Test #46:
score: 0
Accepted
time: 446ms
memory: 27700kb
Test #47:
score: 0
Accepted
time: 521ms
memory: 24900kb
Test #48:
score: 0
Accepted
time: 551ms
memory: 24760kb
Test #49:
score: 0
Accepted
time: 564ms
memory: 24428kb
Test #50:
score: 0
Accepted
time: 478ms
memory: 27976kb
Test #51:
score: 0
Accepted
time: 469ms
memory: 26576kb
Test #52:
score: 0
Accepted
time: 470ms
memory: 30036kb
Test #53:
score: 0
Accepted
time: 537ms
memory: 26256kb
Test #54:
score: 0
Accepted
time: 539ms
memory: 25156kb
Test #55:
score: 0
Accepted
time: 455ms
memory: 30996kb
Test #56:
score: 0
Accepted
time: 559ms
memory: 24236kb
Test #57:
score: 0
Accepted
time: 546ms
memory: 23940kb
Test #58:
score: 0
Accepted
time: 541ms
memory: 24564kb
Test #59:
score: 0
Accepted
time: 493ms
memory: 25864kb
Test #60:
score: 0
Accepted
time: 411ms
memory: 30552kb
Test #61:
score: 0
Accepted
time: 532ms
memory: 25356kb
Test #62:
score: 0
Accepted
time: 493ms
memory: 25284kb
Test #63:
score: 0
Accepted
time: 574ms
memory: 23292kb
Test #64:
score: 0
Accepted
time: 414ms
memory: 31216kb
Test #65:
score: 0
Accepted
time: 597ms
memory: 24160kb
Test #66:
score: 0
Accepted
time: 589ms
memory: 25632kb
Test #67:
score: 0
Accepted
time: 568ms
memory: 26556kb
Test #68:
score: 0
Accepted
time: 574ms
memory: 27808kb
Test #69:
score: 0
Accepted
time: 616ms
memory: 21772kb
Test #70:
score: 0
Accepted
time: 622ms
memory: 24100kb
Test #71:
score: 0
Accepted
time: 616ms
memory: 25108kb
Test #72:
score: 0
Accepted
time: 602ms
memory: 21952kb
Extra Test:
score: 0
Extra Test Passed