#include "plants.h"
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long LL;
const LL LLINF=1e18;
int n, k;
vector<int> vc1, vc2;
struct LAZY_SEG{
LL tree[1600010], lazy[1600010];
void prop(int point, int s, int e){
if(s==e)tree[point]+=lazy[point];
else{
lazy[point*2]+=lazy[point];
lazy[point*2+1]+=lazy[point];
}
lazy[point]=0;
}
void eat(int point){
tree[point]=min(tree[point*2]+lazy[point*2], tree[point*2+1]+lazy[point*2+1]);
}
void init(){
memset(tree, 0, sizeof tree);
memset(lazy, 0, sizeof lazy);
}
void alter(int point, int s, int e, int a, int b, LL val){
if(e<a||s>b)return;
if(a<=s&&e<=b){
lazy[point]+=val;
return;
}
prop(point, s, e);
alter(point*2, s, (s+e)/2, a, b, val);
alter(point*2+1, (s+e)/2+1, e, a, b, val);
eat(point);
}
int argmin(int point, int s, int e){
if(tree[point]+lazy[point]>0)return -1;
if(s==e)return s;
prop(point, s, e);
int ret=argmin(point*2, s, (s+e)/2);
if(ret<0)ret=argmin(point*2+1, (s+e)/2+1, e);
eat(point);
return ret;
}
}seg;
int stk[400010], re;
vector<int> calc(vector<int> vc){
vector<int> ret;
ret.resize(vc.size());
re=0;
seg.init();
for(int i=0; i<2*n; i++){
seg.alter(1, 0, 2*n-1, i, i, (LL)vc[i]);
}
for(int i=1; i<=2*n; i++){
int x;
while(1){
x=seg.argmin(1, 0, 2*n-1);
if(x>=0)break;
seg.alter(1, 0, 2*n-1, stk[re], 2*n-1, -1);
re--;
}
ret[x]=i;
seg.alter(1, 0, 2*n-1, x, x, LLINF);
seg.alter(1, 0, 2*n-1, x-k+1, x-1, -1);
if(x-k+1<0)stk[++re]=2*n+x-k;
}
return ret;
}
void init(int _k, vector<int> r){
n=r.size(); k=_k;
for(int i=0; i<n; i++)r.eb(r[i]);
vc1=calc(r);
for(int i=0; i<2*n; i++)r[i]=k-1-r[i];
vc2=calc(r);
}
int compare_plants(int x, int y){
if(x>y)return -compare_plants(y, x);
if(vc1[x]>vc1[y]||vc2[x+n]<vc2[y])return -1;
if(vc2[x]>vc2[y]||vc1[x+n]<vc1[y])return 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25368 KB |
Output is correct |
3 |
Correct |
18 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
78 ms |
28152 KB |
Output is correct |
7 |
Correct |
167 ms |
28984 KB |
Output is correct |
8 |
Correct |
986 ms |
34772 KB |
Output is correct |
9 |
Correct |
981 ms |
34892 KB |
Output is correct |
10 |
Correct |
977 ms |
34892 KB |
Output is correct |
11 |
Correct |
969 ms |
34764 KB |
Output is correct |
12 |
Correct |
1000 ms |
34892 KB |
Output is correct |
13 |
Correct |
969 ms |
34892 KB |
Output is correct |
14 |
Correct |
983 ms |
34764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25328 KB |
Output is correct |
3 |
Correct |
18 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
23 ms |
25472 KB |
Output is correct |
7 |
Correct |
107 ms |
28408 KB |
Output is correct |
8 |
Correct |
20 ms |
25472 KB |
Output is correct |
9 |
Correct |
23 ms |
25472 KB |
Output is correct |
10 |
Correct |
109 ms |
28476 KB |
Output is correct |
11 |
Correct |
103 ms |
28280 KB |
Output is correct |
12 |
Correct |
104 ms |
28644 KB |
Output is correct |
13 |
Correct |
109 ms |
28444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25328 KB |
Output is correct |
3 |
Correct |
18 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
23 ms |
25472 KB |
Output is correct |
7 |
Correct |
107 ms |
28408 KB |
Output is correct |
8 |
Correct |
20 ms |
25472 KB |
Output is correct |
9 |
Correct |
23 ms |
25472 KB |
Output is correct |
10 |
Correct |
109 ms |
28476 KB |
Output is correct |
11 |
Correct |
103 ms |
28280 KB |
Output is correct |
12 |
Correct |
104 ms |
28644 KB |
Output is correct |
13 |
Correct |
109 ms |
28444 KB |
Output is correct |
14 |
Correct |
198 ms |
28860 KB |
Output is correct |
15 |
Correct |
1897 ms |
34780 KB |
Output is correct |
16 |
Correct |
237 ms |
28972 KB |
Output is correct |
17 |
Correct |
1869 ms |
34764 KB |
Output is correct |
18 |
Correct |
1171 ms |
35276 KB |
Output is correct |
19 |
Correct |
1191 ms |
35276 KB |
Output is correct |
20 |
Correct |
1698 ms |
34892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25344 KB |
Output is correct |
3 |
Correct |
95 ms |
28280 KB |
Output is correct |
4 |
Correct |
1035 ms |
34892 KB |
Output is correct |
5 |
Correct |
1143 ms |
34892 KB |
Output is correct |
6 |
Correct |
1494 ms |
35020 KB |
Output is correct |
7 |
Correct |
1816 ms |
34896 KB |
Output is correct |
8 |
Correct |
1863 ms |
34920 KB |
Output is correct |
9 |
Correct |
1069 ms |
34764 KB |
Output is correct |
10 |
Correct |
1071 ms |
34840 KB |
Output is correct |
11 |
Correct |
976 ms |
34892 KB |
Output is correct |
12 |
Correct |
1068 ms |
34764 KB |
Output is correct |
13 |
Correct |
1185 ms |
35020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
25472 KB |
Output is correct |
2 |
Correct |
18 ms |
25344 KB |
Output is correct |
3 |
Correct |
19 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
19 ms |
25472 KB |
Output is correct |
7 |
Correct |
34 ms |
25984 KB |
Output is correct |
8 |
Correct |
33 ms |
25976 KB |
Output is correct |
9 |
Correct |
33 ms |
25984 KB |
Output is correct |
10 |
Correct |
34 ms |
25976 KB |
Output is correct |
11 |
Correct |
33 ms |
25976 KB |
Output is correct |
12 |
Correct |
33 ms |
25984 KB |
Output is correct |
13 |
Correct |
33 ms |
25976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
19 ms |
25344 KB |
Output is correct |
3 |
Correct |
18 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
21 ms |
25344 KB |
Output is correct |
6 |
Correct |
1116 ms |
34836 KB |
Output is correct |
7 |
Correct |
1449 ms |
34764 KB |
Output is correct |
8 |
Correct |
1720 ms |
34776 KB |
Output is correct |
9 |
Correct |
1851 ms |
34892 KB |
Output is correct |
10 |
Correct |
1052 ms |
34892 KB |
Output is correct |
11 |
Correct |
1352 ms |
35020 KB |
Output is correct |
12 |
Correct |
1020 ms |
34892 KB |
Output is correct |
13 |
Correct |
1117 ms |
34892 KB |
Output is correct |
14 |
Correct |
1485 ms |
34892 KB |
Output is correct |
15 |
Correct |
1753 ms |
34892 KB |
Output is correct |
16 |
Correct |
1027 ms |
34892 KB |
Output is correct |
17 |
Correct |
1114 ms |
34892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25368 KB |
Output is correct |
3 |
Correct |
18 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Correct |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
78 ms |
28152 KB |
Output is correct |
7 |
Correct |
167 ms |
28984 KB |
Output is correct |
8 |
Correct |
986 ms |
34772 KB |
Output is correct |
9 |
Correct |
981 ms |
34892 KB |
Output is correct |
10 |
Correct |
977 ms |
34892 KB |
Output is correct |
11 |
Correct |
969 ms |
34764 KB |
Output is correct |
12 |
Correct |
1000 ms |
34892 KB |
Output is correct |
13 |
Correct |
969 ms |
34892 KB |
Output is correct |
14 |
Correct |
983 ms |
34764 KB |
Output is correct |
15 |
Correct |
18 ms |
25344 KB |
Output is correct |
16 |
Correct |
18 ms |
25328 KB |
Output is correct |
17 |
Correct |
18 ms |
25344 KB |
Output is correct |
18 |
Correct |
18 ms |
25344 KB |
Output is correct |
19 |
Correct |
18 ms |
25344 KB |
Output is correct |
20 |
Correct |
23 ms |
25472 KB |
Output is correct |
21 |
Correct |
107 ms |
28408 KB |
Output is correct |
22 |
Correct |
20 ms |
25472 KB |
Output is correct |
23 |
Correct |
23 ms |
25472 KB |
Output is correct |
24 |
Correct |
109 ms |
28476 KB |
Output is correct |
25 |
Correct |
103 ms |
28280 KB |
Output is correct |
26 |
Correct |
104 ms |
28644 KB |
Output is correct |
27 |
Correct |
109 ms |
28444 KB |
Output is correct |
28 |
Correct |
198 ms |
28860 KB |
Output is correct |
29 |
Correct |
1897 ms |
34780 KB |
Output is correct |
30 |
Correct |
237 ms |
28972 KB |
Output is correct |
31 |
Correct |
1869 ms |
34764 KB |
Output is correct |
32 |
Correct |
1171 ms |
35276 KB |
Output is correct |
33 |
Correct |
1191 ms |
35276 KB |
Output is correct |
34 |
Correct |
1698 ms |
34892 KB |
Output is correct |
35 |
Correct |
18 ms |
25344 KB |
Output is correct |
36 |
Correct |
18 ms |
25344 KB |
Output is correct |
37 |
Correct |
95 ms |
28280 KB |
Output is correct |
38 |
Correct |
1035 ms |
34892 KB |
Output is correct |
39 |
Correct |
1143 ms |
34892 KB |
Output is correct |
40 |
Correct |
1494 ms |
35020 KB |
Output is correct |
41 |
Correct |
1816 ms |
34896 KB |
Output is correct |
42 |
Correct |
1863 ms |
34920 KB |
Output is correct |
43 |
Correct |
1069 ms |
34764 KB |
Output is correct |
44 |
Correct |
1071 ms |
34840 KB |
Output is correct |
45 |
Correct |
976 ms |
34892 KB |
Output is correct |
46 |
Correct |
1068 ms |
34764 KB |
Output is correct |
47 |
Correct |
1185 ms |
35020 KB |
Output is correct |
48 |
Correct |
19 ms |
25472 KB |
Output is correct |
49 |
Correct |
18 ms |
25344 KB |
Output is correct |
50 |
Correct |
19 ms |
25344 KB |
Output is correct |
51 |
Correct |
18 ms |
25344 KB |
Output is correct |
52 |
Correct |
18 ms |
25344 KB |
Output is correct |
53 |
Correct |
19 ms |
25472 KB |
Output is correct |
54 |
Correct |
34 ms |
25984 KB |
Output is correct |
55 |
Correct |
33 ms |
25976 KB |
Output is correct |
56 |
Correct |
33 ms |
25984 KB |
Output is correct |
57 |
Correct |
34 ms |
25976 KB |
Output is correct |
58 |
Correct |
33 ms |
25976 KB |
Output is correct |
59 |
Correct |
33 ms |
25984 KB |
Output is correct |
60 |
Correct |
33 ms |
25976 KB |
Output is correct |
61 |
Correct |
88 ms |
28152 KB |
Output is correct |
62 |
Correct |
165 ms |
28728 KB |
Output is correct |
63 |
Correct |
1035 ms |
34896 KB |
Output is correct |
64 |
Correct |
1137 ms |
34780 KB |
Output is correct |
65 |
Correct |
1486 ms |
34764 KB |
Output is correct |
66 |
Correct |
1750 ms |
34892 KB |
Output is correct |
67 |
Correct |
1861 ms |
34764 KB |
Output is correct |
68 |
Correct |
1094 ms |
34892 KB |
Output is correct |
69 |
Correct |
1364 ms |
35148 KB |
Output is correct |
70 |
Correct |
1032 ms |
34780 KB |
Output is correct |
71 |
Correct |
1130 ms |
34776 KB |
Output is correct |
72 |
Correct |
1507 ms |
34892 KB |
Output is correct |
73 |
Correct |
1803 ms |
34784 KB |
Output is correct |
74 |
Correct |
1040 ms |
34892 KB |
Output is correct |
75 |
Correct |
1121 ms |
34892 KB |
Output is correct |