#include<cstdio>
#include<algorithm>
#include<vector>
#define pil pair<int,long long>
#define N_ 301000
#define SZ 524288
using namespace std;
struct point {
int b, e, c, ck;
bool operator <(const point &p)const {
return b != p.b ? b<p.b : e>p.e;
}
}P[N_*3];
int w[N_], cnt, C[N_];
int n;
long long IT[SZ + SZ], D[N_*3], Res[N_];
void Put(int a, long long b) {
a += SZ;
while (a) {
IT[a] = max(IT[a], b);
a >>= 1;
}
}
long long Max(int b, int e) {
long long r = 0;
b += SZ, e += SZ;
while (b <= e) {
r = max(r, max(IT[b], IT[e]));
b = (b + 1) >> 1, e = (e - 1) >> 1;
}
return r;
}
void Calc(int a) {
int b = P[a].b, e = P[a].e;
D[a] = Max(e, n) + P[a].c;
}
int main() {
int i;
scanf("%d", &n);
P[cnt++] = { 1,n,0 };
for (i = 1; i <= n; i++) scanf("%d", &w[i]);
for (i = 1; i <= n; i++){
scanf("%d", &C[i]);
if (i - w[i] + 1 >= 1)P[cnt++] = { i - w[i] + 1, i, C[i], 1 };
if (i + w[i] - 1 <= n)P[cnt++] = { i, i + w[i] - 1, C[i], 0 };
if(w[i] != 1)P[cnt++] = { i,i,0,0 };
}
sort(P, P + cnt);
vector<pil>V;
for (i = 0; i < cnt; i++) {
if (i && P[i].b != P[i - 1].b) {
for (auto &x : V) Put(x.first, x.second);
V.clear();
}
Calc(i);
if (P[i].ck == 1)Put(P[i].e - 1, D[i]);
else V.push_back({ P[i].e, D[i] });
}
for (i = 0; i < cnt; i++) {
if (P[i].b == P[i].e)Res[P[i].b] = max(Res[P[i].b], D[i]);
}
for (i = 1; i <= n; i++)printf("%lld ", Res[i]);
}
Compilation message
gorgeous.cpp: In function 'void Calc(int)':
gorgeous.cpp:34:6: warning: unused variable 'b' [-Wunused-variable]
int b = P[a].b, e = P[a].e;
^
gorgeous.cpp: In function 'int main()':
gorgeous.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
gorgeous.cpp:41:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 1; i <= n; i++) scanf("%d", &w[i]);
~~~~~^~~~~~~~~~~~~
gorgeous.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &C[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
3 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
3 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
564 KB |
Output is correct |
9 |
Correct |
3 ms |
564 KB |
Output is correct |
10 |
Correct |
3 ms |
568 KB |
Output is correct |
11 |
Correct |
4 ms |
696 KB |
Output is correct |
12 |
Correct |
3 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
736 KB |
Output is correct |
14 |
Correct |
4 ms |
796 KB |
Output is correct |
15 |
Correct |
5 ms |
796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
564 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
3 ms |
564 KB |
Output is correct |
7 |
Correct |
2 ms |
564 KB |
Output is correct |
8 |
Correct |
3 ms |
564 KB |
Output is correct |
9 |
Correct |
3 ms |
564 KB |
Output is correct |
10 |
Correct |
3 ms |
568 KB |
Output is correct |
11 |
Correct |
4 ms |
696 KB |
Output is correct |
12 |
Correct |
3 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
736 KB |
Output is correct |
14 |
Correct |
4 ms |
796 KB |
Output is correct |
15 |
Correct |
5 ms |
796 KB |
Output is correct |
16 |
Correct |
8 ms |
1056 KB |
Output is correct |
17 |
Correct |
31 ms |
2944 KB |
Output is correct |
18 |
Correct |
109 ms |
9304 KB |
Output is correct |
19 |
Correct |
157 ms |
11876 KB |
Output is correct |
20 |
Correct |
365 ms |
26592 KB |
Output is correct |
21 |
Correct |
389 ms |
28060 KB |
Output is correct |
22 |
Correct |
407 ms |
28060 KB |
Output is correct |
23 |
Correct |
370 ms |
28060 KB |
Output is correct |
24 |
Correct |
394 ms |
28060 KB |
Output is correct |
25 |
Correct |
321 ms |
32284 KB |
Output is correct |