Submission #878413

# Submission time Handle Problem Language Result Execution time Memory
878413 2023-11-24T10:28:06 Z auslander Divide and conquer (IZhO14_divide) C++17
100 / 100
25 ms 7644 KB
#include <iostream>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <string>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <iterator>
using namespace std;

//defines
#define ll long long
#define usg unsigned
#define kap map
#define print(x, n) for(int for_loop = 0; for_loop < n; for_loop++){cout<<x[for_loop]<<' ';}cout<<endl; 
#define read(x, n) for(int for_loop = 0; for_loop < n; for_loop++){cin>>x[for_loop];} 
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ratdig(x) cout << fixed << setprecision(x);
#define xfixdig(x) cout << setprecision(x);
#define multi int t; cin>>t; presolve(); while(t--) solve()
#define single presolve(); solve(); return 0
#define rev(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()

//functions
void yn(bool b)
{
	if (b)
	{
		cout << "YES\n";
		return;
	}
	cout << "NO\n";
}

ll gcd(ll a, ll b) {
	if (a == 0)
		return b;
	if (b == 0)
		return a;
	return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
	return (a * b) / gcd(a, b);
}

string to2(ll a)
{
	string r = "";
	for (ll i = a; i > 0; )
	{
		ll k = i % 2;
		i /= 2;
		char c = k + 48;
		r += c;
	}
	if (a == 0)
	{
		r = "0";
	}
	rev(r);

	return r;
}

ll binpow(ll a, ll b, ll mod = -1)
{
	ll ans = 1;
	while (b)
	{
		if ((b & 1) == 1)
		{
			ans *= a;
			if (mod != -1)
				ans %= mod;
		}
		b >>= 1;
		a *= a;
		if (mod != -1)
			a %= mod;
	}
	return ans;
}

//body

void presolve()
{

}

#define midd mid + 1
#define poss pos * 2
#define middle ll mid = (l + r) / 2

const int N = 100005;
ll t[4 * N], e[N], g[N], x[N];

void build(ll l, ll r, ll pos)
{
	if (l == r)
	{
		if (l > 0)
			t[pos] = e[l - 1] - x[l];
		else t[pos] = -x[l];
		return;
	}
	middle;
	build(l, mid, poss);
	build(midd, r, poss + 1);
	t[pos] = min(t[poss], t[poss + 1]);
}

ll query(ll l, ll r, ll u, ll pos)
{
	middle;
	if (l == r)
	{
		return r;
	}
	if (t[poss] <= u)
		return query(l, mid, u, poss);
	return query(midd, r, u, poss + 1);
}

void solve()
{
	ll i, j, k, m, r, n;
	cin >> n;
	k = 0;
	m = 0;
	for (i = 0; i < n; i++)
	{
		cin >> x[i] >> g[i] >> e[i];
		g[i] += k;
		e[i] += m;
		k = g[i];
		m = e[i];
	}
	build(0, n - 1, 1);
	ll res = g[0];
	ll mn = -x[0];
	for (i = 1; i < n; i++)
	{
		m = e[i] - x[i];
		if (mn > m)
		{
			res = max(res, g[i] - g[i - 1]);
			mn = e[i - 1] - x[i];
			continue;
		}
		//cout << i << endl;
		m = query(0, n - 1, m, 1);
		//cout << m << endl;
		if (m == 0)
		{
			res = max(res, g[i]);
		}
		else
		{
			res = max(res, g[i] - g[m - 1]);
		}
		mn = e[i - 1] - x[i];	
	}
	cout << res;
}

int main()
{
	speed;
	single;
	multi;

	return 0;
}

Compilation message

divide.cpp: In function 'void solve()':
divide.cpp:135:8: warning: unused variable 'j' [-Wunused-variable]
  135 |  ll i, j, k, m, r, n;
      |        ^
divide.cpp:135:17: warning: unused variable 'r' [-Wunused-variable]
  135 |  ll i, j, k, m, r, n;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4556 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4556 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4588 KB Output is correct
21 Correct 1 ms 4572 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 2 ms 4700 KB Output is correct
24 Correct 2 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4556 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4560 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4696 KB Output is correct
20 Correct 1 ms 4588 KB Output is correct
21 Correct 1 ms 4572 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 2 ms 4700 KB Output is correct
24 Correct 2 ms 4572 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 3 ms 4812 KB Output is correct
28 Correct 11 ms 5724 KB Output is correct
29 Correct 12 ms 5980 KB Output is correct
30 Correct 25 ms 7644 KB Output is correct
31 Correct 21 ms 6780 KB Output is correct
32 Correct 20 ms 6636 KB Output is correct
33 Correct 19 ms 6492 KB Output is correct
34 Correct 20 ms 6228 KB Output is correct
35 Correct 19 ms 6880 KB Output is correct
36 Correct 21 ms 7028 KB Output is correct