Submission #539299

#TimeUsernameProblemLanguageResultExecution timeMemory
539299Soumya1도서관 (JOI18_library)C++17
100 / 100
225 ms344 KiB
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
void Solve(int n) {
  int store[n + 1];
  {
      vector<int> q(n);
      for (int i = 1; i <= n; i++) {
          q[i - 1] = 1;
          store[i] = Query(q);
      }
  }
  store[0] = 0;
  vector<int> edge[n + 1];
  for (int i = 1; i <= n; i++) {
      int old_answer = store[i - 1];
      int new_answer = store[i];
      if (old_answer + 1 == new_answer) {
          continue;
      }
      int lo = 1, hi = i - 1;
      while (lo < hi) {
          int mid = (lo + hi) / 2;
          vector<int> q(n);
          for (int j = 1; j <= mid; j++) q[j - 1] = 1;
          q[i - 1] = 1;
          int x = store[mid];
          int y = Query(q);
          if (y > x) lo = mid + 1;
          else hi = mid;
      }
      edge[lo].push_back(i);
      edge[i].push_back(lo);
      if (new_answer < old_answer) {
          lo = 1, hi = i - 1;
          while (lo < hi) {
              int mid = (lo + hi) / 2;
              vector<int> q(n);
              for (int j = 1; j <= mid; j++) q[j - 1] = 1;
              q[i - 1] = 1;
              int x = store[mid];
              int y = Query(q);
              if (x <= y) lo = mid + 1;
              else hi = mid;
          }
          edge[lo].push_back(i);
          edge[i].push_back(lo);
      }
  }
  int start;
  for (int i = 1; i <= n; i++) {
      if ((int) edge[i].size() <= 1) start = i;
  }
  vector<bool> vis(n + 1);
  vector<int> ans;
  while ((int) ans.size() < n) {
      ans.push_back(start);
      vis[start] = true;
      for (int next : edge[start]) {
          if (!vis[next]) {
              start = next;
              break;
          }
      }
  }
  Answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...