# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
841371 | LucaIlie | Minerals (JOI19_minerals) | C++17 | 17 ms | 2988 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 43000;
int pairr[2 * MAX_N + 1], perm[2 * MAX_N + 1];
bool inSet[2 * MAX_N + 1];
vector<int> firstt, secondd;
int ans = 0;
void solve( int n ) {
for ( int b = log2( n ); b >= 0; b-- ) {
int g1 = 0;
for ( int i = 0; i < n; i++ ) {
if ( (i & (1 << b)) ) {
if ( !inSet[firstt[i]] ) {
ans = Query( firstt[i] );
inSet[firstt[i]] = true;
}
} else {
g1++;
if ( inSet[firstt[i]] ) {
ans = Query( firstt[i] );
inSet[firstt[i]] = false;
}
}
}
for ( int i = 0; i < n; i++ ) {
if ( g1 == 0 ) {
pairr[secondd[i]] += (1 << b);
continue;
}
int prevAns = ans;
ans = Query( secondd[i] );
inSet[secondd[i]] ^= 1;
if ( ans == prevAns )
pairr[secondd[i]] += (1 << b);
else
g1--;
}
}
}
void Solve( int n ) {
vector <int> v;
for ( int i = 1; i <= 2 * n; i++ ) {
v.push_back( i );
perm[i] = i;
}
// random_shuffle( perm + 1, perm + 1 + 2 * n );
int prevAns = 0;
for ( int i = 1; i <= 2 * n; i++ ) {
if ( firstt.size() == n ) {
secondd.push_back( perm[i] );
continue;
}
ans = Query( perm[i] );
inSet[perm[i]] = true;
if ( ans > prevAns )
firstt.push_back( perm[i] );
else
secondd.push_back( perm[i] );
prevAns = ans;
}
solve( n );
for ( int i = 0; i < n; i++ )
Answer( secondd[i], firstt[pairr[secondd[i]]] );
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |