#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF=1e18;
struct node{
int s,e,m;
ii val;
ll lazy=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
val=ii(0,s);
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy){
val.fi+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
}
void update(int i,int j,ll k){
propo();
if (s==i && e==j) lazy+=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=min(l->val,r->val);
}
}
int query(int i){
propo();
if (s==e) return val.fi;
else if (i<=m) return l->query(i);
else return r->query(i);
}
} *root,*root2;
int n;
void update(int i,int j,ll k){
//cout<<i<<" "<<j<<" "<<k<<endl;
if (i<=j) root->update(i,j,k);
else root->update(i,n-1,k),root->update(0,j,k);
}
void update2(int i,int j,ll k){
//cout<<i<<" "<<j<<endl;
if (i<=j) root2->update(i,j,k);
else root2->update(i,n-1,k),root2->update(0,j,k);
}
vector<int> construct_fast(vector<int> v,int k){
n=sz(v);
vector<int> ans(n,0);
root=new node(0,n-1);
root2=new node(0,n-1);
rep(x,0,n) root->update(x,x,v[x]),root2->update(x,x,v[x]);
while (root2->val.fi==0){
int pos=root2->val.se;
root2->update(pos,pos,INF);
update((pos+1)%n,(pos+(k-1))%n,1);
}
rep(val,n,0){
int idx=root->val.se;
//cout<<"curr: "<<idx<<" "<<root->val.fi<<endl;
ans[idx]=val;
update((idx+1)%n,(idx+(k-1))%n,-1);
update((idx-(k-1)+n)%n,(idx-1+n)%n,-1);
update2((idx-(k-1)+n)%n,(idx-1+n)%n,-1);
//rep(x,0,n) cout<<root2->query(x)<<" "; cout<<endl;
while (root2->val.fi==0){
int pos=root2->val.se;
root2->update(pos,pos,INF);
update((pos+1)%n,(pos+(k-1))%n,1);
}
root->update(idx,idx,INF);
}
return ans;
}
vector<int> arr;
void init(int k, std::vector<int> r) {
arr=construct_fast(r,k);
//for (auto &it:arr) cout<<it<<" "; cout<<endl;
}
int compare_plants(int x, int y) {
if (arr[x]<arr[y]) return -1;
else return 1;
}
Compilation message
plants.cpp: In constructor 'node::node(int, int)':
plants.cpp:24:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 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 |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
88 ms |
4472 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
87 ms |
4472 KB |
Output is correct |
11 |
Correct |
78 ms |
4344 KB |
Output is correct |
12 |
Correct |
76 ms |
4600 KB |
Output is correct |
13 |
Correct |
82 ms |
4476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
88 ms |
4472 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
87 ms |
4472 KB |
Output is correct |
11 |
Correct |
78 ms |
4344 KB |
Output is correct |
12 |
Correct |
76 ms |
4600 KB |
Output is correct |
13 |
Correct |
82 ms |
4476 KB |
Output is correct |
14 |
Correct |
182 ms |
8696 KB |
Output is correct |
15 |
Correct |
1958 ms |
55968 KB |
Output is correct |
16 |
Correct |
183 ms |
8568 KB |
Output is correct |
17 |
Correct |
1953 ms |
55960 KB |
Output is correct |
18 |
Correct |
783 ms |
56056 KB |
Output is correct |
19 |
Correct |
788 ms |
55864 KB |
Output is correct |
20 |
Correct |
1357 ms |
55988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
72 ms |
3704 KB |
Output is correct |
4 |
Correct |
586 ms |
55976 KB |
Output is correct |
5 |
Correct |
858 ms |
56056 KB |
Output is correct |
6 |
Correct |
1384 ms |
55960 KB |
Output is correct |
7 |
Correct |
1807 ms |
55992 KB |
Output is correct |
8 |
Correct |
1959 ms |
55960 KB |
Output is correct |
9 |
Correct |
665 ms |
55960 KB |
Output is correct |
10 |
Correct |
690 ms |
56056 KB |
Output is correct |
11 |
Correct |
457 ms |
55928 KB |
Output is correct |
12 |
Correct |
590 ms |
55968 KB |
Output is correct |
13 |
Correct |
812 ms |
55964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |