# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
73882 | 2018-08-29T08:12:43 Z | 강태규(#2274) | 놀이터에 떨어진 이상한 약 (FXCUP3_gorgeous) | C++11 | 443 ms | 41600 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; int n; int c[300001]; int d[300001]; struct node { int x, t; llong d; node(int x, llong d, int t) : x(x), d(d), t(t) {} bool operator<(const node &p) const { if (x != p.x) return x < p.x; return t < p.t; } }; llong seg[300001]; void update(int i, llong x) { while (i <= n) { seg[i] = max(seg[i], x); i += i & -i; } } llong query(int i) { llong ret = 0; while (i) { ret = max(ret, seg[i]); i -= i & -i; } return ret; } llong ans[300001]; vector<node> ev[300001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", c + i); for (int i = 1; i <= n; ++i) scanf("%d", d + i); for (int i = 1; i <= n; ++i) { if (c[i] == 1) { ans[i] += d[i]; continue; } if (i < n && i + c[i] - 1 <= n) ev[i + c[i] - 1].emplace_back(i, d[i], 1); if (1 <= i - c[i] + 1 && 1 < i) ev[i].emplace_back(i - c[i] + 1, d[i], 2); } for (int it = n; it > 0; --it) { sort(ev[it].begin(), ev[it].end()); for (node n : ev[it]) { if (n.t == 0) { update(n.x, n.d); continue; } llong v = query(n.x) + n.d; if (n.t == 1) update(n.x + 1, v); else ev[it - 1].emplace_back(n.x, v, 0); } ans[it] += query(it); } for (int i = 1; i <= n; ++i) { printf("%lld%c", ans[i], "\n "[i < n]); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7484 KB | Output is correct |
3 | Correct | 8 ms | 7592 KB | Output is correct |
4 | Correct | 7 ms | 7592 KB | Output is correct |
5 | Correct | 9 ms | 7612 KB | Output is correct |
6 | Correct | 9 ms | 7612 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7484 KB | Output is correct |
3 | Correct | 8 ms | 7592 KB | Output is correct |
4 | Correct | 7 ms | 7592 KB | Output is correct |
5 | Correct | 9 ms | 7612 KB | Output is correct |
6 | Correct | 9 ms | 7612 KB | Output is correct |
7 | Correct | 8 ms | 7612 KB | Output is correct |
8 | Correct | 9 ms | 7612 KB | Output is correct |
9 | Correct | 8 ms | 7612 KB | Output is correct |
10 | Correct | 11 ms | 7612 KB | Output is correct |
11 | Correct | 11 ms | 7636 KB | Output is correct |
12 | Correct | 11 ms | 7680 KB | Output is correct |
13 | Correct | 9 ms | 7680 KB | Output is correct |
14 | Correct | 10 ms | 7692 KB | Output is correct |
15 | Correct | 11 ms | 7820 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 10 ms | 7484 KB | Output is correct |
3 | Correct | 8 ms | 7592 KB | Output is correct |
4 | Correct | 7 ms | 7592 KB | Output is correct |
5 | Correct | 9 ms | 7612 KB | Output is correct |
6 | Correct | 9 ms | 7612 KB | Output is correct |
7 | Correct | 8 ms | 7612 KB | Output is correct |
8 | Correct | 9 ms | 7612 KB | Output is correct |
9 | Correct | 8 ms | 7612 KB | Output is correct |
10 | Correct | 11 ms | 7612 KB | Output is correct |
11 | Correct | 11 ms | 7636 KB | Output is correct |
12 | Correct | 11 ms | 7680 KB | Output is correct |
13 | Correct | 9 ms | 7680 KB | Output is correct |
14 | Correct | 10 ms | 7692 KB | Output is correct |
15 | Correct | 11 ms | 7820 KB | Output is correct |
16 | Correct | 13 ms | 8092 KB | Output is correct |
17 | Correct | 28 ms | 9516 KB | Output is correct |
18 | Correct | 92 ms | 14948 KB | Output is correct |
19 | Correct | 138 ms | 17068 KB | Output is correct |
20 | Correct | 344 ms | 29488 KB | Output is correct |
21 | Correct | 443 ms | 30508 KB | Output is correct |
22 | Correct | 348 ms | 30508 KB | Output is correct |
23 | Correct | 335 ms | 30508 KB | Output is correct |
24 | Correct | 381 ms | 30508 KB | Output is correct |
25 | Correct | 231 ms | 41600 KB | Output is correct |