Submission #303656

# Submission time Handle Problem Language Result Execution time Memory
303656 2020-09-20T14:03:01 Z myungwoo Comparing Plants (IOI20_plants) C++17
100 / 100
1441 ms 17828 KB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;

#define MAXN 200005
#define debug(...) fprintf(stderr, __VA_ARGS__); fflush(stderr);

const int TS = 1<<20, ST = TS/2-1;
int N, K, R[MAXN*2];
int A[MAXN*2], B[MAXN*2];

struct SegTree{
	struct Value{
		int value, lazysum;
	};
	Value tree[TS];
	void build(int arr[]){
		memset(tree, 0, sizeof(tree));
		for (int i=ST+1;i<TS;i++) tree[i].value = i-ST <= N+N ? arr[i-ST] : 1e9;
		for (int i=ST;i;i--) tree[i].value = min(tree[i*2].value, tree[i*2+1].value);
	}
	void propagate(int n){
		if (n <= ST){
			tree[n*2].value += tree[n].lazysum, tree[n*2+1].value += tree[n].lazysum;
			tree[n*2].lazysum += tree[n].lazysum, tree[n*2+1].lazysum += tree[n].lazysum;
		}
		tree[n].lazysum = 0;
	}
	void update(int n, int s, int e, int l, int r, const int &v){
		if (l > r || e < l || r < s) return;
		if (l <= s && e <= r){
			tree[n].value += v, tree[n].lazysum += v;
			return;
		}
		propagate(n);
		int m = s+e >> 1;
		update(n*2, s, m, l, r, v);
		update(n*2+1, m+1, e, l, r, v);
		tree[n].value = min(tree[n*2].value, tree[n*2+1].value);
	}
	int findzero(int n){
		if (tree[n].value != 0) return 0;
		propagate(n);
		if (n > ST) return n-ST;
		if (!tree[n*2].value) return findzero(n*2);
		else if (!tree[n*2+1].value) return findzero(n*2+1);
		else assert(0);
	}
} segtree;

void get(int perm[])
{
	segtree.build(R);
	stack <int> wait;
	for (int ord=1;ord<=N+N;ord++){
		int x = segtree.findzero(1);
		while (!x){
			assert(!wait.empty());
			int q = wait.top(); wait.pop();
			segtree.update(1, 1, TS/2, q, N+N, -1);
			x = segtree.findzero(1);
		}
		perm[x] = ord;
		segtree.update(1, 1, TS/2, x, x, 1e9);
		segtree.update(1, 1, TS/2, max(1, x-K+1), x-1, -1);
		if (x-K+1 < 1) wait.push(N+N-(1-(x-K+1))+1);
	}
}

void init(int K, vector<int> r)
{
	::K = K;
	N = r.size();
	for (int i=1;i<=N;i++) R[N+i] = R[i] = r[i-1];
	get(A);
	for (int i=1;i<=N+N;i++) R[i] = K-R[i]-1;
	get(B);
}

int compare_plants(int x, int y)
{
	if (x > y) return -compare_plants(y, x);
	x++; y++;
	if (A[x] > A[y] || B[y] > B[x+N]) return -1;
	if (B[x] > B[y] || A[y] > A[x+N]) return 1;
	return 0;
}

Compilation message

plants.cpp: In member function 'void SegTree::update(int, int, int, int, int, const int&)':
plants.cpp:36:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |   int m = s+e >> 1;
      |           ~^~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 9 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 74 ms 11328 KB Output is correct
7 Correct 147 ms 12028 KB Output is correct
8 Correct 730 ms 17320 KB Output is correct
9 Correct 733 ms 17272 KB Output is correct
10 Correct 734 ms 17144 KB Output is correct
11 Correct 722 ms 17144 KB Output is correct
12 Correct 718 ms 17144 KB Output is correct
13 Correct 714 ms 17144 KB Output is correct
14 Correct 718 ms 17216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 10 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 15 ms 8704 KB Output is correct
7 Correct 114 ms 11512 KB Output is correct
8 Correct 11 ms 8576 KB Output is correct
9 Correct 15 ms 8704 KB Output is correct
10 Correct 104 ms 11512 KB Output is correct
11 Correct 97 ms 11512 KB Output is correct
12 Correct 121 ms 11640 KB Output is correct
13 Correct 104 ms 11512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 10 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 15 ms 8704 KB Output is correct
7 Correct 114 ms 11512 KB Output is correct
8 Correct 11 ms 8576 KB Output is correct
9 Correct 15 ms 8704 KB Output is correct
10 Correct 104 ms 11512 KB Output is correct
11 Correct 97 ms 11512 KB Output is correct
12 Correct 121 ms 11640 KB Output is correct
13 Correct 104 ms 11512 KB Output is correct
14 Correct 184 ms 12024 KB Output is correct
15 Correct 1441 ms 17400 KB Output is correct
16 Correct 193 ms 12024 KB Output is correct
17 Correct 1431 ms 17272 KB Output is correct
18 Correct 943 ms 17620 KB Output is correct
19 Correct 989 ms 17828 KB Output is correct
20 Correct 1381 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 96 ms 11384 KB Output is correct
4 Correct 781 ms 17272 KB Output is correct
5 Correct 876 ms 17276 KB Output is correct
6 Correct 1117 ms 17092 KB Output is correct
7 Correct 1327 ms 17316 KB Output is correct
8 Correct 1388 ms 17272 KB Output is correct
9 Correct 815 ms 17216 KB Output is correct
10 Correct 801 ms 17228 KB Output is correct
11 Correct 714 ms 17084 KB Output is correct
12 Correct 832 ms 17180 KB Output is correct
13 Correct 937 ms 17440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 9 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 11 ms 8576 KB Output is correct
7 Correct 25 ms 9216 KB Output is correct
8 Correct 25 ms 9216 KB Output is correct
9 Correct 26 ms 9216 KB Output is correct
10 Correct 25 ms 9216 KB Output is correct
11 Correct 25 ms 9216 KB Output is correct
12 Correct 26 ms 9208 KB Output is correct
13 Correct 30 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 8 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 10 ms 8576 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 864 ms 17320 KB Output is correct
7 Correct 1082 ms 17276 KB Output is correct
8 Correct 1281 ms 17316 KB Output is correct
9 Correct 1389 ms 17144 KB Output is correct
10 Correct 801 ms 17208 KB Output is correct
11 Correct 1082 ms 17400 KB Output is correct
12 Correct 759 ms 17132 KB Output is correct
13 Correct 855 ms 17316 KB Output is correct
14 Correct 1079 ms 17272 KB Output is correct
15 Correct 1296 ms 17296 KB Output is correct
16 Correct 758 ms 17144 KB Output is correct
17 Correct 841 ms 17400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 9 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 74 ms 11328 KB Output is correct
7 Correct 147 ms 12028 KB Output is correct
8 Correct 730 ms 17320 KB Output is correct
9 Correct 733 ms 17272 KB Output is correct
10 Correct 734 ms 17144 KB Output is correct
11 Correct 722 ms 17144 KB Output is correct
12 Correct 718 ms 17144 KB Output is correct
13 Correct 714 ms 17144 KB Output is correct
14 Correct 718 ms 17216 KB Output is correct
15 Correct 9 ms 8576 KB Output is correct
16 Correct 9 ms 8576 KB Output is correct
17 Correct 10 ms 8576 KB Output is correct
18 Correct 10 ms 8576 KB Output is correct
19 Correct 9 ms 8576 KB Output is correct
20 Correct 15 ms 8704 KB Output is correct
21 Correct 114 ms 11512 KB Output is correct
22 Correct 11 ms 8576 KB Output is correct
23 Correct 15 ms 8704 KB Output is correct
24 Correct 104 ms 11512 KB Output is correct
25 Correct 97 ms 11512 KB Output is correct
26 Correct 121 ms 11640 KB Output is correct
27 Correct 104 ms 11512 KB Output is correct
28 Correct 184 ms 12024 KB Output is correct
29 Correct 1441 ms 17400 KB Output is correct
30 Correct 193 ms 12024 KB Output is correct
31 Correct 1431 ms 17272 KB Output is correct
32 Correct 943 ms 17620 KB Output is correct
33 Correct 989 ms 17828 KB Output is correct
34 Correct 1381 ms 17272 KB Output is correct
35 Correct 9 ms 8576 KB Output is correct
36 Correct 9 ms 8576 KB Output is correct
37 Correct 96 ms 11384 KB Output is correct
38 Correct 781 ms 17272 KB Output is correct
39 Correct 876 ms 17276 KB Output is correct
40 Correct 1117 ms 17092 KB Output is correct
41 Correct 1327 ms 17316 KB Output is correct
42 Correct 1388 ms 17272 KB Output is correct
43 Correct 815 ms 17216 KB Output is correct
44 Correct 801 ms 17228 KB Output is correct
45 Correct 714 ms 17084 KB Output is correct
46 Correct 832 ms 17180 KB Output is correct
47 Correct 937 ms 17440 KB Output is correct
48 Correct 9 ms 8576 KB Output is correct
49 Correct 9 ms 8576 KB Output is correct
50 Correct 9 ms 8576 KB Output is correct
51 Correct 9 ms 8576 KB Output is correct
52 Correct 9 ms 8576 KB Output is correct
53 Correct 11 ms 8576 KB Output is correct
54 Correct 25 ms 9216 KB Output is correct
55 Correct 25 ms 9216 KB Output is correct
56 Correct 26 ms 9216 KB Output is correct
57 Correct 25 ms 9216 KB Output is correct
58 Correct 25 ms 9216 KB Output is correct
59 Correct 26 ms 9208 KB Output is correct
60 Correct 30 ms 9208 KB Output is correct
61 Correct 87 ms 11512 KB Output is correct
62 Correct 149 ms 11896 KB Output is correct
63 Correct 777 ms 17272 KB Output is correct
64 Correct 868 ms 17272 KB Output is correct
65 Correct 1119 ms 17132 KB Output is correct
66 Correct 1308 ms 17272 KB Output is correct
67 Correct 1399 ms 17272 KB Output is correct
68 Correct 819 ms 17236 KB Output is correct
69 Correct 1075 ms 17400 KB Output is correct
70 Correct 786 ms 17144 KB Output is correct
71 Correct 885 ms 17272 KB Output is correct
72 Correct 1106 ms 17348 KB Output is correct
73 Correct 1312 ms 17312 KB Output is correct
74 Correct 786 ms 17216 KB Output is correct
75 Correct 870 ms 17252 KB Output is correct