#include "plants.h"
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(all(x))
#define press(x) x.erase(unique(all(x)), x.end());
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
const int INF=1e9;
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-1;
}
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;
}
/*
4 3 2
0 1 1 2
0 2
1 2
*/
# |
Verdict |
Execution time |
Memory |
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 |
19 ms |
25344 KB |
Output is correct |
5 |
Correct |
19 ms |
25344 KB |
Output is correct |
6 |
Correct |
80 ms |
28152 KB |
Output is correct |
7 |
Correct |
173 ms |
28728 KB |
Output is correct |
8 |
Correct |
986 ms |
34780 KB |
Output is correct |
9 |
Correct |
990 ms |
34892 KB |
Output is correct |
10 |
Correct |
1006 ms |
34892 KB |
Output is correct |
11 |
Correct |
987 ms |
34776 KB |
Output is correct |
12 |
Correct |
1008 ms |
34844 KB |
Output is correct |
13 |
Correct |
1012 ms |
34844 KB |
Output is correct |
14 |
Correct |
1004 ms |
34780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
20 ms |
25344 KB |
Output is correct |
3 |
Correct |
20 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Incorrect |
20 ms |
25344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
20 ms |
25344 KB |
Output is correct |
3 |
Correct |
20 ms |
25344 KB |
Output is correct |
4 |
Correct |
18 ms |
25344 KB |
Output is correct |
5 |
Incorrect |
20 ms |
25344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
25344 KB |
Output is correct |
2 |
Correct |
18 ms |
25344 KB |
Output is correct |
3 |
Correct |
94 ms |
28280 KB |
Output is correct |
4 |
Correct |
1056 ms |
34776 KB |
Output is correct |
5 |
Correct |
1204 ms |
34776 KB |
Output is correct |
6 |
Incorrect |
1476 ms |
34892 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
25412 KB |
Output is correct |
2 |
Correct |
18 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 |
18 ms |
25344 KB |
Output is correct |
6 |
Correct |
20 ms |
25472 KB |
Output is correct |
7 |
Correct |
35 ms |
25976 KB |
Output is correct |
8 |
Incorrect |
34 ms |
26076 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
25344 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 |
Incorrect |
21 ms |
25344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
19 ms |
25344 KB |
Output is correct |
5 |
Correct |
19 ms |
25344 KB |
Output is correct |
6 |
Correct |
80 ms |
28152 KB |
Output is correct |
7 |
Correct |
173 ms |
28728 KB |
Output is correct |
8 |
Correct |
986 ms |
34780 KB |
Output is correct |
9 |
Correct |
990 ms |
34892 KB |
Output is correct |
10 |
Correct |
1006 ms |
34892 KB |
Output is correct |
11 |
Correct |
987 ms |
34776 KB |
Output is correct |
12 |
Correct |
1008 ms |
34844 KB |
Output is correct |
13 |
Correct |
1012 ms |
34844 KB |
Output is correct |
14 |
Correct |
1004 ms |
34780 KB |
Output is correct |
15 |
Correct |
18 ms |
25344 KB |
Output is correct |
16 |
Correct |
20 ms |
25344 KB |
Output is correct |
17 |
Correct |
20 ms |
25344 KB |
Output is correct |
18 |
Correct |
18 ms |
25344 KB |
Output is correct |
19 |
Incorrect |
20 ms |
25344 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |