Submission #106815

# Submission time Handle Problem Language Result Execution time Memory
106815 2019-04-20T15:29:29 Z eriksuenderhauf Two Dishes (JOI19_dishes) C++11
0 / 100
530 ms 32292 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll a[MAXN], b[MAXN];
ll s[MAXN], p[MAXN], q[MAXN], t[MAXN];
map<pii,ll> pts;
ll seg[MAXN], lazy[MAXN];

void prop(int l, int r, int k) {
	if (l != r) {
		lazy[k*2]+=lazy[k];
		lazy[k*2+1]+=lazy[k];
	}
	lazy[k] = 0;
}

ll qry(int l, int r, int k, int a, int b) {
	if (r < a || b < l || a > b) return -INF;
	seg[k] += lazy[k];
	prop(l,r,k);
	if (a <= l && r <= b) return seg[k];
	int m = (l + r) / 2;
	return max(qry(l,m,k*2,a,b),qry(m+1,r,k*2+1,a,b));
}

void upd1(int l, int r, int k, int a, ll v) {
	if (a < l || r < a) return;
	seg[k] += lazy[k];
	prop(l,r,k);
	if (a <= l && r <= a) {
		seg[k] = v;
		return;
	}
	int m = (l + r) / 2;
	upd1(l, m, k*2, a, v);
	upd1(m+1, r, k*2+1, a, v);
	seg[k] = max(seg[k*2],seg[k*2+1]);
}

void upd2(int l, int r, int k, int a, int b, ll v) {
	if (b < l || r < a) return;
	seg[k] += lazy[k];
	prop(l,r,k);
	if (a <= l && r <= b) {
		seg[k] += v;
		lazy[k] = v;
		prop(l, r, k);
		return;
	}
	int m = (l + r) / 2;
	upd2(l, m, k*2, a, b, v);
	upd2(m+1, r, k*2+1, a, b, v);
	seg[k] = max(seg[k*2],seg[k*2+1]);
}

int main() {
	int n, m;
	ll ans = 0;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld %lld %lld", &a[i], &s[i], &p[i]);
		a[i] += a[i - 1];
	}
	for (int i = 1; i <= m; i++) {
		scanf("%lld %lld %lld", &b[i], &t[i], &q[i]);
		b[i] += b[i - 1];
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] > s[i]) continue;
		if (a[i] + b[m] <= s[i]) {
			ans += p[i];
			continue;
		}
		int ind = upper_bound(b+1, b+1 + m, s[i]-a[i]) - b-1;
		pts[{i-1, -(ind+1)}] += p[i];
	}
	for (int i = 1; i <= n; i++) {
		if (b[i] > t[i]) continue;
		if (b[i] + a[n] <= t[i]) {
			ans += q[i];
			continue;
		}
		int ind = upper_bound(a+1, a+1 + n, t[i]-b[i]) - a-1;
		ans += q[i];
		pts[{ind, -i}] -= q[i];
	}
	for (auto &it: pts) {
		int x, y;
		tie(x, y) = it.fi;
		ll c = it.se;
		//cerr << x << " " << -y << " " << c << "\n";
		ll tmp = qry(0, m, 1, 0, -y - 1);
		upd1(0, m, 1, -y, tmp);
		upd2(0, m, 1, 0, -y - 1, c);
	}
	prl(ans+qry(0,m,1,0,m));
    return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
dishes.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &a[i], &s[i], &p[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &b[i], &t[i], &q[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 520 ms 32292 KB Output is correct
2 Correct 530 ms 31304 KB Output is correct
3 Correct 190 ms 9948 KB Output is correct
4 Correct 368 ms 22888 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 431 ms 28176 KB Output is correct
7 Incorrect 108 ms 5356 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 356 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 520 ms 32292 KB Output is correct
2 Correct 530 ms 31304 KB Output is correct
3 Correct 190 ms 9948 KB Output is correct
4 Correct 368 ms 22888 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 431 ms 28176 KB Output is correct
7 Incorrect 108 ms 5356 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 520 ms 32292 KB Output is correct
2 Correct 530 ms 31304 KB Output is correct
3 Correct 190 ms 9948 KB Output is correct
4 Correct 368 ms 22888 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 431 ms 28176 KB Output is correct
7 Incorrect 108 ms 5356 KB Output isn't correct
8 Halted 0 ms 0 KB -