#include "plants.h"
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int h[MAXN],n,k,s[MAXN<<2],arr[MAXN];
void build(int nd=1,int x=0,int y=n-1){
for(int i=x;i<=y;i++)s[i]=arr[i];
}
void inc(int l,int r,int val,int nd=1,int x=0,int y=n-1){
for(int i=l;i<=r;i++)s[i]+=val;
}
void upd(int x,int y,int val){
if(x<=y)
inc(x,y,val);
else
inc(x,n-1,val),inc(0,y,val);
}
int get(){
for(int i=0;i<n;i++)
if(!s[i])
return i;
}
void zero(int i){
upd(i+1,(i+k-1)%n,1);
}
void flex(int x,int y){
if(x<=y){
for(int i=x;i<=y;i++)if(s[i]==0)zero(i);
}
else{
for(int i=x;i<n;i++)if(s[i]==0)zero(i);
for(int i=0;i<=y;i++)if(s[i]==0)zero(i);
}
}
void print(){
for(int i=0;i<n;i++)printf("%d ",s[i]);puts("");
}
void init(int K, vector<int> r) {
n=int(r.size());k=K;
for(int i=0;i<n;i++)arr[i]=r[i];
build();
for(int i=0;i<n;i++)
if(!arr[i])
zero(i);
for(int i=n-1;i>=0;i--){
int res=get();
h[res]=i;
//debug(res);
int pre=(res-K+1+n)%n;
int nex=(res+K-1)%n;
upd(res,res,INF);
upd(pre,res,-1);
upd(res,nex,-1);
flex(pre,res);
}
}
int compare_plants(int x, int y) {
int ans=0;
ans+=(h[x]>h[y]);
ans-=(h[x]<h[y]);
return ans;
}
Compilation message
plants.cpp: In function 'void print()':
plants.cpp:52:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
52 | for(int i=0;i<n;i++)printf("%d ",s[i]);puts("");
| ^~~
plants.cpp:52:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
52 | for(int i=0;i<n;i++)printf("%d ",s[i]);puts("");
| ^~~~
plants.cpp: In function 'int get()':
plants.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
63 ms |
4608 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |