답안 #1043062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043062 2024-08-03T20:26:47 Z MarwenElarbi 식물 비교 (IOI20_plants) C++17
0 / 100
51 ms 8936 KB
#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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Incorrect 0 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Incorrect 0 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Incorrect 0 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 51 ms 8936 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4536 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 0 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Incorrect 0 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Incorrect 0 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -