QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#430868 | #6610. Forged in the Barrens | zlt | WA | 16ms | 60164kb | C++14 | 2.4kb | 2024-06-04 16:08:42 | 2024-06-04 16:08:44 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 100100;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
ll n, m, type, a[maxn];
typedef vector<ll> poly;
inline poly operator + (poly a, poly b) {
int n = (int)a.size() - 1, m = (int)b.size() - 1;
poly res;
res.pb(a[0] + b[0]);
int i = 0, j = 0;
ll s = a[0] + b[0];
while (i < n && j < m) {
if (a[i + 1] - a[i] > b[j + 1] - b[j]) {
s += a[i + 1] - a[i];
++i;
res.pb(s);
} else {
s += b[j + 1] - b[j];
++j;
res.pb(s);
}
}
while (i < n) {
s += a[i + 1] - a[i];
++i;
res.pb(s);
}
while (j < m) {
s += b[j + 1] - b[j];
++j;
res.pb(s);
}
assert((int)res.size() == n + m + 1);
return res;
}
inline poly get(poly a, poly b) {
int n = (int)a.size(), m = (int)b.size();
poly res(max(n, m), -inf);
for (int i = 0; i < max(n, m); ++i) {
if (i < n) {
res[i] = max(res[i], a[i]);
}
if (i < m) {
res[i] = max(res[i], b[i]);
}
}
return res;
}
poly F[262199][3][3];
void dfs(int rt, int l, int r) {
if (l == r) {
F[rt][0][0] = {-inf};
F[rt][0][1] = {-a[l]};
F[rt][0][2] = {-inf};
F[rt][1][0] = {-a[l]};
F[rt][1][1] = {0, 0};
F[rt][1][2] = {a[l]};
F[rt][2][0] = {-inf};
F[rt][2][1] = {a[l]};
F[rt][2][2] = {-inf};
return;
}
int mid = (l + r) >> 1;
dfs(rt << 1, l, mid);
dfs(rt << 1 | 1, mid + 1, r);
for (int i = 0; i <= 2; ++i) {
for (int j = 0; j <= 2; ++j) {
F[rt][i][j] = get(F[rt << 1][i][j], F[rt << 1 | 1][i][j]);
poly res = F[rt << 1][i][1] + F[rt << 1 | 1][1][j];
F[rt][i][j] = get(F[rt][i][j], res);
res = F[rt << 1][i][0] + F[rt << 1 | 1][2][j];
res.insert(res.begin(), -inf);
F[rt][i][j] = get(F[rt][i][j], res);
res = F[rt << 1][i][2] + F[rt << 1 | 1][0][j];
res.insert(res.begin(), -inf);
F[rt][i][j] = get(F[rt][i][j], res);
}
}
}
void solve() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
dfs(1, 1, n);
for (int i = 1; i <= n; ++i) {
printf("%lld\n", F[1][1][1][i]);
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 59072kb
input:
5 1 2 3 4 5
output:
4 3 2 1 0
result:
ok 5 number(s): "4 3 2 1 0"
Test #2:
score: 0
Accepted
time: 4ms
memory: 59144kb
input:
5 1 2 1 2 1
output:
1 2 2 1 0
result:
ok 5 number(s): "1 2 2 1 0"
Test #3:
score: 0
Accepted
time: 4ms
memory: 59108kb
input:
6 1 1 4 5 1 4
output:
4 7 7 7 4 0
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 16ms
memory: 59116kb
input:
6 1 9 1 9 8 1
output:
8 16 23 16 8 0
result:
ok 6 numbers
Test #5:
score: 0
Accepted
time: 8ms
memory: 59112kb
input:
12 1 1 4 5 1 4 1 9 1 9 8 1
output:
8 16 23 27 30 30 30 27 23 16 8 0
result:
ok 12 numbers
Test #6:
score: 0
Accepted
time: 12ms
memory: 59084kb
input:
1 882082994
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: -100
Wrong Answer
time: 12ms
memory: 60164kb
input:
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
0
result:
wrong answer Answer contains longer sequence [length = 200000], but output contains 1 elements