이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;
const int nax=4e5+5;
#define fi first
#define se second
int n,k;
pair<int,int> segtree[4*nax];
int lazy[nax*4];
int ans[nax];
int tab[nax];
void build(int pos,int l,int r){
	if(l==r){
		segtree[pos]={tab[l],l};
		return;
	}
	int mid=(r+l)/2;
	build(pos*2+1,l,mid);
	build(pos*2+2,mid+1,r);
	segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
	return;
}
void propagate(int pos){
	if(lazy[pos]){
		segtree[pos*2+1].fi+=lazy[pos];
		segtree[pos*2+2].fi+=lazy[pos];
		lazy[pos*2+1]+=lazy[pos];
		lazy[pos*2+2]+=lazy[pos];
	}
	lazy[pos]=0;
}
void update(int pos,int l,int r,int left,int right,int value){
	if(l>r||l>right||r<left) return;
	if(l>=left&&r<=right){
		segtree[pos].fi+=value;
		lazy[pos]+=value;
		return;
	}
	int mid=(r+l)/2;
	propagate(pos);
	update(pos*2+1,l,mid,left,right,value);
	update(pos*2+2,mid+1,r,left,right,value);
	segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
pair<int,int> query(int pos,int l,int r,int left,int right){
	if(l>r||l>right||r<left) return {1e9,1e9};
	if(l>=left&&r<=right){
		return segtree[pos];
	}
	int mid=(r+l)/2;
	propagate(pos);
	return min(query(pos*2+1,l,mid,left,right),query(pos*2+2,mid+1,r,left,right));
}
pair<int,int> q(int l,int r){
	if(l>r){
		return min(query(0,0,n-1,0,r),query(0,0,n-1,l,n-1));
	}else return query(0,0,n-1,l,r);
}
int jump(){
	int x=query(0,0,n-1,0,n-1).se;
	while(q(x-k+1,x-1).fi==0){
		x=q(x-k+1,x-1).se;
	}
	return x;
}
void upd(int l,int r,int value){
	if(l>r){
		update(0,0,n-1,0,r,value);
		update(0,0,n-1,l,n-1,value);
	}else update(0,0,n-1,l,r,value);
}
void init(int K, std::vector<int> r) {
    n=r.size();
    k=K;
    for (int i = 0; i < n; ++i) tab[i]=r[i];
    build(0,0,n-1);
	for (int i = n; i >= 1; --i)
	{
		int x=jump();
		ans[x]=i;
		upd((x-k+1+n)%n,(x-1+n)%n,-1);
		upd(x,x,1e9);
	}
    return;
}
int compare_plants(int x, int y) {
    return ( ans[x]>ans[y] ? 1 : -1);
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |