Submission #45089

# Submission time Handle Problem Language Result Execution time Memory
45089 2018-04-11T07:57:49 Z nibnalin Divide and conquer (IZhO14_divide) C++17
100 / 100
471 ms 176768 KB
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;

const lli maxn = lli(1e5)+5, inf = lli(1e16)+5, maxv = lli(1e16)+10, offset = lli(1e16)+5;

lli x[maxn], g[maxn], d[maxn];

struct ppnode {
	lli val;
	ppnode *l, *r;
	ppnode(lli _val = inf, ppnode* _l = NULL, ppnode* _r = NULL)
	{
		val = _val, l = _l, r = _r;
	}
};

typedef ppnode* pnode;

pnode root[maxn] = {NULL};

pnode upd(pnode root, lli L, lli R, lli a, lli v)
{
	if(L == R) return new ppnode(min(root->val, v), NULL, NULL);
	else if(a <= (L+R)/2) return new ppnode(min(root->val, v), upd(root->l, L, (L+R)/2, a, v), root->r);
	else return new ppnode(min(root->val, v), root->l, upd(root->r, (L+R)/2+1, R, a, v));
}

lli qry(pnode root, lli L, lli R, lli a, lli b)
{
	if(a > R || b < L) return inf;
	else if(a <= L && R <= b) return root->val;
	else
	{
		lli res = inf;
		if(root->l) res = min(res, qry(root->l, L, (L+R)/2, a, b));
		if(root->r) res = min(res, qry(root->r, (L+R)/2+1, R, a, b));
		return res;
	}
}

int main(void)
{
	lli n, res = 0;
	scanf("%lld", &n);
	for(lli i = 1;i <= n;i++)
	{
		scanf("%lld%lld%lld", &x[i], &g[i], &d[i]);
		g[i] += g[i-1], d[i] += d[i-1];
	}

	root[0] = new ppnode();
	root[0]->l = root[0]->r = root[0];
	for(lli i = 1;i <= n;i++)
	{
		root[i] = upd(root[i-1], 0, maxv+offset, x[i]-d[i-1]+offset, g[i-1]);
		res = max(res, g[i]-qry(root[i], 0, maxv+offset, x[i]-d[i]+offset, maxv+offset));
	}
	printf("%lld\n", res);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
divide.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x[i], &g[i], &d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 2 ms 740 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 2 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 868 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 4 ms 1380 KB Output is correct
4 Correct 5 ms 1772 KB Output is correct
5 Correct 7 ms 2156 KB Output is correct
6 Correct 7 ms 2744 KB Output is correct
7 Correct 6 ms 2744 KB Output is correct
8 Correct 6 ms 2744 KB Output is correct
9 Correct 8 ms 3196 KB Output is correct
10 Correct 11 ms 4092 KB Output is correct
11 Correct 23 ms 9340 KB Output is correct
12 Correct 24 ms 9340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 9340 KB Output is correct
2 Correct 42 ms 18172 KB Output is correct
3 Correct 44 ms 18172 KB Output is correct
4 Correct 220 ms 88540 KB Output is correct
5 Correct 234 ms 88572 KB Output is correct
6 Correct 458 ms 176640 KB Output is correct
7 Correct 427 ms 176640 KB Output is correct
8 Correct 431 ms 176640 KB Output is correct
9 Correct 397 ms 176640 KB Output is correct
10 Correct 401 ms 176768 KB Output is correct
11 Correct 426 ms 176768 KB Output is correct
12 Correct 471 ms 176768 KB Output is correct