답안 #738204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738204 2023-05-08T09:00:47 Z bobthebuilder 식물 비교 (IOI20_plants) C++17
14 / 100
79 ms 4172 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
#define ll long long
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
const int maxn=2e5+5;
const int INF=0x3f3f3f3f;
namespace {
int seg[4*maxn],pos[4*maxn];
int arr[maxn];
int lazy[4*maxn];
int ans[maxn];
int cur;
int k;
int n;
}
void pushdown(int idx,int l,int r){
	if(!lazy[idx]){
		return;
	}
	seg[idx]+=lazy[idx];
	if(l==r){
		lazy[idx]=0;
		return;
	}
	lazy[idx*2]+=lazy[idx];
	lazy[idx*2+1]+=lazy[idx];
	lazy[idx]=0;
}
void build(int idx,int l,int r){
	
	if(l==r){
		seg[idx]=arr[l];
		pos[idx]=l;
		return;
	}
	int mid=(l+r)/2;
	build(idx*2,l,mid),build(idx*2+1,mid+1,r);
	seg[idx]=min(seg[idx*2],seg[idx*2+1]);
	if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2];
	else pos[idx]=pos[idx*2+1];
}
void upd(int idx,int l,int r,int ql,int qr,int x){
	pushdown(idx,l,r);
	if(r<ql or l>qr) return;
	if(ql<=l and r<=qr){
		lazy[idx]+=x;
		pushdown(idx,l,r);
		return;
	}
	int mid=(l+r)/2;
	upd(idx*2,l,mid,ql,qr,x);
	upd(idx*2+1,mid+1,r,ql,qr,x);
	seg[idx]=min(seg[idx*2],seg[idx*2+1]);
	if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2];
	else pos[idx]=pos[idx*2+1];
}
pii query(int idx,int l,int r,int ql,int qr){
	if(ql>qr) return {INF,-1};
	pushdown(idx,l,r);
	if(r<ql or l>qr) return {INF,-1};
	if(ql<=l and r<=qr){
		return {seg[idx],pos[idx]};
	}
	int mid=(l+r)/2;
	return min(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr));
}

void get(int z){
	pii mn;
	if(z-k<0){
		mn=min(query(1,0,n-1,0,z-1),query(1,0,n-1,n+(z-k),n-1));
	}
	else{
		mn=query(1,0,n-1,z-k,z-1);
	}
	if(mn.f==0){
		get(mn.s);
	}
	ans[z]=cur--;
	if(z-k<0){
		upd(1,0,n-1,0,z-1,-1);
		upd(1,0,n-1,n+(z-k),n-1,-1);
	}
	else{
		upd(1,0,n-1,z-k,z-1,-1);
	}
	upd(1,0,n-1,z,z,INF);
}
void init(int K, std::vector<int> r) {
	k=K;
	--k;
	n=sz(r);
	REP(i,n){
		arr[i]=r[i];
	}
	cur=n;
	build(1,0,n-1);
	while(cur>0){
		int z=query(1,0,n-1,0,n-1).s;
		get(z);
	}

}

int compare_plants(int x, int y) {
	if(ans[x]>ans[y]){
		return 1;
	}
	return -1;
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 66 ms 3404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 52 ms 3456 KB Output is correct
11 Correct 54 ms 3316 KB Output is correct
12 Correct 47 ms 3456 KB Output is correct
13 Correct 53 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 66 ms 3404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 52 ms 3456 KB Output is correct
11 Correct 54 ms 3316 KB Output is correct
12 Correct 47 ms 3456 KB Output is correct
13 Correct 53 ms 3448 KB Output is correct
14 Incorrect 79 ms 4172 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 45 ms 3184 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -