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( vector <int> &f, vector<int> &s ) {
if ( f.size() == 1 && s.size() == 1 ) {
pairr[s[0]] = f[0];
return;
}
vector<int> fl, fr, sl, sr;
int leftt = 0, rightt = 0;
for ( int i = 0; i < f.size() / 2; i++ ) {
if ( !inSet[f[i]] ) {
ans = Query( f[i] );
inSet[f[i]] = true;
}
fl.push_back( f[i] );
leftt++;
}
for ( int i = f.size() / 2; i < f.size(); i++ ) {
if ( inSet[f[i]] ) {
ans = Query( f[i] );
inSet[f[i]] = false;
}
fr.push_back( f[i] );
rightt++;
}
for ( int i = 0; i < s.size(); i++ ) {
if ( rightt == 0 ) {
sl.push_back( s[i] );
leftt--;
continue;
}
if ( leftt == 0 ) {
sr.push_back( s[i] );
rightt--;
continue;
}
int prevAns = ans;
ans = Query( secondd[i] );
inSet[secondd[i]] ^= 1;
if ( ans == prevAns ) {
sl.push_back( s[i] );
leftt--;
} else {
sr.push_back( s[i] );
rightt--;
}
}
solve( fl, sl );
solve( fr, sr );
}
void Solve( int n ) {
for ( int i = 1; i <= 2 * n; 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( firstt, secondd );
for ( int i = 0; i < n; i++ )
Answer( secondd[i], pairr[secondd[i]] );
}
Compilation message (stderr)
minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&)':
minerals.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for ( int i = 0; i < f.size() / 2; i++ ) {
| ~~^~~~~~~~~~~~~~
minerals.cpp:29:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for ( int i = f.size() / 2; i < f.size(); i++ ) {
| ~~^~~~~~~~~~
minerals.cpp:38:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for ( int i = 0; i < s.size(); i++ ) {
| ~~^~~~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:74:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | if ( firstt.size() == n ) {
| ~~~~~~~~~~~~~~^~~~
# | 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... |