Submission #841372

#TimeUsernameProblemLanguageResultExecution timeMemory
841372LucaIlieMinerals (JOI19_minerals)C++17
40 / 100
28 ms3016 KiB
#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)

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:58:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |         if ( firstt.size() == n ) {
      |              ~~~~~~~~~~~~~~^~~~
#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...