QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721946 | #6531. Base Station Construction | Agakiss | WA | 102ms | 14872kb | C++20 | 2.3kb | 2024-11-07 17:15:57 | 2024-11-07 17:15:57 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
//#define endl std::endl
#define i64 long long
#define pb push_back
#define pii std::pair<i64, i64>
#define INF 0x3f3f3f3f3f3f3f3f
const i64 N = 5e5 + 10;
i64 T, n, m, pos, ans;
i64 a[N], dp[N];
std::priority_queue<i64> pq;
struct tree {
i64 val;
} t[N * 6];
struct rec {
i64 l, r;
} p[N];
void pushup(i64 p) {
t[p].val = std::min(t[p << 1].val, t[p << 1 | 1].val);
}
void add(i64 p, i64 l, i64 r, i64 x, i64 k) {
if (l == r) {
t[p].val = std::min(t[p].val, k);
return;
}
i64 mid = (l + r) >> 1;
if (x <= mid) add(p << 1, l, mid, x, k);
else add(p << 1 | 1, mid + 1, r, x, k);
pushup(p);
}
i64 query(i64 p, i64 l, i64 r, i64 x, i64 y) {
if (y < x) return 0;
if (x <= l && r <= y) return t[p].val;
i64 mid = (l + r) >> 1, res = INF;
if (x <= mid) res = std::min(res, query(p << 1, l, mid, x, y));
if (y > mid) res = std::min(res, query(p << 1 | 1, mid + 1, r, x, y));
return res;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
std::cin >> T;
while (T--) {
std::cin >> n;
for (i64 i = 1; i <= n; i++)
std::cin >> a[i];
std::cin >> m;
for (i64 i = 1; i <= m; i++)
std::cin >> p[i].l >> p[i].r;
std::sort(p + 1, p + m + 1, [](auto x, auto y){ return x.r < y.r || x.r == y.r && x.l < y.l; });
pos = 1;
for (i64 i = 1; i <= n * 6; i++)
t[i].val = INF;
//std::cout << "*" << endl;
while (!pq.empty()) pq.pop();
pq.push(0);
add(1, 0, n, 0, 0);
for (int i = 1; i <= n; i++)
dp[i] = INF;
for (i64 i = 1; i <= n; i++) {
while (p[pos].r < i && pos < m) pq.push(p[pos].l), pos++;
dp[i] = query(1, 0, n, pq.top(), i - 1) + a[i];
add(1, 0, n, i, dp[i]);
//std::cout << "*" << endl;
}
//std::cout << "*" << endl;
ans = INF;
/*for (i64 i = 1; i <= n; i++)
std::cout << dp[i] << " ";
std::cout << endl;
*/for (i64 i = p[m].l; i <= p[m].r; i++)
ans = std::min(ans, dp[i]);
std::cout << ans << endl;
if (ans == 36) {
std::cout << "----------------" << endl;
std::cout << n << endl;
for (i64 i = 1; i <= n; i++)
std::cout << a[i] << " ";
std::cout << endl;
std::cout << m<<endl;
for (i64 i = 1; i <= m; i++)
std::cout << p[i].l << " " << p[i].r<< endl;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9736kb
input:
2 5 3 2 4 1 100 3 1 3 2 4 5 5 5 7 3 4 2 2 3 1 4 2 3 4 5
output:
102 5
result:
ok 2 number(s): "102 5"
Test #2:
score: -100
Wrong Answer
time: 102ms
memory: 14872kb
input:
6201 12 88 78 46 95 84 98 55 3 68 42 6 18 19 6 9 10 11 12 12 8 11 8 12 2 3 2 3 1 5 9 9 7 8 6 11 2 4 12 12 2 4 2 9 7 10 8 8 1 7 6 11 5 76 27 48 66 61 2 1 4 3 5 8 64 81 20 6 86 9 4 55 1 7 7 9 1 43 18 81 11 22 9 61 83 14 5 6 2 6 5 8 1 4 9 9 9 9 7 7 2 5 8 9 5 6 4 8 5 8 9 9 6 6 10 66 41 84 7 80 31 22 96 ...
output:
141 48 4 126 303 141 23 170 159 139 153 194 136 89 230 93 287 89 124 130 148 27 1 193 36 ---------------- 16 36 57 36 67 94 84 16 59 83 55 82 97 26 28 33 34 19 3 3 7 7 6 9 10 10 3 11 3 11 7 11 10 13 12 13 6 14 9 14 11 14 14 14 1 15 3 15 13 15 15 15 1 16 3 16 93 239 303 236 150 177 57 46 18 24 66 83...
result:
wrong answer 25th numbers differ - expected: '194', found: '36'