답안 #393411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393411 2021-04-23T11:32:36 Z asbsfds 금 캐기 (IZhO14_divide) C++14
100 / 100
100 ms 23272 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const llint inf = (1LL << 60);
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n;
int x[maxn];
llint g[maxn], d[maxn];
llint tour[treesiz];
llint c[maxn];
vector< llint > v;

void update(int x, llint val) {
	x += off;
	tour[x] = min(tour[x], val);
	
	x /= 2;
	while (x > 0) tour[x] = min(tour[x * 2], tour[x * 2 + 1]), x /= 2;
}

llint query(int a, int b, int l, int r, int node) {
	if (l > b || r < a) return inf;
	if (l >= a && r <= b) return tour[node];
	
	int mid = (l + r) / 2;
	return min(query(a, b, l, mid, node * 2), query(a, b, mid + 1, r, node * 2 + 1));
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) 
		scanf("%d%lld%lld", x+i, g+i, d+i);
	
	for (int i = 1; i <= n; i++) {
		g[i] += g[i - 1];
		d[i] += d[i - 1];
	}
	for (int i = 1; i < treesiz; i++) tour[i] = inf;
	
	v.push_back(-inf);
	for (int i = 1; i <= n; i++) {
		c[i] = d[i - 1] - x[i];
		v.push_back(c[i]);
	}
	
	//for (int i = 1; i <= n; i++) printf("%lld ", c[i]); printf("\n");
	
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	
	llint sol = 0;
	for (int i = 1; i <= n; i++) {
		sol = max(sol, g[i] - g[i - 1]);
		
		llint ac = d[i] - x[i];
		int ind = upper_bound(v.begin(), v.end(), ac) - v.begin(); ind--;
		sol = max(sol, g[i] - query(0, ind, 0, off - 1, 1));
		
		ind = lower_bound(v.begin(), v.end(), c[i]) - v.begin();
		update(ind, g[i - 1]);
	}
	printf("%lld\n", sol);
	return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
divide.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%d%lld%lld", x+i, g+i, d+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16716 KB Output is correct
2 Correct 10 ms 16716 KB Output is correct
3 Correct 9 ms 16716 KB Output is correct
4 Correct 9 ms 16684 KB Output is correct
5 Correct 9 ms 16716 KB Output is correct
6 Correct 10 ms 16708 KB Output is correct
7 Correct 10 ms 16716 KB Output is correct
8 Correct 9 ms 16716 KB Output is correct
9 Correct 9 ms 16716 KB Output is correct
10 Correct 9 ms 16716 KB Output is correct
11 Correct 9 ms 16716 KB Output is correct
12 Correct 10 ms 16628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16716 KB Output is correct
2 Correct 10 ms 16716 KB Output is correct
3 Correct 9 ms 16716 KB Output is correct
4 Correct 9 ms 16684 KB Output is correct
5 Correct 9 ms 16716 KB Output is correct
6 Correct 10 ms 16708 KB Output is correct
7 Correct 10 ms 16716 KB Output is correct
8 Correct 9 ms 16716 KB Output is correct
9 Correct 9 ms 16716 KB Output is correct
10 Correct 9 ms 16716 KB Output is correct
11 Correct 9 ms 16716 KB Output is correct
12 Correct 10 ms 16628 KB Output is correct
13 Correct 11 ms 16708 KB Output is correct
14 Correct 9 ms 16716 KB Output is correct
15 Correct 10 ms 16660 KB Output is correct
16 Correct 11 ms 16716 KB Output is correct
17 Correct 10 ms 16716 KB Output is correct
18 Correct 10 ms 16832 KB Output is correct
19 Correct 10 ms 16800 KB Output is correct
20 Correct 12 ms 16716 KB Output is correct
21 Correct 10 ms 16716 KB Output is correct
22 Correct 11 ms 16844 KB Output is correct
23 Correct 14 ms 16972 KB Output is correct
24 Correct 13 ms 16972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16716 KB Output is correct
2 Correct 10 ms 16716 KB Output is correct
3 Correct 9 ms 16716 KB Output is correct
4 Correct 9 ms 16684 KB Output is correct
5 Correct 9 ms 16716 KB Output is correct
6 Correct 10 ms 16708 KB Output is correct
7 Correct 10 ms 16716 KB Output is correct
8 Correct 9 ms 16716 KB Output is correct
9 Correct 9 ms 16716 KB Output is correct
10 Correct 9 ms 16716 KB Output is correct
11 Correct 9 ms 16716 KB Output is correct
12 Correct 10 ms 16628 KB Output is correct
13 Correct 11 ms 16708 KB Output is correct
14 Correct 9 ms 16716 KB Output is correct
15 Correct 10 ms 16660 KB Output is correct
16 Correct 11 ms 16716 KB Output is correct
17 Correct 10 ms 16716 KB Output is correct
18 Correct 10 ms 16832 KB Output is correct
19 Correct 10 ms 16800 KB Output is correct
20 Correct 12 ms 16716 KB Output is correct
21 Correct 10 ms 16716 KB Output is correct
22 Correct 11 ms 16844 KB Output is correct
23 Correct 14 ms 16972 KB Output is correct
24 Correct 13 ms 16972 KB Output is correct
25 Correct 13 ms 17032 KB Output is correct
26 Correct 16 ms 17228 KB Output is correct
27 Correct 17 ms 17400 KB Output is correct
28 Correct 47 ms 19548 KB Output is correct
29 Correct 48 ms 19896 KB Output is correct
30 Correct 100 ms 23272 KB Output is correct
31 Correct 82 ms 22044 KB Output is correct
32 Correct 81 ms 22076 KB Output is correct
33 Correct 79 ms 21948 KB Output is correct
34 Correct 96 ms 21924 KB Output is correct
35 Correct 83 ms 22492 KB Output is correct
36 Correct 86 ms 22576 KB Output is correct