#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define X first
#define Y second
#define ALL(v) v.begin(),v.end()
#define SZ(a) ((int)a.size())
#define pb push_back
int seg[200005],lazy[200005];
void build(int l,int r,int rt,vector<int> &v)
{
if(l==r)
return seg[rt]=v[l],void();
int mid=(l+r)>>1;
build(l,mid,rt<<1,v),build(mid+1,r,rt<<1|1,v);
seg[rt]=min(seg[rt<<1],seg[rt<<1|1]);
}
void down(int rt)
{
if(lazy[rt])
{
seg[rt<<1]+=lazy[rt],lazy[rt<<1]+=lazy[rt];
seg[rt<<1|1]+=lazy[rt],lazy[rt<<1|1]+=lazy[rt];
lazy[rt]=0;
}
}
void modify(int L,int R,int l,int r,int rt,int val)
{
if(l!=r) down(rt);
if(L<=l&&R>=r)
return lazy[rt]+=val,seg[rt]+=val,void();
int mid=(l+r)>>1;
if(L<=mid)
modify(L,R,l,mid,rt<<1,val);
if(R>mid)
modify(L,R,mid+1,r,rt<<1|1,val);
seg[rt]=min(seg[rt<<1],seg[rt<<1|1]);
}
int query(int l,int r,int rt)
{
if(l!=r) down(rt);
if(l==r)
return l;
int mid=(l+r)>>1;
if(seg[rt<<1]<=seg[rt<<1|1])
return query(l,mid,rt<<1);
return query(mid+1,r,rt<<1|1);
}
const int INF=1e9;
int arr[200005];
void init(int k, vector<int> r)
{
int n=SZ(r);
build(0,n-1,1,r);
for(int i=n;i>=1;--i)
{
int u=query(0,n-1,1);
if(u>=k-1)
modify(u-k+1,u,0,n-1,1,-1);
else
modify(0,u,0,n-1,1,-1),modify(n-(k-u-1),n-1,0,n-1,1,-1);
modify(u,u,0,n-1,1,INF),arr[u]=i;
}
}
int compare_plants(int x, int y)
{
return (arr[x]>arr[y])?1:-1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
71 ms |
3256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |