Submission #301627

# Submission time Handle Problem Language Result Execution time Memory
301627 2020-09-18T05:31:51 Z maximath_1 Comparing Plants (IOI20_plants) C++11
49 / 100
1668 ms 30704 KB
#include "plants.h"
#include <vector>
#include <iostream>
using namespace std;

#define ll long long
const ll inf = 1e18;
int n, arr[200005];
vector<int> r;

pair<ll, int> st[200005 * 4][2];

void build(int nd, int cl, int cr, int tp){
	st[nd][tp] = {0, cl};
	if(cl != cr){
		build(nd * 2, cl, (cl + cr) / 2, tp);
		build(nd * 2 + 1, (cl + cr) / 2 + 1, cr, tp);
	}
}

ll lz[200005 * 4][2];

void prop(int nd, int cl, int cr, int tp){
	if(lz[nd][tp]){
		st[nd][tp].first += lz[nd][tp];
		if(cl != cr){
			lz[nd * 2][tp] += lz[nd][tp];
			lz[nd * 2 + 1][tp] += lz[nd][tp];
		}
		lz[nd][tp] = 0;
	}
}

void upd(int nd, int cl, int cr, int l, int r, ll vv, int tp){
	prop(nd, cl, cr, tp);
	if(cr < l || r < cl) return;
	if(l <= cl && cr <= r){
		lz[nd][tp] += vv;
		prop(nd, cl, cr, tp);
		return;
	}

	upd(nd * 2, cl, (cl + cr) / 2, l, r, vv, tp);
	upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, l, r, vv, tp);
	st[nd][tp] = min(st[nd * 2][tp], st[nd * 2 + 1][tp]);
}

ll que(int nd, int cl, int cr, int l, int r, int tp){
	prop(nd, cl, cr, tp);
	if(cr < l || r < cl) return inf;
	if(l <= cl && cr <= r) return st[nd][tp].first;

	return min(que(nd * 2, cl, (cl + cr) / 2, l, r, tp), que(nd * 2 + 1, (cl + cr) / 2 + 1, cr, l, r, tp));
}

void update(int l, int r, ll vv, int tp){
	if(l <= r)
		upd(1, 0, n - 1, l, r, vv, tp);
	else{
		upd(1, 0, n - 1, l, n - 1, vv, tp);
		upd(1, 0, n - 1, 0, r, vv, tp);
	}
}

int kk;
vector<int> pref;

void init(int k, vector<int> r){
	n = r.size();
	pref.resize(n + 1);
	for(int i = 0; i < n; i ++)
		pref[i + 1] = pref[i] + r[i];
	kk = k;
	if(kk == 2) return;

	build(1, 0, n - 1, 0);build(1, 0, n - 1, 1);
//	exit(0);
	for(int i = 0; i < n; i ++){
		update(i, i, r[i], 0);
		update(i, i, r[i], 1);
	}

	while(st[1][1].first == 0){
		int ps = st[1][1].second;
		update(ps, ps, inf, 1);
		update((ps + 1) % n, (ps + (k - 1)) % n, 1, 0);
	}

	for(int vv = n; vv > 0; vv --){
		int id = st[1][0].second;
		arr[id] = vv;

		update((id + 1) % n, (id + (k - 1)) % n, -1, 0);
		update((id + n - (k - 1)) % n, (id + n - 1) % n, -1, 0);
		update((id + n - (k - 1)) % n, (id + n - 1) % n, -1, 1);

		while(st[1][1].first == 0){
			int ps = st[1][1].second;
			update(ps, ps, inf, 1);
			update((ps + 1) % n, (ps + (k - 1)) % n, 1, 0);
		}

		update(id, id, inf, 0);
	}
}

int compare_plants(int x, int y){
	if(kk == 2){
		if(pref[y] == pref[x]) return 1;
		if(pref[y] - pref[x] == y - x) return -1;
		if(pref[n] - (pref[y] - pref[x]) == n - (y - x)) return 1;
		if(pref[n] == (pref[y] - pref[x])) return -1;
		return 0;
	}
	if(arr[x] < arr[y]) return -1;
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 92 ms 3192 KB Output is correct
7 Correct 88 ms 3448 KB Output is correct
8 Correct 113 ms 5112 KB Output is correct
9 Correct 106 ms 5068 KB Output is correct
10 Correct 99 ms 4984 KB Output is correct
11 Correct 100 ms 5024 KB Output is correct
12 Correct 100 ms 4984 KB Output is correct
13 Correct 95 ms 5056 KB Output is correct
14 Correct 99 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 90 ms 4088 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 90 ms 4088 KB Output is correct
11 Correct 86 ms 3960 KB Output is correct
12 Correct 92 ms 4156 KB Output is correct
13 Correct 94 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 90 ms 4088 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 7 ms 512 KB Output is correct
10 Correct 90 ms 4088 KB Output is correct
11 Correct 86 ms 3960 KB Output is correct
12 Correct 92 ms 4156 KB Output is correct
13 Correct 94 ms 4088 KB Output is correct
14 Correct 187 ms 6580 KB Output is correct
15 Correct 1668 ms 30496 KB Output is correct
16 Correct 189 ms 6648 KB Output is correct
17 Correct 1623 ms 30456 KB Output is correct
18 Correct 1026 ms 30460 KB Output is correct
19 Correct 1040 ms 30456 KB Output is correct
20 Correct 1405 ms 30504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 72 ms 3448 KB Output is correct
4 Correct 813 ms 29996 KB Output is correct
5 Correct 1010 ms 30468 KB Output is correct
6 Correct 1236 ms 30528 KB Output is correct
7 Correct 1467 ms 30456 KB Output is correct
8 Correct 1595 ms 30540 KB Output is correct
9 Correct 917 ms 30376 KB Output is correct
10 Correct 887 ms 30500 KB Output is correct
11 Correct 94 ms 4984 KB Output is correct
12 Correct 803 ms 30456 KB Output is correct
13 Correct 984 ms 30704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 92 ms 3192 KB Output is correct
7 Correct 88 ms 3448 KB Output is correct
8 Correct 113 ms 5112 KB Output is correct
9 Correct 106 ms 5068 KB Output is correct
10 Correct 99 ms 4984 KB Output is correct
11 Correct 100 ms 5024 KB Output is correct
12 Correct 100 ms 4984 KB Output is correct
13 Correct 95 ms 5056 KB Output is correct
14 Correct 99 ms 4984 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 90 ms 4088 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 90 ms 4088 KB Output is correct
25 Correct 86 ms 3960 KB Output is correct
26 Correct 92 ms 4156 KB Output is correct
27 Correct 94 ms 4088 KB Output is correct
28 Correct 187 ms 6580 KB Output is correct
29 Correct 1668 ms 30496 KB Output is correct
30 Correct 189 ms 6648 KB Output is correct
31 Correct 1623 ms 30456 KB Output is correct
32 Correct 1026 ms 30460 KB Output is correct
33 Correct 1040 ms 30456 KB Output is correct
34 Correct 1405 ms 30504 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 72 ms 3448 KB Output is correct
38 Correct 813 ms 29996 KB Output is correct
39 Correct 1010 ms 30468 KB Output is correct
40 Correct 1236 ms 30528 KB Output is correct
41 Correct 1467 ms 30456 KB Output is correct
42 Correct 1595 ms 30540 KB Output is correct
43 Correct 917 ms 30376 KB Output is correct
44 Correct 887 ms 30500 KB Output is correct
45 Correct 94 ms 4984 KB Output is correct
46 Correct 803 ms 30456 KB Output is correct
47 Correct 984 ms 30704 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 1 ms 360 KB Output is correct
50 Correct 0 ms 256 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Incorrect 1 ms 384 KB Output isn't correct
53 Halted 0 ms 0 KB -