#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
const int inf = 1e9;
int n,k;
vector<int> R,A,B;
set<int> ss;
set<pair<int,int>> cc;
void cal(int x,int y){
cc.erase({A[y],y});
if((y-x+n)%n>=k){
//cout << "add " << y << '\n';
cc.insert({A[y],y});
}
}
void add(int x){
if(ss.empty()){
ss.insert(x);
cc.insert({A[x],x});
//cout << "add " << x << '\n';
return;
}
auto it=ss.lower_bound(x);
if(it!=ss.end()) cal(x,*it);
else cal(x,*ss.begin());
if(it==ss.begin()) cal(*ss.rbegin(),x);
else{
it--;
cal(*it,x);
}
ss.insert(x);
}
void del(int x){
cc.erase({A[x],x});ss.erase(x);
if(ss.empty()) return;
auto it=ss.lower_bound(x);
int y=(it!=ss.end()?*it:*ss.begin());
cc.insert({A[y],y});
}
int tree[4*maxn],lazy[4*maxn];
void build(int l,int r,int id){
lazy[id]=0;
if(l==r){
tree[id]=R[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,id<<1);build(mid+1,r,id<<1|1);
tree[id]=min(tree[id<<1],tree[id<<1|1]);
}
void getnew(int id,int val){
tree[id]-=val;
lazy[id]+=val;
}
void pushdown(int id){
if(!lazy[id]) return;
getnew(id<<1,lazy[id]);
getnew(id<<1|1,lazy[id]);
lazy[id]=0;
}
void get(int l,int r,int id){
if(tree[id]>0) return;
if(l==r){
tree[id]=inf;
//cout << "add2 " << l << '\n';
add(l);
return;
}
pushdown(id);
int mid=(l+r)>>1;
get(l,mid,id<<1);get(mid+1,r,id<<1|1);
tree[id]=min(tree[id<<1],tree[id<<1|1]);
}
void update(int l,int r,int id,int tl,int tr){
if(tr<l || r<tl) return;
if(tl<=l && r<=tr){
getnew(id,1);
return;
}
pushdown(id);
int mid=(l+r)>>1;
update(l,mid,id<<1,tl,tr);update(mid+1,r,id<<1|1,tl,tr);
tree[id]=min(tree[id<<1],tree[id<<1|1]);
}
vector<int> solve(){
vector<int> p(n);
ss.clear();cc.clear();
build(0,n-1,1);
for(int i=n-1;i>=0;i--){
get(0,n-1,1);
int x=cc.begin()->second;
p[x]=i;del(x);
//cout << "P " << x << ' ' << i << '\n';
if(x>=k-1) update(0,n-1,1,x-k+1,x);
else{
update(0,n-1,1,0,x);
update(0,n-1,1,n-(k-x)+1,n-1);
}
}
return p;
}
void init(int _k, std::vector<int> r) {
k=_k;R=r;
n=(int)r.size();
A.assign(n,0);
A=solve();
B=solve();
}
int compare_plants(int x, int y) {
bool lt=(B[x]>B[y] || A[x]>A[y]),rt=(A[x]<A[y] || B[x]<B[y]);
return ((lt && rt)?0:(lt?1:-1));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
41 ms |
5452 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
38 ms |
5396 KB |
Output is correct |
11 |
Correct |
36 ms |
5456 KB |
Output is correct |
12 |
Correct |
35 ms |
5524 KB |
Output is correct |
13 |
Correct |
37 ms |
5464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
41 ms |
5452 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
3 ms |
2396 KB |
Output is correct |
10 |
Correct |
38 ms |
5396 KB |
Output is correct |
11 |
Correct |
36 ms |
5456 KB |
Output is correct |
12 |
Correct |
35 ms |
5524 KB |
Output is correct |
13 |
Correct |
37 ms |
5464 KB |
Output is correct |
14 |
Correct |
59 ms |
7760 KB |
Output is correct |
15 |
Correct |
327 ms |
11880 KB |
Output is correct |
16 |
Correct |
59 ms |
7816 KB |
Output is correct |
17 |
Correct |
334 ms |
11752 KB |
Output is correct |
18 |
Correct |
329 ms |
16588 KB |
Output is correct |
19 |
Correct |
242 ms |
11896 KB |
Output is correct |
20 |
Correct |
315 ms |
11860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
45 ms |
5200 KB |
Output is correct |
4 |
Correct |
271 ms |
14852 KB |
Output is correct |
5 |
Correct |
299 ms |
12372 KB |
Output is correct |
6 |
Correct |
345 ms |
12036 KB |
Output is correct |
7 |
Correct |
353 ms |
11860 KB |
Output is correct |
8 |
Correct |
332 ms |
11860 KB |
Output is correct |
9 |
Correct |
286 ms |
14392 KB |
Output is correct |
10 |
Correct |
310 ms |
12704 KB |
Output is correct |
11 |
Correct |
267 ms |
21072 KB |
Output is correct |
12 |
Correct |
197 ms |
11868 KB |
Output is correct |
13 |
Correct |
313 ms |
18260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |