답안 #224019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
224019 2020-04-17T04:49:03 Z shenxy Just Long Neckties (JOI20_ho_t1) C++11
100 / 100
202 ms 27256 KB
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<long long, int> ii;
struct seg {
    int s, e, m, v;
    seg *l, *r;
    seg(int _s, int _e) {
        s = _s, e = _e, m = (s + e) / 2, v = 0;
        if (s != e) {
            l = new seg(s, m);
            r = new seg(m + 1, e);
        }
    }
    void update(int i, int nv) {
        if (s != e) {
            if (i > m) r -> update(i, nv);
            else l -> update(i, nv);
            v = max(l -> v, r -> v);
        } else v = nv;
    }
    int query(int a, int b) {
        if (s == a && e == b) return v;
        if (a > m) return r -> query(a, b);
        if (b <= m) return l -> query(a, b);
        return max(l -> query(a, m), r -> query(m + 1, b));
    }
} *root;
int main() {
	int N;
	scanf("%d", &N);
	ii A[N + 1];
	long long B[N], ans[N + 1];
	for (int i = 0; i <= N; ++i) scanf("%lld", &A[i].first), A[i].second = i;
	for (int i = 0; i < N; ++i) scanf("%lld", &B[i]);
	sort(A, A + N + 1);
	sort(B, B + N);
	root = new seg(0, N - 1);
	for (int i = 0; i < N; ++i) root -> update(i, max(A[i].first - B[i], 0LL));
	ans[A[N].second] = root -> query(0, N - 1);
	for (int i = N - 1; i >= 0; --i) {
		root -> update(i, max(A[i + 1].first - B[i], 0LL));
		ans[A[i].second] = root -> query(0, N - 1);
	}
	for (int i = 0; i <= N; ++i) printf("%lld ", ans[i]);
	return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
ho_t1.cpp:34:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i <= N; ++i) scanf("%lld", &A[i].first), A[i].second = i;
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t1.cpp:35:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; ++i) scanf("%lld", &B[i]);
                              ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 6 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 6 ms 512 KB Output is correct
30 Correct 6 ms 512 KB Output is correct
31 Correct 6 ms 640 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 182 ms 25848 KB Output is correct
34 Correct 195 ms 26744 KB Output is correct
35 Correct 186 ms 26104 KB Output is correct
36 Correct 185 ms 26488 KB Output is correct
37 Correct 198 ms 27256 KB Output is correct
38 Correct 199 ms 26976 KB Output is correct
39 Correct 198 ms 25956 KB Output is correct
40 Correct 191 ms 25720 KB Output is correct
41 Correct 190 ms 25976 KB Output is correct
42 Correct 190 ms 25848 KB Output is correct
43 Correct 199 ms 25720 KB Output is correct
44 Correct 186 ms 25208 KB Output is correct
45 Correct 191 ms 25336 KB Output is correct
46 Correct 185 ms 25080 KB Output is correct
47 Correct 178 ms 25848 KB Output is correct
48 Correct 171 ms 25848 KB Output is correct
49 Correct 195 ms 26720 KB Output is correct
50 Correct 197 ms 26488 KB Output is correct
51 Correct 197 ms 26488 KB Output is correct
52 Correct 202 ms 26488 KB Output is correct
53 Correct 202 ms 26616 KB Output is correct