QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673813 | #6104. Building Bombing | stompQ | WA | 1ms | 7740kb | C++23 | 2.1kb | 2024-10-25 10:32:13 | 2024-10-25 10:32:13 |
Judging History
answer
#include <iostream>
#include <map>
using namespace std;
int t[400005][11], lazy[400005][11], a[100005], f[100005][12];
map<int, int> m;
void push(int v, int h) {
t[v * 2][h] += lazy[v][h];
t[v * 2 + 1][h] += lazy[v][h];
lazy[v * 2][h] += lazy[v][h];
lazy[v * 2 + 1][h] += lazy[v][h];
lazy[v][h] = 0;
}
void update(int v, int h, int tl, int tr, int l, int r, int x, int fl) {
if (l > r) return;
if (tl == l && tr == r) {
if (fl == 0) t[v][h] = x;
else {
t[v][h] += x;
lazy[v][h] += x;
}
return;
}
push(v, h);
int mid = (tl + tr) / 2;
update(v * 2, h, tl, mid, l, min(r, mid), x, fl);
update(v * 2 + 1, h, mid + 1, tr, max(l, mid + 1), r, x, fl);
t[v][h] = min(t[v * 2][h], t[v * 2 + 1][h]);
}
int sum(int v, int h, int tl, int tr, int l, int r) {
if (l > r) return 1e9;
if (tl == l && tr == r) {
return t[v][h];
}
push(v, h);
int mid = (tl + tr) / 2;
return min(sum(v * 2, h, tl, mid, l, min(r, mid)), sum(v * 2 + 1, h, mid + 1, tr, max(l, mid + 1), r));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, l, k, z = 0;
cin >> n >> l >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
m[a[i]] = 1;
}
for (auto &w : m) w.second = ++z;
for (int i = 1; i <= n; i++) a[i] = m[a[i]];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
update(1, j, 1, z, a[i], a[i], 1e9, 0);
f[i][j] = 1e9;
}
}
update(1, 1, 1, z, a[l], a[l], 0, 0);
f[a[l]][1] = 0;
for (int i = l + 1; i <= n; i++) {
for (int j = k; j >= 2; j--) {
int h = sum(1, j - 1, 1, z, 1, a[i] - 1);
h = min(h, sum(1, j, 1, z, a[i], a[i]));
update(1, j, 1, z, a[i], a[i], h, 0);
}
for (int j = 1; j <= k; j++) {
update(1, j, 1, z, 1, a[i] - 1, 1, 1);
}
}
int res = sum(1, k, 1, z, 1, z);
for (int i = 1; i < l; i++) res += (a[i] == a[l]);
if (res >= 1e6) cout << -1;
else cout << res;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7736kb
input:
7 2 3 10 30 90 40 60 60 80
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7652kb
input:
3 2 2 30 20 10
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7604kb
input:
1 1 1 608954134
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7740kb
input:
10 5 3 872218248 517822599 163987167 517822599 458534407 142556631 142556631 458534407 458534407 872218248
output:
-1
result:
ok 1 number(s): "-1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7724kb
input:
10 4 2 31201623 546478688 709777934 672927273 672927273 709777934 801718395 672927273 926114576 38983342
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'