QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140063#4400. HomeworkAPROHACK0 8ms33040kbC++143.0kb2023-08-15 01:57:592023-08-15 01:58:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-15 01:58:00]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:33040kb
  • [2023-08-15 01:57:59]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
using namespace std;
int n, q, k, t;
int roots[2];
vector<int>child[500005][2];
vector<int>chosen;
bool isChosen[500005];
int lca[500005][20][2];
int distancia[500005][20][2];
int deep[5000005][2];


void bfs(int s, int tri = 0){
	queue<pair<int, int > >cola; // node, deep
	cola.push({s, 0});
	while(!cola.empty() and chosen.size() < k){
		auto cur = cola.front();
		cola.pop();
		chosen.pb(cur.ff);
		deep[cur.ff][tri] = cur.ss;
		isChosen[cur.ff] = true;
		for(int i = 0 ; i < child[cur.ff][tri].size() ; i ++){
			lca[child[cur.ff][tri][i]][0][tri] = cur.ff;
			cola.push({child[cur.ff][tri][i], cur.ss + 1});
		}
	}	
}

int getDist(int a, int b, int tri){
	if(deep[a][tri] < deep[b][tri])swap(a, b);
	int dd = deep[a][tri] - deep[b][tri];
	int ans = 0;
	for(int i = 19 ; i >= 0 ; i --){
		if(dd & (1<<i)){
			ans += distancia[a][i][tri];
			a = lca[a][i][tri];
		}
	}
	if(a == b)return ans;
	for(int i = 19 ; i >= 0 ; i --){
		if(lca[a][i][tri] != lca[b][i][tri]){
			ans += distancia[a][i][tri];
			ans += distancia[b][i][tri];
			a = lca[a][i][tri];
			b = lca[a][i][tri];
		}
	}
	ans += distancia[a][0][tri] + distancia[b][0][tri];
	return ans;
	
	
}


int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	/*
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	* */
	cin >> n >> k >> q >> t;
	memset(isChosen, false, sizeof isChosen);
	int temp;
	for(int i = 1 ; i <= n ; i ++){
		cin >> temp;
		if(temp == -1)roots[0] = i;
		else child[temp][0].pb(i);
	}
	for(int i = 1 ; i <= n ; i ++){
		cin >> temp;
		if(temp == -1)roots[1] = i;
		else child[temp][1].pb(i);
	}
	bfs(roots[0]);
	for(auto i : chosen)cout << i << " ";
	cout << endl;	
	vector<int>questions;
	for(int i = 0 ; i < k ; i ++){
		for(int j = 0 ; j < child[chosen[i]][0].size() ; j ++){
			if(isChosen[child[chosen[i]][0][j]]){
				questions.pb(child[chosen[i]][0][j]);
			}
		}
	}
	for(int i = 0 ; i < questions.size() ; i ++){
		cout << "? " << questions[i] << " " << lca[questions[i]][0][0] << endl;
	}
	cout << "!" << endl;
	for(int i = 0 ; i < questions.size() ; i ++){
		int a, b;
		cin >> a >> b >> a >> b;
		distancia[questions[i]][0][0] = a;
	}
	lca[roots[0]][0][0] = roots[0];
	distancia[roots[0]][0][0] = 0;
	for(int x = 1 ; x < 20 ; x ++){
		for(int i = 1 ; i <= n ; i++){
			lca[i][x][0] = lca[lca[i][x-1][0]][x-1][0];
			distancia[i][x][0] = distancia[lca[i][x-1][0]][x-1][0] + distancia[i][x-1][0];
			//lca[i][x][1] = lca[lca[i][x-1][1]][x-1][1];
		}
	}
	vector<pair<int, int> > queries;
	for(int i = 0 ; i < t ; i ++){
		int a, b;
		cin >> a >> b;
		queries.pb({a, b});
	}
	for(int i = 0 ;  i < t ; i ++){
		cout << getDist(queries[i].ff, queries[i].ss, 0) << " " << getDist(queries[i].ff, queries[i].ss, 0) << "\n";
	}
	cout << endl;
	int ready;
	//~ cin >> ready;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 33040kb

input:

min(max(?,max(min(?,min(?,?)),?)),min(max(?,?),max(?,?)))

output:


!


result:

wrong answer 1st lines differ - expected: '6', found: ''

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #57:

score: 0
Wrong Answer
time: 8ms
memory: 32596kb

input:

min(?,min(?,min(min(min(min(?,min(min(?,min(?,min(?,min(min(?,min(?,min(min(?,min(min(?,min(?,min(?,min(min(?,min(min(?,min(min(?,min(?,min(?,min(min(?,min(min(?,min(min(min(min(?,min(min(min(min(min(?,min(min(?,min(min(?,min(?,min(?,min(?,min(min(?,min(?,min(?,min(?,min(min(?,min(?,min(?,min(min(mi...

output:


!


result:

wrong answer 1st lines differ - expected: '1', found: ''

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%