#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;
vector<int> rk;
struct ST{
struct no{
pair<int,int> mn;
int tag=0;
};
vector<no> st;
void init(int x){
st.resize(4*x);
}
void build(int v,int L,int R,vector<int>& a){
if(L==R){
st[v].mn={a[L],L};
return;
}
int m=(L+R)/2;
build(2*v+1,L,m,a);
build(2*v+2,m+1,R,a);
st[v].mn=min(st[2*v+1].mn,st[2*v+2].mn);
}
void upd(int v,int t){
st[v].tag+=t;
st[v].mn.fs+=t;
}
void pudo(int v){
if(st[v].tag==0){
return;
}
upd(2*v+1,st[v].tag);
upd(2*v+2,st[v].tag);
st[v].tag=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);
}
st[v].mn=min(st[2*v+1].mn,st[2*v+2].mn);
}
pair<int,int> query(int v,int L,int R,int l,int r){
if(L==l && r==R){
return st[v].mn;
}
pudo(v);
int m=(L+R)/2;
if(r<=m){
return query(2*v+1,L,m,l,r);
}
else if(l>m){
return query(2*v+2,m+1,R,l,r);
}
else{
return min(query(2*v+1,L,m,l,m),query(2*v+2,m+1,R,m+1,r));
}
}
}st;
int n;
void update(int l,int r){
if(l>r){
st.update(0,0,n-1,l,n-1,-1);
st.update(0,0,n-1,0,r,-1);
}
else{
st.update(0,0,n-1,l,r,-1);
}
}
void init(int k, vector<int> r) {
n=r.size();
rk.resize(n);
st.init(n);
st.build(0,0,n-1,r);
for(int i=0;i<n;i++){
auto h=st.query(0,0,n-1,0,n-1);
assert(h.fs==0);
int xl=(h.sc+1-k+n)%n,xr=(h.sc-1+n)%n;
if(xl>h.sc){
auto z=st.query(0,0,n-1,xl,n-1);
if(z.fs==0){
h=z;
}
}
xl=(h.sc+1-k+n)%n;
xr=(h.sc-1+n)%n;
rk[h.sc]=i;
update(xl,xr);
st.update(0,0,n-1,h.sc,h.sc,10000007);
}
return;
}
int compare_plants(int x, int y) {
return rk[x]<rk[y]?1:-1;
}
# |
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 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
43 ms |
3340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
43 ms |
3420 KB |
Output is correct |
11 |
Correct |
40 ms |
3308 KB |
Output is correct |
12 |
Correct |
40 ms |
3532 KB |
Output is correct |
13 |
Correct |
42 ms |
3400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
43 ms |
3340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
43 ms |
3420 KB |
Output is correct |
11 |
Correct |
40 ms |
3308 KB |
Output is correct |
12 |
Correct |
40 ms |
3532 KB |
Output is correct |
13 |
Correct |
42 ms |
3400 KB |
Output is correct |
14 |
Correct |
57 ms |
4276 KB |
Output is correct |
15 |
Correct |
241 ms |
14320 KB |
Output is correct |
16 |
Correct |
56 ms |
4268 KB |
Output is correct |
17 |
Correct |
285 ms |
14308 KB |
Output is correct |
18 |
Correct |
146 ms |
14288 KB |
Output is correct |
19 |
Correct |
147 ms |
14440 KB |
Output is correct |
20 |
Correct |
230 ms |
14284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |