Submission #133903

#TimeUsernameProblemLanguageResultExecution timeMemory
133903ekremMinerals (JOI19_minerals)C++17
80 / 100
315 ms13892 KiB


#include "minerals.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;
typedef set < int > si;

int n, top, onc, h[MAXN], aa[MAXN];
set < int > :: iterator it;

int myrandom(int x){
	return rand()%x;
}

int sor(int x){
	if(h[x])
		top--;
	else
		top++;
	h[x] = 1 - h[x];
	return top - Query(aa[x]);
}

void coz(si a, si b, int d){
	if(a.size() == 1){
		Answer(aa[*a.begin()], aa[*b.begin()]);
		return;
	}
	int n = a.size();
	si x, y;
	for(int i = 1; i <= n/2; i++){
		int of = *a.begin();
		a.erase(of);
		x.insert(of);
		onc = sor(of);
	}
	for(it = b.begin(); it != b.end(); it++){
		int don = sor(*it);
		if(don != onc){
			y.insert(*it);
		}
		onc = don;
	}
	for(it = y.begin(); it != y.end(); it++)
		b.erase(*it);
	// for(it = x.begin(); it != x.end(); it++)
	// 	onc = sor(*it);
	if(d == 1){
		coz(a, y, 1);
		coz(x, b, 0);
	} else{
		coz(x, y, 1);
		coz(a, b, 0);
	}
}

void Solve(int N) {
	n = N+N;
	srand(time(0));
	for(int i = 1; i <= n; i++)
		aa[i] = i;
	random_shuffle(aa + 1, aa + n + 1, myrandom);
	// for(int i = 1; i <= n; i++)
	// 	cout << aa[i] << " ";cout << endl;
	set < int > a, b;
	for(int i = 1; i <= n; i++){
		int don = sor(i);
		// cout << don << " " << onc << endl;
		if(don > onc)
			a.insert(i);
		else
			b.insert(i);
		onc = don;
	}
	coz(a, b, 1);
	// for(it = a.begin(); it != a.end(); it++)cout << *it << " ";cout << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...