Submission #688557

#TimeUsernameProblemLanguageResultExecution timeMemory
688557AlcabelArt Collections (BOI22_art)C++17
100 / 100
1537 ms868 KiB
#include <art.h> #include <bits/stdc++.h> using namespace std; void solve(int n) { vector<int> p(n); iota(p.begin(), p.end(), 1); vector<int> sorted = {p[0]}, posOf(n); int was = publish(p); for (int i = 1; i < n; ++i) { swap(p[0], p[i]); int cur = publish(p); swap(p[0], p[i]); sorted.emplace_back(p[i]); posOf[p[i] - 1] = i; bool isNewGreater = false; for (int j = i; j >= 0; --j) { // j is current pos of p[i] // - posOf[p[0] - 1] - (i - posOf[p[i] - 1]) + isNewGreater // + (i - posOf[p[0] - 1]) + posOf[p[i] - 1] - (1 - isNewGreater) if (was - posOf[p[0] - 1] - (i - posOf[p[i] - 1]) + isNewGreater + (i - posOf[p[0] - 1]) + posOf[p[i] - 1] - (1 - isNewGreater) == cur) { break; } assert(j > 0); if (sorted[j - 1] == p[0]) { isNewGreater = true; } --posOf[p[i] - 1]; ++posOf[sorted[j - 1] - 1]; swap(sorted[j - 1], sorted[j]); } } answer(sorted); }

Compilation message (stderr)

interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.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...