Submission #305042

# Submission time Handle Problem Language Result Execution time Memory
305042 2020-09-22T12:58:38 Z Wu_Ren Comparing Plants (IOI20_plants) C++11
100 / 100
1509 ms 22768 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
int tag[1600010],mn[1600010],st[400010],t=0,n,k;
vector<int>tmp1,tmp2;
void pushdown(int t){
	mn[t<<1]+=tag[t];
	mn[t<<1|1]+=tag[t];
	tag[t<<1]+=tag[t];
	tag[t<<1|1]+=tag[t];
	tag[t]=0;
}
void add(int ll,int rr,int l,int r,int t,int c){
	if(rr<l||ll>r) return;
	if(ll<=l&&r<=rr){
		tag[t]+=c;
		mn[t]+=c;
		return;
	}
	pushdown(t);
	int mid=(l+r)>>1;
	if(ll<=mid) add(ll,rr,l,mid,t<<1,c);
	if(mid<rr) add(ll,rr,mid+1,r,t<<1|1,c);
	mn[t]=min(mn[t<<1],mn[t<<1|1]);
}
int query(int l,int r,int t){
	if(mn[t]>0) return -1;
	if(l==r) return l;
	pushdown(t);
	int mid=(l+r)>>1;
	if(mn[t<<1]>0) return query(mid+1,r,t<<1|1);
	else return query(l,mid,t<<1);
}
vector<int> work(vector<int> now){
	vector<int>ans;
	ans.resize(now.size());
	t=0,memset(tag,0,sizeof(tag)),memset(mn,0,sizeof(mn));
	for(int i=0;i<2*n;i++) add(i,i,0,2*n-1,1,now[i]);
	for(int i=1;i<=2*n;i++){
		int x=query(0,2*n-1,1);
		while(x<0&&t) add(st[t],2*n-1,0,2*n-1,1,-1),t--,x=query(0,2*n-1,1);
		ans[x]=i;
		add(x,x,0,2*n-1,1,1e9);
		add(x-k+1,x-1,0,2*n-1,1,-1);
		if(x-k+1<0) st[++t]=2*n+x-k;
	}
	return ans;
}
void init(int _k,vector<int> r){
	n=r.size(),k=_k;
	for(int i=0;i<n;i++) r.push_back(r[i]);
	tmp1=work(r);
	for(int i=0;i<2*n;i++) r[i]=k-1-r[i];
	tmp2=work(r);
}
int compare_plants(int x, int y){
	if(x>y) return -compare_plants(y,x);
	if(tmp1[x]>tmp1[y]||tmp2[x+n]<tmp2[y]) return -1;
	if(tmp2[x]>tmp2[y]||tmp1[x+n]<tmp1[y]) return 1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12800 KB Output is correct
2 Correct 9 ms 12800 KB Output is correct
3 Correct 10 ms 12800 KB Output is correct
4 Correct 9 ms 12800 KB Output is correct
5 Correct 9 ms 12800 KB Output is correct
6 Correct 71 ms 15608 KB Output is correct
7 Correct 151 ms 16200 KB Output is correct
8 Correct 839 ms 22220 KB Output is correct
9 Correct 847 ms 22220 KB Output is correct
10 Correct 844 ms 22348 KB Output is correct
11 Correct 849 ms 22288 KB Output is correct
12 Correct 840 ms 22348 KB Output is correct
13 Correct 838 ms 22348 KB Output is correct
14 Correct 860 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12800 KB Output is correct
2 Correct 10 ms 12800 KB Output is correct
3 Correct 10 ms 12800 KB Output is correct
4 Correct 10 ms 12800 KB Output is correct
5 Correct 10 ms 12800 KB Output is correct
6 Correct 15 ms 12928 KB Output is correct
7 Correct 101 ms 15864 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
9 Correct 14 ms 12952 KB Output is correct
10 Correct 105 ms 15992 KB Output is correct
11 Correct 99 ms 15864 KB Output is correct
12 Correct 96 ms 16116 KB Output is correct
13 Correct 103 ms 16024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12800 KB Output is correct
2 Correct 10 ms 12800 KB Output is correct
3 Correct 10 ms 12800 KB Output is correct
4 Correct 10 ms 12800 KB Output is correct
5 Correct 10 ms 12800 KB Output is correct
6 Correct 15 ms 12928 KB Output is correct
7 Correct 101 ms 15864 KB Output is correct
8 Correct 11 ms 12928 KB Output is correct
9 Correct 14 ms 12952 KB Output is correct
10 Correct 105 ms 15992 KB Output is correct
11 Correct 99 ms 15864 KB Output is correct
12 Correct 96 ms 16116 KB Output is correct
13 Correct 103 ms 16024 KB Output is correct
14 Correct 183 ms 16212 KB Output is correct
15 Correct 1496 ms 22348 KB Output is correct
16 Correct 185 ms 16312 KB Output is correct
17 Correct 1504 ms 22348 KB Output is correct
18 Correct 1055 ms 22768 KB Output is correct
19 Correct 1053 ms 22604 KB Output is correct
20 Correct 1430 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12800 KB Output is correct
2 Correct 9 ms 12800 KB Output is correct
3 Correct 86 ms 15796 KB Output is correct
4 Correct 897 ms 22348 KB Output is correct
5 Correct 993 ms 22348 KB Output is correct
6 Correct 1199 ms 22220 KB Output is correct
7 Correct 1395 ms 22348 KB Output is correct
8 Correct 1509 ms 22476 KB Output is correct
9 Correct 935 ms 22348 KB Output is correct
10 Correct 930 ms 22220 KB Output is correct
11 Correct 845 ms 22348 KB Output is correct
12 Correct 950 ms 22348 KB Output is correct
13 Correct 1076 ms 22604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12800 KB Output is correct
2 Correct 9 ms 12800 KB Output is correct
3 Correct 9 ms 12800 KB Output is correct
4 Correct 11 ms 12800 KB Output is correct
5 Correct 10 ms 12800 KB Output is correct
6 Correct 14 ms 12928 KB Output is correct
7 Correct 26 ms 13440 KB Output is correct
8 Correct 25 ms 13440 KB Output is correct
9 Correct 25 ms 13440 KB Output is correct
10 Correct 25 ms 13440 KB Output is correct
11 Correct 25 ms 13436 KB Output is correct
12 Correct 25 ms 13440 KB Output is correct
13 Correct 26 ms 13440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12800 KB Output is correct
2 Correct 10 ms 12800 KB Output is correct
3 Correct 10 ms 12800 KB Output is correct
4 Correct 10 ms 12800 KB Output is correct
5 Correct 12 ms 12928 KB Output is correct
6 Correct 973 ms 22348 KB Output is correct
7 Correct 1205 ms 22352 KB Output is correct
8 Correct 1421 ms 22348 KB Output is correct
9 Correct 1494 ms 22348 KB Output is correct
10 Correct 921 ms 22292 KB Output is correct
11 Correct 1198 ms 22476 KB Output is correct
12 Correct 889 ms 22348 KB Output is correct
13 Correct 984 ms 22348 KB Output is correct
14 Correct 1222 ms 22476 KB Output is correct
15 Correct 1403 ms 22348 KB Output is correct
16 Correct 884 ms 22348 KB Output is correct
17 Correct 983 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12800 KB Output is correct
2 Correct 9 ms 12800 KB Output is correct
3 Correct 10 ms 12800 KB Output is correct
4 Correct 9 ms 12800 KB Output is correct
5 Correct 9 ms 12800 KB Output is correct
6 Correct 71 ms 15608 KB Output is correct
7 Correct 151 ms 16200 KB Output is correct
8 Correct 839 ms 22220 KB Output is correct
9 Correct 847 ms 22220 KB Output is correct
10 Correct 844 ms 22348 KB Output is correct
11 Correct 849 ms 22288 KB Output is correct
12 Correct 840 ms 22348 KB Output is correct
13 Correct 838 ms 22348 KB Output is correct
14 Correct 860 ms 22220 KB Output is correct
15 Correct 10 ms 12800 KB Output is correct
16 Correct 10 ms 12800 KB Output is correct
17 Correct 10 ms 12800 KB Output is correct
18 Correct 10 ms 12800 KB Output is correct
19 Correct 10 ms 12800 KB Output is correct
20 Correct 15 ms 12928 KB Output is correct
21 Correct 101 ms 15864 KB Output is correct
22 Correct 11 ms 12928 KB Output is correct
23 Correct 14 ms 12952 KB Output is correct
24 Correct 105 ms 15992 KB Output is correct
25 Correct 99 ms 15864 KB Output is correct
26 Correct 96 ms 16116 KB Output is correct
27 Correct 103 ms 16024 KB Output is correct
28 Correct 183 ms 16212 KB Output is correct
29 Correct 1496 ms 22348 KB Output is correct
30 Correct 185 ms 16312 KB Output is correct
31 Correct 1504 ms 22348 KB Output is correct
32 Correct 1055 ms 22768 KB Output is correct
33 Correct 1053 ms 22604 KB Output is correct
34 Correct 1430 ms 22220 KB Output is correct
35 Correct 9 ms 12800 KB Output is correct
36 Correct 9 ms 12800 KB Output is correct
37 Correct 86 ms 15796 KB Output is correct
38 Correct 897 ms 22348 KB Output is correct
39 Correct 993 ms 22348 KB Output is correct
40 Correct 1199 ms 22220 KB Output is correct
41 Correct 1395 ms 22348 KB Output is correct
42 Correct 1509 ms 22476 KB Output is correct
43 Correct 935 ms 22348 KB Output is correct
44 Correct 930 ms 22220 KB Output is correct
45 Correct 845 ms 22348 KB Output is correct
46 Correct 950 ms 22348 KB Output is correct
47 Correct 1076 ms 22604 KB Output is correct
48 Correct 11 ms 12800 KB Output is correct
49 Correct 9 ms 12800 KB Output is correct
50 Correct 9 ms 12800 KB Output is correct
51 Correct 11 ms 12800 KB Output is correct
52 Correct 10 ms 12800 KB Output is correct
53 Correct 14 ms 12928 KB Output is correct
54 Correct 26 ms 13440 KB Output is correct
55 Correct 25 ms 13440 KB Output is correct
56 Correct 25 ms 13440 KB Output is correct
57 Correct 25 ms 13440 KB Output is correct
58 Correct 25 ms 13436 KB Output is correct
59 Correct 25 ms 13440 KB Output is correct
60 Correct 26 ms 13440 KB Output is correct
61 Correct 84 ms 15736 KB Output is correct
62 Correct 152 ms 16184 KB Output is correct
63 Correct 894 ms 22220 KB Output is correct
64 Correct 986 ms 22348 KB Output is correct
65 Correct 1216 ms 22348 KB Output is correct
66 Correct 1410 ms 22348 KB Output is correct
67 Correct 1476 ms 22348 KB Output is correct
68 Correct 937 ms 22348 KB Output is correct
69 Correct 1233 ms 22476 KB Output is correct
70 Correct 895 ms 22220 KB Output is correct
71 Correct 989 ms 22248 KB Output is correct
72 Correct 1225 ms 22348 KB Output is correct
73 Correct 1410 ms 22476 KB Output is correct
74 Correct 905 ms 22220 KB Output is correct
75 Correct 973 ms 22348 KB Output is correct