QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572854 | #9222. Price Combo | Yansuan_HCl | WA | 601ms | 101524kb | C++20 | 3.4kb | 2024-09-18 16:36:03 | 2024-09-18 16:36:04 |
Judging History
answer
#include <bits/stdc++.h>
#define ms(x, v) memset(x, v, sizeof(x))
#define il __attribute__((always_inline)) static
#define U(i,l,r) for(int i(l),END##i(r);i<=END##i;++i)
#define D(i,r,l) for(int i(r),END##i(l);i>=END##i;--i)
using namespace std;
using ll = long long;
#define IC isdigit(c)
#define GC c=getchar()
void rd(auto &x) { x = 0; char GC; bool f = 0;
for (; !IC; GC) f |= c == '-';
for (; IC; GC) x = x * 10 + c - 48;
if (f) x = -x;
}
void rd(auto &x, auto &...y) { rd(x); rd(y...); }
#define meow(...) fprintf(stderr, __VA_ARGS__)
#define Assert(e, v) if (!(e)) exit(v);
const int N = 200005;
int n;
const ll inf = 1e18;
using info = array<ll, 4>; using tag = array<array<ll, 4>, 4>;
void clear(tag &l) {
U (x, 0, 3) l[x].fill(inf);
}
void init(tag &l) {
clear(l);
U (x, 0, 3) l[x][x] = 0;
}
void mul(info &f, info l, const tag &r) {
f.fill(inf);
U (x, 0, 3) U (y, 0, 3) f[y] = min(f[y], l[x] + r[x][y]);
}
void mul(tag &f, tag l, const tag &r) {
clear(f);
U (i, 0, 3) U (j, 0, 3) if (l[i][j] != inf) U (k, 0, 3) if (r[j][k] != inf)
f[i][k] = min(f[i][k], l[i][j] + r[j][k]);
}
void check(info &f, const info &l, const info &r) {
U (i, 0, 3) f[i] = min(l[i], r[i]);
}
#define mid ((l + r) >> 1)
#define ls (p << 1)
#define rs (ls | 1)
#define arg int p = 1, int l = 0, int r = n
struct { info v; tag t; bool f; } tr[N * 4];
void app(int p, const tag &t) {
mul(tr[p].v, tr[p].v, t);
if (!tr[p].f) {
tr[p].t = t; tr[p].f = 1;
} else {
mul(tr[p].t, tr[p].t, t);
}
}
void down(int p) {
if (!tr[p].f) return;
tag &t = tr[p].t;
app(ls, t); app(rs, t);
tr[p].f = 0;
}
void up(int p) {
check(tr[p].v, tr[ls].v, tr[rs].v);
}
void mod(int x, const info &v, arg) {
if (l == r) { tr[p].v = v; return; }
down(p);
(x <= mid) ? mod(x, v, ls, l, mid) : mod(x, v, rs, mid + 1, r);
up(p);
}
void op(int b, int e, const tag &v, arg) {
if (b <= l && e >= r) { app(p, v); return; }
down(p);
if (b <= mid) op(b, e, v, ls, l, mid);
if (e > mid) op(b, e, v, rs, mid + 1, r);
up(p);
}
info query(int b, int e, arg) {
if (b <= l && e >= r) return tr[p].v;
down(p);
info f; f.fill(inf);
if (b <= mid) f = query(b, e, ls, l, mid);
if (e > mid) {
info g = f;
check(f, g, query(b, e, rs, mid + 1, r));
}
return f;
}
void build(arg) {
init(tr[p].t); tr[p].v.fill(inf); tr[p].v[0] = 0;
if (l == r) return;
build(ls, l, mid); build(rs, mid + 1, r);
}
void add_a(int b, int e, ll v) {
tag f; clear(f);
U (i, 0, 3) f[i ^ 2][i] = (i & 2 ? v : 0);
op(b, e, f);
}
void add_b(int b, int e, ll v) {
tag f; clear(f);
U (i, 0, 3) f[i ^ 1][i] = (i & 1 ? v : 0);
op(b, e, f);
}
ll a[N], b[N];
pair<ll, int> la[N], lb[N];
int refa[N], refb[N];
int main() {
// freopen("ava.in", "r", stdin);
rd(n);
U (i, 1, n) rd(a[i]), la[i] = {a[i], i};
U (i, 1, n) rd(b[i]), lb[i] = {b[i], i};
sort(la + 1, la + n + 1); sort(lb + 1, lb + n + 1);
U (i, 1, n) {
a[i] = lower_bound(la + 1, la + n + 1, make_pair(a[i], i)) - la;
b[i] = lower_bound(lb + 1, lb + n + 1, make_pair(b[i], i)) - lb;
refa[a[i]] = i; refb[b[i]] = i;
}
build();
D (x, n, 1) {
int i = refa[x];
info t = query(b[i] - 1, n);
mod(b[i] - 1, t);
add_a(0, b[i] - 1, la[a[i]].first);
add_b(b[i], n, lb[b[i]].first);
}
ll ans = inf;
U (i, 0, 3) ans = min(ans, tr[1].v[i]);
printf("%lld\n", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12112kb
input:
7 10 12 19 99 10 8 49 9 14 15 199 11 7 19
output:
131
result:
ok single line: '131'
Test #2:
score: 0
Accepted
time: 0ms
memory: 12060kb
input:
7 10 12 19 99 10 8 49 9 14 15 199 11 7 19
output:
131
result:
ok single line: '131'
Test #3:
score: -100
Wrong Answer
time: 601ms
memory: 101524kb
input:
199913 1212731 2525164 3210261 2457211 1013738 1931420 923123 867112 762069 2108660 108920 2491869 867107 387025 2278045 574027 1661570 820133 1274150 2001346 779766 3305537 3000211 2418643 2108660 2001343 1074820 2754411 826712 3117447 1661569 338161 1849064 3007920 3057426 468078 3252798 1274146 4...
output:
154816471644
result:
wrong answer 1st lines differ - expected: '154816494865', found: '154816471644'