답안 #349746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349746 2021-01-18T09:59:01 Z Bill_00 The Potion of Great Power (CEOI20_potion) C++14
38 / 100
657 ms 54400 KB
#include <bits/stdc++.h>
#define N 200000
#define M 100000
#define pb push_back
#define ff first
#define ss second
using namespace std;
int h[M],n;
vector<vector<int>>v[M];
int cnt[N];
int q[M][2];
vector<pair<int,bool> >day[N];
void init(int nn,int d, int H[]){
	n=nn;
	for(int i=0;i<n;i++) h[i]=H[i];
}

void curseChanges(int u, int A[], int B[]){
	for(int i=1;i<=u;i++){
		cnt[A[i-1]]++;
		cnt[B[i-1]]++;
	}
	for(int i=0;i<n;i++){
		v[i].resize(cnt[i]);
		cnt[i]=0;
	}
	for(int i=1;i<=u;i++){
		q[i][0]=cnt[A[i-1]];
		q[i][1]=cnt[B[i-1]];
		cnt[A[i-1]]++;
		cnt[B[i-1]]++;
	}
	for(int i=0;i<n;i++) cnt[i]=0;
	for(int i=1;i<=u;i++){
		int a=A[i-1],b=B[i-1];
		day[a].pb({i,0});
		day[b].pb({i,1});
		if(cnt[a]==0){
			v[a][cnt[a]].pb(b);
		}
		else{
			bool flag=0;
			for(int j:v[a][cnt[a]-1]){
				if(j==b){
					flag=1;
					continue;
				}
				v[a][cnt[a]].pb(j);
			}
			if(flag==0) v[a][cnt[a]].pb(b);
		}
		if(cnt[b]==0){
			v[b][cnt[b]].pb(a);
		}
		else{
			bool flag=0;
			for(int j:v[b][cnt[b]-1]){
				if(j==a){
					flag=1;
					continue;
				}
				v[b][cnt[b]].pb(j);
			}
			if(flag==0) v[b][cnt[b]].pb(a);
		}
		cnt[a]++;
		cnt[b]++;
	}
}

int question(int x, int y, int z) {
	pair<int,bool>pp={z,1};
	int ans=1e9;
	int id=upper_bound(day[x].begin(),day[x].end(),pp)-day[x].begin();
	--id;
	int e=day[x].size()-1;
	if(id<0 || id>e){
		return ans;
	}
	int a=q[day[x][id].ff][day[x][id].ss];
	id=upper_bound(day[y].begin(),day[y].end(),pp)-day[y].begin();
	--id;
	e=day[y].size()-1;
	if(id<0 || id>e){
		return ans;
	}
	int b=q[day[y][id].ff][day[y][id].ss];

	// cout << a << ' ' << b << '\n';
	if(v[x][a].size()==0 || v[y][b].size()==0){
		return ans;
	}
	vector<int>xx,yy;
	for(int V:v[y][b]){
		yy.pb(h[V]);
	}
	sort(yy.begin(),yy.end());
	for(int U:v[x][a]){
		int id=lower_bound(yy.begin(),yy.end(),h[U])-yy.begin();
		ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
		int r=yy.size()-1;
		ans=min(ans,abs(yy[min(id,r)]-h[U]));
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7532 KB Output is correct
2 Correct 7 ms 7532 KB Output is correct
3 Correct 7 ms 7532 KB Output is correct
4 Correct 21 ms 9068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 152 ms 54400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 111 ms 48108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 9196 KB Output is correct
2 Correct 78 ms 9580 KB Output is correct
3 Correct 111 ms 9708 KB Output is correct
4 Correct 657 ms 16236 KB Output is correct
5 Correct 602 ms 14896 KB Output is correct
6 Correct 93 ms 9836 KB Output is correct
7 Correct 512 ms 14700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 7 ms 7532 KB Output is correct
3 Correct 7 ms 7532 KB Output is correct
4 Correct 7 ms 7532 KB Output is correct
5 Correct 21 ms 9068 KB Output is correct
6 Runtime error 152 ms 54400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -