#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e2+5;
const int inf = 1e9;
int n,k;
vector<int> R;
set<int> ss,cc;
void cal(int x,int y){
cc.erase(y);
if((y-x+n)%n>=k){
//cout << "add " << y << '\n';
cc.insert(y);
}
}
void add(int x){
if(ss.empty()){
ss.insert(x);
cc.insert(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(x);ss.erase(x);
if(ss.empty()) return;
auto it=ss.lower_bound(x);
int y=(it!=ss.end()?*it:*ss.begin());
cc.insert(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> r){
R=r;
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();
if((int)cc.size()>1 && x==0) x=*cc.rbegin();
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;
}
vector<int> A,B;
void init(int _k, std::vector<int> r) {
k=_k;
n=(int)r.size();
A=solve(r);
for(int i=0;i<n;i++) r[i]=k-1-r[i];
B=solve(r);
for(int i=0;i<n;i++) B[i]=n-1-B[i];
//for(int i=0;i<n;i++) cout << P[i] << ' ';
//cout << '\n';
}
int compare_plants(int x, int y) {
bool lt=(B[x]>B[y]),rt=(A[x]<A[y]);
return ((lt && rt)?0:(lt?1:-1));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
24 ms |
5368 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |