QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#886609 | #2211. IOI Problem Revised | HuTao | AC ✓ | 1084ms | 53360kb | C++14 | 3.9kb | 2025-02-07 10:03:08 | 2025-02-07 14:43:58 |
Judging History
This is the latest submission verdict.
- [2025-02-07 14:35:59]
- hack成功,自动添加数据
- (/hack/1532)
- [2025-02-07 10:03:08]
- Submitted
answer
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef __int128 i128;
const int N = 4e5 + 5;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, k;
LL l, a[N], sa[N];
i128 f[N];
int c0[N], c1[N];
int p[N], rp[N];
LL ans;
struct Range{
int l, r, k;
}q[N];
int hh, tt;
inline i128 W(int i, int j)
{
int mid = (i + j + 1) >> 1;
return i == j ? INF : f[i] + (sa[j] - sa[mid]) - (sa[mid] - sa[i]) + a[mid] * ((mid - i) - (j - mid));
}
inline bool Solve(LL d, int c[])
{
q[hh = tt = 0] = {1, n, 0};
for(int i = 1; i <= n; i ++ )
{
f[i] = W(q[hh].k, i) - d;
c[i] = c[q[hh].k] + 1;
q[hh].l ++ ;
if(q[hh].l > q[hh].r) hh ++ ;
while(hh <= tt && W(i, q[tt].l) < W(q[tt].k, q[tt].l)) tt -- ;
if(hh > tt) q[hh = tt = 0] = {i + 1, n, i};
else
{
int L = q[tt].l, R = q[tt].r + 1, Mid;
while(L < R)
{
Mid = (L + R) >> 1;
if(W(i, Mid) < W(q[tt].k, Mid)) R = Mid;
else L = Mid + 1;
}
q[tt].r = L - 1;
if(L <= n) q[ ++ tt] = {L, n, i};
}
}
return c[n] <= k;
}
inline void Get()
{
LL L = -2e17, R = 0, Mid;
while(L < R)
{
Mid = (L + R + 1) >> 1;
if(Solve(Mid, c0)) L = Mid;
else R = Mid - 1;
}
Solve(L + 1, c1);
Solve(L, c0);
ans = f[n] + (i128)L * k;
p[k] = n;
for(int i = n - 1, j = n, t = k - 1; i >= 0; i -- )
{
if(c0[i] <= t && t <= c1[i] && W(i, j) - L == f[j])
{
j = p[t -- ] = i;
}
}
}
LL g[N];
int pre[N];
vector<int> pp[N];
inline void Solve(int l, int r, int L, int R)
{
if(l > r) return ;
if(L == R)
{
for(int i = l; i <= r; i ++ )
{
g[i] = W(L, i);
pre[i] = L;
}
return ;
}
int mid = (l + r) >> 1, p = L;
i128 w = INF;
for(int i = L; i <= R; i ++ )
{
if(W(i, mid) < w)
{
w = W(i, mid);
p = i;
}
}
g[mid] = w, pre[mid] = p;
Solve(l, mid - 1, L, p);
Solve(mid + 1, r, p, R);
}
inline void Solve(vector<pair<int, int> > p)
{
if(p[0].fi > p[0].se) return ;
int l = p[0].fi, r = p[0].se, mid = (l + r) >> 1;
p[0].fi = p[0].se = mid;
p.emplace_back(mid + n, mid + n);
// for(int i = 0; i <= k; i ++ ) printf("(%d %d) ", p[i].fi, p[i].se);
// puts("");
f[mid] = 0;
for(int i = 1; i <= k; i ++ )
{
Solve(p[i].fi, p[i].se, p[i - 1].fi, p[i - 1].se);
for(int j = p[i].fi; j <= p[i].se; j ++ ) f[j] = g[j];
pp[i] = vector<int>(pre + p[i].fi, pre + p[i].se + 1);
}
p[0] = {l, r}, p[k] = {l + n, r + n};
vector<pair<int, int> > p1(p);
p1.pop_back();
for(int i = k - 1, j = pre[mid + n]; i >= 0; j = i ? pp[i][j - p[i].fi] : 0, i -- )
{
p1[i].fi = p[i].fi;
p1[i].se = j;
}
if(f[mid + n] < ans)
{
ans = f[mid + n];
for(int i = 0; i < k; i ++ ) rp[i] = p1[i].se;
rp[k] = mid + n;
}
// for(int i = 0; i < k; i ++ ) printf("%d ", p1[i].se);
// puts("");
assert(p1[0].se == mid);
p1[0].se -- ;
Solve(p1);
for(int i = 0; i < k; i ++ )
{
p1[i].fi = p1[i].se;
p1[i].se = p[i].se;
}
p1[0].fi += 2;
Solve(p1);
}
LL rr[N];
int main()
{
scanf("%d%d%lld", &n, &k, &l);
for(int i = 1; i <= n; i ++ ) scanf("%lld", &a[i]), a[n + i] = a[i] + l;
for(int i = 1; i <= n * 2; i ++ ) sa[i] = sa[i - 1] + a[i];
Get();
for(int i = 0; i <= k; i ++ ) rp[i] = p[i], p[i + k] = p[i] + n;
// printf("!%lld\n", ans);
// for(int i = 0; i <= k; i ++ ) printf("%d ", p[i]);
// puts("");
int t = 0;
for(int i = 1; i < k; i ++ )
if(p[i + 1] - p[i] < p[t + 1] - p[t])
t = i;
vector<pair<int, int> > p1;
for(int i = 0; i < k; i ++ ) p1.emplace_back(p[i + t], p[i + t + 1]);
Solve(p1);
printf("%lld\n", ans);
for(int i = 0; i < k; i ++ ) rr[i] = a[(rp[i] + rp[i + 1] + 1) >> 1] % l;
sort(rr, rr + k);
for(int i = 0; i < k; i ++ ) printf("%lld ", rr[i]);
puts("");
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 22308kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 26468kb
Test #3:
score: 0
Accepted
time: 3ms
memory: 24412kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 24420kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 26472kb
Test #6:
score: 0
Accepted
time: 0ms
memory: 24424kb
Test #7:
score: 0
Accepted
time: 4ms
memory: 26516kb
Test #8:
score: 0
Accepted
time: 4ms
memory: 24480kb
Test #9:
score: 0
Accepted
time: 10ms
memory: 24496kb
Test #10:
score: 0
Accepted
time: 9ms
memory: 22580kb
Test #11:
score: 0
Accepted
time: 124ms
memory: 25980kb
Test #12:
score: 0
Accepted
time: 102ms
memory: 28876kb
Test #13:
score: 0
Accepted
time: 128ms
memory: 28128kb
Test #14:
score: 0
Accepted
time: 105ms
memory: 28708kb
Test #15:
score: 0
Accepted
time: 117ms
memory: 31744kb
Test #16:
score: 0
Accepted
time: 712ms
memory: 50832kb
Test #17:
score: 0
Accepted
time: 783ms
memory: 44780kb
Test #18:
score: 0
Accepted
time: 779ms
memory: 45056kb
Test #19:
score: 0
Accepted
time: 872ms
memory: 39564kb
Test #20:
score: 0
Accepted
time: 700ms
memory: 51560kb
Test #21:
score: 0
Accepted
time: 713ms
memory: 48668kb
Test #22:
score: 0
Accepted
time: 692ms
memory: 51148kb
Test #23:
score: 0
Accepted
time: 839ms
memory: 39132kb
Test #24:
score: 0
Accepted
time: 796ms
memory: 41900kb
Test #25:
score: 0
Accepted
time: 766ms
memory: 46548kb
Test #26:
score: 0
Accepted
time: 827ms
memory: 42516kb
Test #27:
score: 0
Accepted
time: 835ms
memory: 41876kb
Test #28:
score: 0
Accepted
time: 767ms
memory: 46288kb
Test #29:
score: 0
Accepted
time: 846ms
memory: 40448kb
Test #30:
score: 0
Accepted
time: 633ms
memory: 51800kb
Test #31:
score: 0
Accepted
time: 731ms
memory: 50196kb
Test #32:
score: 0
Accepted
time: 699ms
memory: 50840kb
Test #33:
score: 0
Accepted
time: 693ms
memory: 49120kb
Test #34:
score: 0
Accepted
time: 765ms
memory: 47812kb
Test #35:
score: 0
Accepted
time: 721ms
memory: 48684kb
Test #36:
score: 0
Accepted
time: 639ms
memory: 53100kb
Test #37:
score: 0
Accepted
time: 724ms
memory: 49832kb
Test #38:
score: 0
Accepted
time: 662ms
memory: 52092kb
Test #39:
score: 0
Accepted
time: 893ms
memory: 37056kb
Test #40:
score: 0
Accepted
time: 672ms
memory: 53360kb
Test #41:
score: 0
Accepted
time: 905ms
memory: 35244kb
Test #42:
score: 0
Accepted
time: 702ms
memory: 51240kb
Test #43:
score: 0
Accepted
time: 868ms
memory: 39924kb
Test #44:
score: 0
Accepted
time: 705ms
memory: 51888kb
Test #45:
score: 0
Accepted
time: 660ms
memory: 53104kb
Test #46:
score: 0
Accepted
time: 684ms
memory: 51420kb
Test #47:
score: 0
Accepted
time: 833ms
memory: 42844kb
Test #48:
score: 0
Accepted
time: 844ms
memory: 37332kb
Test #49:
score: 0
Accepted
time: 880ms
memory: 37904kb
Test #50:
score: 0
Accepted
time: 760ms
memory: 44148kb
Test #51:
score: 0
Accepted
time: 743ms
memory: 49920kb
Test #52:
score: 0
Accepted
time: 733ms
memory: 50292kb
Test #53:
score: 0
Accepted
time: 859ms
memory: 40752kb
Test #54:
score: 0
Accepted
time: 843ms
memory: 38420kb
Test #55:
score: 0
Accepted
time: 681ms
memory: 51408kb
Test #56:
score: 0
Accepted
time: 863ms
memory: 38344kb
Test #57:
score: 0
Accepted
time: 856ms
memory: 37748kb
Test #58:
score: 0
Accepted
time: 841ms
memory: 40320kb
Test #59:
score: 0
Accepted
time: 774ms
memory: 43548kb
Test #60:
score: 0
Accepted
time: 635ms
memory: 53204kb
Test #61:
score: 0
Accepted
time: 850ms
memory: 40688kb
Test #62:
score: 0
Accepted
time: 757ms
memory: 45696kb
Test #63:
score: 0
Accepted
time: 878ms
memory: 38152kb
Test #64:
score: 0
Accepted
time: 640ms
memory: 53200kb
Test #65:
score: 0
Accepted
time: 1084ms
memory: 40808kb
Test #66:
score: 0
Accepted
time: 1052ms
memory: 44888kb
Test #67:
score: 0
Accepted
time: 1013ms
memory: 44476kb
Test #68:
score: 0
Accepted
time: 1019ms
memory: 44364kb
Test #69:
score: 0
Accepted
time: 962ms
memory: 36856kb
Test #70:
score: 0
Accepted
time: 968ms
memory: 38068kb
Test #71:
score: 0
Accepted
time: 948ms
memory: 36960kb
Test #72:
score: 0
Accepted
time: 961ms
memory: 34248kb
Extra Test:
score: 0
Extra Test Passed