답안 #305041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305041 2020-09-22T12:54:47 Z Wu_Ren 식물 비교 (IOI20_plants) C++11
0 / 100
27 ms 25760 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;
int tag[1600010],mn[1600010],st[400010],t=0,n,k;
vector<int>tmp1,tmp2;
void pushdown(int t){
	mn[t<<1]+=tag[t];
	mn[t<<1|1]+=tag[t];
	tag[t<<1]+=tag[t];
	tag[t<<1|1]+=tag[t];
	tag[t]=0;
}
void add(int ll,int rr,int l,int r,int t,int c){
	if(ll<=l&&r<=rr){
		tag[t]+=c;
		mn[t]+=c;
		return;
	}
	pushdown(t);
	int mid=(l+r)>>1;
	if(ll<=mid) add(ll,rr,l,mid,t<<1,c);
	if(mid<rr) add(ll,rr,mid+1,r,t<<1|1,c);
	mn[t]=min(mn[t<<1],mn[t<<1|1]);
}
int query(int l,int r,int t){
	if(mn[t]>0) return -1;
	if(l==r) return l;
	pushdown(t);
	int mid=(l+r)>>1;
	if(mn[t<<1]>0) return query(mid+1,r,t<<1|1);
	else return query(l,mid,t<<1);
}
vector<int> work(vector<int> now){
	vector<int>ans;
	ans.resize(now.size());
	t=0,memset(tag,0,sizeof(tag)),memset(mn,0,sizeof(mn));
	for(int i=0;i<2*n;i++) add(i,i,0,2*n-1,1,now[i]);
	for(int i=1;i<=2*n;i++){
		int x=query(0,2*n-1,1);
		while(x<0&&t) add(st[t],2*n-1,0,2*n-1,1,-1),t--,x=query(0,2*n-1,1);
		ans[x]=i;
		add(x,x,0,2*n-1,1,1e9);
		add(x-k+1,x-1,0,2*n-1,1,-1);
		if(x-k+1<0) st[++t]=2*n+x-k;
	}
	return ans;
}
void init(int _k,vector<int> r){
	n=r.size(),k=_k;
	for(int i=0;i<n;i++) r.push_back(r[i]);
	tmp1=work(r);
	for(int i=0;i<2*n;i++) r[i]=k-1-r[i];
	tmp2=work(r);
}
int compare_plants(int x, int y){
	if(x>y) return -compare_plants(y,x);
	if(tmp1[x]>tmp1[y]||tmp2[x+n]<tmp2[y]) return -1;
	if(tmp2[x]>tmp2[y]||tmp1[x+n]<tmp1[y]) return 1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 25728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 25728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 25728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 25728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 25760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 25720 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 25728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -