#include "plants.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct ST{
vector<pair<int,int> > st;
void init(int x){
st.resize(4*x);
}
void pull(int v){
st[v].fs=min(st[2*v+1].fs,st[2*v+2].fs);
}
void upd(int v,int x){
st[v].fs+=x;
st[v].sc+=x;
}
void build(int v,int L,int R,vector<int>& x){
if(L==R){
st[v].fs=x[L];
return;
}
int m=(L+R)/2;
build(2*v+1,L,m,x);
build(2*v+2,m+1,R,x);
pull(v);
}
void pudo(int v){
upd(2*v+1,st[v].sc);
upd(2*v+2,st[v].sc);
st[v].sc=0;
}
void update(int v,int L,int R,int l,int r,int t){
if(L==l && R==r){
upd(v,t);
return;
}
pudo(v);
int m=(L+R)/2;
if(r<=m){
update(2*v+1,L,m,l,r,t);
}
else if(l>m){
update(2*v+2,m+1,R,l,r,t);
}
else{
update(2*v+1,L,m,l,m,t);
update(2*v+2,m+1,R,m+1,r,t);
}
pull(v);
}
int finds(int v,int L,int R){
if(L==R){
return L;
}
if(st[v].fs>0){
return -1;
}
int m=(L+R)/2;
pudo(v);
if(st[2*v+1].fs>0){
return finds(2*v+2,m+1,R);
}
else{
return finds(2*v+1,L,m);
}
}
};
int k;
int n;
vector<int> a[2];
void get(vector<int> c,int g){
queue<int> s;
ST st;
int m=2*n;
a[g].resize(m);
st.init(m);
st.build(0,0,m-1,c);
for(int i=0;i<2*n;i++){
int x=st.finds(0,0,m-1);
while(x<0){
auto h=s.front();
s.pop();
st.update(0,0,m-1,h,m-1,-1);
x=st.finds(0,0,m-1);
}
st.update(0,0,m-1,x,x,1e9);
int l=x-k+1;
a[g][x]=i;
if(l<0){
st.update(0,0,m-1,0,x,-1);
s.push(l+m);
}
else{
st.update(0,0,m-1,l,x,-1);
}
}
}
void init(int K, vector<int> r){
k=K;
n=r.size();
vector<int> z(2*n);
for(int i=0;i<n;i++){
z[i]=z[i+n]=r[i];
}
get(z,0);
for(auto& h:z){
h=k-1-h;
}
get(z,1);
}
int compare_plants(int x, int y) {
if(x>y){
return -compare_plants(y,x);
}
if(a[0][x]>a[0][y] || a[1][y]>a[1][x+n]){
return -1;
}
else if(a[1][x]>a[1][y] || a[0][y]>a[0][x+n]){
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
40 ms |
4056 KB |
Output is correct |
7 |
Correct |
71 ms |
7184 KB |
Output is correct |
8 |
Correct |
353 ms |
25832 KB |
Output is correct |
9 |
Correct |
357 ms |
26032 KB |
Output is correct |
10 |
Correct |
352 ms |
25844 KB |
Output is correct |
11 |
Correct |
354 ms |
25924 KB |
Output is correct |
12 |
Correct |
353 ms |
25828 KB |
Output is correct |
13 |
Correct |
358 ms |
25920 KB |
Output is correct |
14 |
Correct |
351 ms |
25936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
300 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
52 ms |
5496 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
52 ms |
5544 KB |
Output is correct |
11 |
Correct |
47 ms |
5392 KB |
Output is correct |
12 |
Correct |
56 ms |
5544 KB |
Output is correct |
13 |
Correct |
51 ms |
5544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
300 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
52 ms |
5496 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
52 ms |
5544 KB |
Output is correct |
11 |
Correct |
47 ms |
5392 KB |
Output is correct |
12 |
Correct |
56 ms |
5544 KB |
Output is correct |
13 |
Correct |
51 ms |
5544 KB |
Output is correct |
14 |
Correct |
90 ms |
7140 KB |
Output is correct |
15 |
Correct |
615 ms |
26720 KB |
Output is correct |
16 |
Correct |
87 ms |
7284 KB |
Output is correct |
17 |
Correct |
608 ms |
26692 KB |
Output is correct |
18 |
Correct |
438 ms |
26684 KB |
Output is correct |
19 |
Correct |
438 ms |
27072 KB |
Output is correct |
20 |
Correct |
624 ms |
26684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
44 ms |
4952 KB |
Output is correct |
4 |
Correct |
379 ms |
25916 KB |
Output is correct |
5 |
Correct |
430 ms |
26060 KB |
Output is correct |
6 |
Correct |
504 ms |
26296 KB |
Output is correct |
7 |
Correct |
595 ms |
26472 KB |
Output is correct |
8 |
Correct |
607 ms |
26680 KB |
Output is correct |
9 |
Correct |
397 ms |
26016 KB |
Output is correct |
10 |
Correct |
395 ms |
26112 KB |
Output is correct |
11 |
Correct |
351 ms |
25916 KB |
Output is correct |
12 |
Correct |
404 ms |
26124 KB |
Output is correct |
13 |
Correct |
439 ms |
26328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
10 ms |
1236 KB |
Output is correct |
8 |
Correct |
10 ms |
1236 KB |
Output is correct |
9 |
Correct |
10 ms |
1252 KB |
Output is correct |
10 |
Correct |
12 ms |
1208 KB |
Output is correct |
11 |
Correct |
10 ms |
1236 KB |
Output is correct |
12 |
Correct |
10 ms |
1208 KB |
Output is correct |
13 |
Correct |
10 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
430 ms |
25248 KB |
Output is correct |
7 |
Correct |
513 ms |
25420 KB |
Output is correct |
8 |
Correct |
600 ms |
25624 KB |
Output is correct |
9 |
Correct |
602 ms |
25880 KB |
Output is correct |
10 |
Correct |
425 ms |
25180 KB |
Output is correct |
11 |
Correct |
502 ms |
25936 KB |
Output is correct |
12 |
Correct |
375 ms |
25072 KB |
Output is correct |
13 |
Correct |
430 ms |
25212 KB |
Output is correct |
14 |
Correct |
542 ms |
25408 KB |
Output is correct |
15 |
Correct |
624 ms |
25728 KB |
Output is correct |
16 |
Correct |
382 ms |
25076 KB |
Output is correct |
17 |
Correct |
443 ms |
25268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
40 ms |
4056 KB |
Output is correct |
7 |
Correct |
71 ms |
7184 KB |
Output is correct |
8 |
Correct |
353 ms |
25832 KB |
Output is correct |
9 |
Correct |
357 ms |
26032 KB |
Output is correct |
10 |
Correct |
352 ms |
25844 KB |
Output is correct |
11 |
Correct |
354 ms |
25924 KB |
Output is correct |
12 |
Correct |
353 ms |
25828 KB |
Output is correct |
13 |
Correct |
358 ms |
25920 KB |
Output is correct |
14 |
Correct |
351 ms |
25936 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
52 ms |
5496 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
52 ms |
5544 KB |
Output is correct |
25 |
Correct |
47 ms |
5392 KB |
Output is correct |
26 |
Correct |
56 ms |
5544 KB |
Output is correct |
27 |
Correct |
51 ms |
5544 KB |
Output is correct |
28 |
Correct |
90 ms |
7140 KB |
Output is correct |
29 |
Correct |
615 ms |
26720 KB |
Output is correct |
30 |
Correct |
87 ms |
7284 KB |
Output is correct |
31 |
Correct |
608 ms |
26692 KB |
Output is correct |
32 |
Correct |
438 ms |
26684 KB |
Output is correct |
33 |
Correct |
438 ms |
27072 KB |
Output is correct |
34 |
Correct |
624 ms |
26684 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
308 KB |
Output is correct |
37 |
Correct |
44 ms |
4952 KB |
Output is correct |
38 |
Correct |
379 ms |
25916 KB |
Output is correct |
39 |
Correct |
430 ms |
26060 KB |
Output is correct |
40 |
Correct |
504 ms |
26296 KB |
Output is correct |
41 |
Correct |
595 ms |
26472 KB |
Output is correct |
42 |
Correct |
607 ms |
26680 KB |
Output is correct |
43 |
Correct |
397 ms |
26016 KB |
Output is correct |
44 |
Correct |
395 ms |
26112 KB |
Output is correct |
45 |
Correct |
351 ms |
25916 KB |
Output is correct |
46 |
Correct |
404 ms |
26124 KB |
Output is correct |
47 |
Correct |
439 ms |
26328 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
300 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
312 KB |
Output is correct |
54 |
Correct |
10 ms |
1236 KB |
Output is correct |
55 |
Correct |
10 ms |
1236 KB |
Output is correct |
56 |
Correct |
10 ms |
1252 KB |
Output is correct |
57 |
Correct |
12 ms |
1208 KB |
Output is correct |
58 |
Correct |
10 ms |
1236 KB |
Output is correct |
59 |
Correct |
10 ms |
1208 KB |
Output is correct |
60 |
Correct |
10 ms |
1236 KB |
Output is correct |
61 |
Correct |
46 ms |
4936 KB |
Output is correct |
62 |
Correct |
73 ms |
7060 KB |
Output is correct |
63 |
Correct |
416 ms |
25928 KB |
Output is correct |
64 |
Correct |
438 ms |
26104 KB |
Output is correct |
65 |
Correct |
547 ms |
26272 KB |
Output is correct |
66 |
Correct |
628 ms |
26512 KB |
Output is correct |
67 |
Correct |
612 ms |
26584 KB |
Output is correct |
68 |
Correct |
398 ms |
26028 KB |
Output is correct |
69 |
Correct |
500 ms |
26748 KB |
Output is correct |
70 |
Correct |
376 ms |
25816 KB |
Output is correct |
71 |
Correct |
438 ms |
26084 KB |
Output is correct |
72 |
Correct |
532 ms |
26340 KB |
Output is correct |
73 |
Correct |
602 ms |
26576 KB |
Output is correct |
74 |
Correct |
384 ms |
25944 KB |
Output is correct |
75 |
Correct |
427 ms |
26128 KB |
Output is correct |