# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
73824 |
2018-08-29T05:34:37 Z |
아인따(#2278) |
Gorgeous Pill (FXCUP3_gorgeous) |
C++11 |
|
372 ms |
32260 KB |
#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]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
524 KB |
Output is correct |
3 |
Correct |
3 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
524 KB |
Output is correct |
3 |
Correct |
3 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
3 ms |
600 KB |
Output is correct |
10 |
Correct |
3 ms |
700 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
828 KB |
Output is correct |
14 |
Correct |
5 ms |
828 KB |
Output is correct |
15 |
Correct |
6 ms |
828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
524 KB |
Output is correct |
3 |
Correct |
3 ms |
524 KB |
Output is correct |
4 |
Correct |
3 ms |
576 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
3 ms |
600 KB |
Output is correct |
10 |
Correct |
3 ms |
700 KB |
Output is correct |
11 |
Correct |
3 ms |
748 KB |
Output is correct |
12 |
Correct |
3 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
828 KB |
Output is correct |
14 |
Correct |
5 ms |
828 KB |
Output is correct |
15 |
Correct |
6 ms |
828 KB |
Output is correct |
16 |
Correct |
15 ms |
1164 KB |
Output is correct |
17 |
Correct |
27 ms |
2828 KB |
Output is correct |
18 |
Correct |
128 ms |
9336 KB |
Output is correct |
19 |
Correct |
139 ms |
11892 KB |
Output is correct |
20 |
Correct |
368 ms |
26604 KB |
Output is correct |
21 |
Correct |
329 ms |
27932 KB |
Output is correct |
22 |
Correct |
372 ms |
27960 KB |
Output is correct |
23 |
Correct |
335 ms |
27960 KB |
Output is correct |
24 |
Correct |
353 ms |
27976 KB |
Output is correct |
25 |
Correct |
279 ms |
32260 KB |
Output is correct |