Submission #682674

# Submission time Handle Problem Language Result Execution time Memory
682674 2023-01-16T18:07:43 Z CyberCow Divide and conquer (IZhO14_divide) C++17
100 / 100
75 ms 8088 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
#define fi first
#define se second
using namespace std;
using ll = long long;
vector<pair<ll, pair<ll, ll>>> v;
ll ans = 0;

void conc(int l, int r)
{
	if (l == r)
	{
		ans = max(ans, v[l].se.fi);
		return;
	}
	int m = (l + r) / 2;
	ll gum = 1, hashv = 0, zoloto = 0, demipox = 0;
	vector<pair<ll ,ll>> a;
	vector<ll> mi;
	for (int i = m + 1; i <= r; i++)
	{
		zoloto += v[i].se.fi;
		hashv += v[i].se.se - (v[i].fi - v[i - 1].fi);
		a.push_back({hashv, zoloto});
		mi.push_back(0);
	}
	sort(a.begin(), a.end());
	mi.back() = a.back().second;
	for (int i = mi.size() - 2; i >= 0; i--)
	{
		mi[i] = max(mi[i + 1], a[i].second);
	}
	for (int i = m; i >= l; i--)
	{
		gum += v[i].se.se;
		demipox += v[i].se.fi;
		int ind = lower_bound(a.begin(), a.end(), make_pair(-(gum - (v[m].fi - v[i].fi + 1)), 0LL)) - a.begin();
		if (ind < a.size())
		{
			ans = max(ans, mi[ind] + demipox);
		}
	}
	conc(l, m);
	conc(m + 1, r);
}

void solve()
{
	int n, i, j, x, y, a, b, c;
	cin >> n;
	for ( i = 0; i < n; i++)
	{
		cin >> a >> b >> c;
		v.push_back({ a, {b, c} });
	}
	conc(0,n - 1);
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--)
	{
		solve();
	}
	return 0;
}

Compilation message

divide.cpp: In function 'void conc(int, int)':
divide.cpp:52:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   if (ind < a.size())
      |       ~~~~^~~~~~~~~~
divide.cpp: In function 'void solve()':
divide.cpp:63:12: warning: unused variable 'j' [-Wunused-variable]
   63 |  int n, i, j, x, y, a, b, c;
      |            ^
divide.cpp:63:15: warning: unused variable 'x' [-Wunused-variable]
   63 |  int n, i, j, x, y, a, b, c;
      |               ^
divide.cpp:63:18: warning: unused variable 'y' [-Wunused-variable]
   63 |  int n, i, j, x, y, a, b, c;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 328 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 328 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 3 ms 712 KB Output is correct
25 Correct 3 ms 660 KB Output is correct
26 Correct 6 ms 976 KB Output is correct
27 Correct 6 ms 1044 KB Output is correct
28 Correct 33 ms 3780 KB Output is correct
29 Correct 33 ms 4236 KB Output is correct
30 Correct 69 ms 8088 KB Output is correct
31 Correct 61 ms 6904 KB Output is correct
32 Correct 68 ms 7028 KB Output is correct
33 Correct 66 ms 6940 KB Output is correct
34 Correct 75 ms 6900 KB Output is correct
35 Correct 60 ms 7412 KB Output is correct
36 Correct 68 ms 7584 KB Output is correct