Submission #1000046

#TimeUsernameProblemLanguageResultExecution timeMemory
1000046pccArt Collections (BOI22_art)C++17
100 / 100
1104 ms1824 KiB
#include "art.h" // // --- Sample implementation for the task art --- // // To compile this program with the sample grader, place: // art.h art_sample.cpp sample_grader.cpp // in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory, // left click on "Open in terminal") and enter e.g.: // g++ -std=c++17 art_sample.cpp sample_grader.cpp // in this folder. This will create a file a.out in the current directory which you can execute from the terminal // as ./a.out // See task statement or sample_grader.cpp for the input specification // /* std::vector<int> order = {1, 2, 3}; publish(order); order = {2, 3, 1}; publish(order); order = {1, 3, 2}; answer(order); */ #include <bits/stdc++.h> #include <bits/extc++.h> using namespace __gnu_pbds; using namespace std; template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; ordered_set<int> big,small; vector<int> apply_perm(vector<int> v){ auto re = v; for(int i = 0;i<v.size();i++){ re[v[i]-1] = i+1; } return re; } void solve(int N) { vector<int> v; for(int i = 1;i<=N;i++)v.push_back(i); vector<int> dif(N,0); for(int i = 0;i<N;i++){ swap(v[i],v[0]); dif[i] = publish(v); swap(v[i],v[0]); } for(auto &i:dif)cerr<<i<<' ';cerr<<endl; vector<int> ans(N,0); for(int i = 1;i<N;i++)big.insert(i),small.insert(i); for(int i = N-1;i>0;i--){ int d = dif[i]-dif[0]; assert(abs(d)%2==1); if(d>0)d++; else d--; d/=2; if(d>0){ auto it = big.find_by_order(d-1); ans[i] = *it; big.erase(*it); } else{ auto it = small.find_by_order(-d-1); ans[i] = -*it; small.erase(*it); } } int mn = 0; for(auto &i:ans)mn = min(mn,i); for(auto &i:ans)i = (i-mn+1); ans = apply_perm(ans); answer(ans); }

Compilation message (stderr)

art.cpp: In function 'std::vector<int> apply_perm(std::vector<int>)':
art.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i = 0;i<v.size();i++){
      |                ~^~~~~~~~~
art.cpp: In function 'void solve(int)':
art.cpp:51:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   51 |  for(auto &i:dif)cerr<<i<<' ';cerr<<endl;
      |  ^~~
art.cpp:51:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |  for(auto &i:dif)cerr<<i<<' ';cerr<<endl;
      |                               ^~~~
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...