QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141417 | #6531. Base Station Construction | cy1999 | WA | 81ms | 16900kb | C++ | 1.9kb | 2023-08-17 11:53:13 | 2023-08-17 11:53:17 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#define lx (x * 2)
#define rx (x * 2 + 1)
#define mid ((l + r) >> 1)
#define int long long
using namespace std;
const int N = 500000, INF = 0x3f3f3f3f;
int n, a[N + 5];
int ml[N + 5];
void init()
{
scanf("%lld", &n);
for(int i = 1; i <= n; i++)
{
scanf("%lld", &a[i]);
ml[i] = -INF;
}
int m;
scanf("%lld", &m);
while(m--)
{
int l, r;
scanf("%lld %lld", &l, &r);
ml[r] = max(ml[r], l);
}
}
struct Tr
{
int mx;
}tr[N * 4 + 5];
void pushup(int x)
{
tr[x].mx = min(tr[lx].mx, tr[rx].mx);
}
void bld(int x, int l, int r)
{
if(l == r)
{
tr[x].mx = INF;
return;
}
bld(lx, l, mid);
bld(rx, mid + 1, r);
}
void mdf(int x, int l, int r, int s, int k)
{
if(l == r)
{
tr[x].mx = k;
return;
}
if(s <= mid)
{
mdf(lx, l, mid, s, k);
}
else
{
mdf(rx, mid + 1, r, s, k);
}
pushup(x);
}
int ask(int x, int l, int r, int s, int t)
{
if(l >= s && r <= t)
{
return tr[x].mx;
}
int ret = INF;
if(s <= mid)
{
ret = min(ret, ask(lx, l, mid, s, t));
}
if( t > mid)
{
ret = min(ret, ask(rx, mid + 1, r, s, t));
}
return ret;
}
int f[N + 5][2];
void solve()
{
bld(1, 1, n);
if(ml[1] != -INF)
{
f[1][0] = INF;
f[1][1] = a[1];
mdf(1, 1, n, 1, f[1][1]);
}
for(int i = 2; i <= n; i++)
{
if(ml[i] != -INF)
{
if(ml[i] == i)
{
f[i][0] = INF;
f[i][1] = min(f[i - 1][0], f[i - 1][1]) + a[i];
}
else
{
f[i][0] = ask(1, 1, n, ml[i], i - 1);
f[i][1] = min(f[i - 1][0], f[i - 1][1]) + a[i];
}
}
else
{
f[i][0] = min(f[i - 1][0], f[i - 1][1]);
f[i][1] = f[i][0] + a[i];
}
mdf(1, 1, n, i, f[i][1]);
}
printf("%lld\n", min(f[n][0], f[n][1]));
}
void clr()
{
}
signed main()
{
int T;
scanf("%lld", &T);
while(T--)
{
init();
solve();
clr();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7740kb
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: 81ms
memory: 16900kb
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:
73 48 4 112 303 141 23 170 159 139 173 236 137 110 230 136 152 132 163 178 186 70 54 193 58 115 239 377 226 224 177 57 103 75 81 123 140 217 165 119 35 157 146 116 150 146 80 211 154 67 154 146 371 244 272 97 302 108 113 43 30 159 70 121 103 179 81 88 142 178 157 191 190 327 291 133 65 61 213 132 21...
result:
wrong answer 1st numbers differ - expected: '141', found: '73'