QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564082#8939. Permutationucup-team3691#WA 60ms3796kbC++143.7kb2024-09-14 19:45:342024-09-14 19:45:35

Judging History

This is the latest submission verdict.

  • [2024-09-14 19:45:35]
  • Judged
  • Verdict: WA
  • Time: 60ms
  • Memory: 3796kb
  • [2024-09-14 19:45:34]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

int nq, sum_len;
vector<int> v;

int query(int l, int r) {
  if (r - l == 0) {
    return l;
  }

  if (v.empty()) {
    cout << "? " << l << " " << r << endl;

    int x;
    cin >> x;

    return x;
  }


  --l; --r;
  ++nq;
  sum_len += r - l + 1;
  vector<pair<int, int>> v2;
  for (int i = l; i <= r; ++i) {
    v2.push_back({v[i], i});
  }

  sort(v2.rbegin(), v2.rend());

  return v2[1].second + 1;
}

void solve_for_n(int n) {
  vector<ll> fib(60, 0);
  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i < 60; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }

  int x, y;
  int l = 1, r = n;

  x = query(l, r);

  while (r - l > 2) {
    int len = r - l + 1;
    int z;
    for (int i = 1; i < 60; ++i) {
      if (fib[i] >= r - l + 1) {
        z = fib[i - 1];
        break;
      }
    }

    int mid = l + z - 1; 
    if (x > mid) {
      mid = r - z;
    }

    if (x <= mid) {
      y = query(l, mid);
    } else {
      y = query(mid + 1, r);
    }

    if (x != y) {
      if (x <= mid) {
        x = query(mid + 1, r);
        l = mid + 1;
      } else {
        x = query(l, mid);
        r = mid;
      }
    } else {
      if (x <= mid) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
  }

  if (r - l == 0) {
    cout << "! " << l << endl;
  } else if (r - l == 1) {
    cout << "! " << (r + l) - x << endl;
  } else if (r - l == 2) {
    int oth = l + 1;
    if (x == oth) {
      oth = l;
    }
    y = query(min(oth, x), max(x, oth));
    if (x == y) {
      cout << "! " << oth << endl;
    } else {
      cout << "! " << (l + l + 1 + l + 2) - x - oth << endl;
    }
  }
}

void solve() {
  int n;
  cin >> n;

  solve_for_n(n);
}

void gen() {
  int nr = 0, bad = 0;
  while (1) {
    ++nr;
    int n = 2 + rng() % 30;

    int lim_q = ceil(1.5 * log2(n));
    int lim_len = 3 * n;

    v.clear();
    nq = 0;
    sum_len = 0;
    for (int i = 1; i <= n; ++i) {
      v.push_back(i);
    }

    shuffle(v.begin(), v.end(), rng);
    solve_for_n(n);

    if (nq > lim_q || lim_len < sum_len) {
      ++bad;
      debug(nr, bad);
      debug(n, nq, lim_q);
      debug(nq - lim_q, -lim_len + sum_len);
    }
  }
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  //solve_for_n(200);
  //return 0;

  //gen();
  //return 0;
  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3652kb

input:

3
5
3
2
5
6
6
6
5
3
4
3
2

output:

? 1 5
? 1 3
? 4 5
! 4
? 1 6
? 2 6
? 4 6
? 2 3
! 2
? 1 4
? 1 3
! 4

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 60ms
memory: 3656kb

input:

10000
10
2
2
2
3
5
10
10
10
10
8
7
10
5
5
1
6
6
10
4
4
4
4
4
10
10
3
2
10
3
3
3
3
2
10
1
1
5
6
7
10
1
1
3
8
8
10
2
4
9
10
3
3
3
1
5
10
4
7
9
10
8
8
7
1
2
10
4
1
9
10
7
7
7
8
4
10
5
1
10
10
8
6
9
10
2
2
1
7
7
10
6
4
10
10
1
1
3
8
8
10
7
7
5
1
2
10
7
7
4
1
2
10
3
4
10
10
4
4
4
4
3
10
8
8
7
2
2
10
8
8
...

output:

? 1 10
? 1 8
? 1 5
? 1 3
? 4 5
! 4
? 1 10
? 3 10
? 6 10
? 8 10
? 6 7
! 6
? 1 10
? 1 8
? 1 5
? 6 8
? 6 7
! 7
? 1 10
? 1 8
? 1 5
? 3 5
? 3 4
! 3
? 1 10
? 3 10
? 1 2
! 1
? 1 10
? 1 8
? 1 5
? 1 3
? 2 3
! 1
? 1 10
? 1 8
? 1 5
? 6 8
? 6 7
! 8
? 1 10
? 1 8
? 1 5
? 6 8
? 7 8
! 7
? 1 10
? 1 8
? 9 10
! 10
? 1...

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 3796kb

input:

10000
3
1
2
11
5
5
3
8
7
2
2
19
3
3
4
13
12
9
7
5
5
5
4
3
3
3
19
6
6
6
7
1
2
2
2
15
11
11
11
11
11

output:

? 1 3
? 1 2
! 3
? 1 11
? 1 8
? 1 5
? 6 8
? 7 8
! 6
? 1 2
! 1
? 1 19
? 1 13
? 1 8
? 9 13
? 11 13
? 9 10
! 10
? 1 7
? 1 5
? 3 5
? 4 5
! 3
? 1 3
? 2 3
! 2
? 1 19
? 1 13
? 1 8
? 4 8
? 1 3
? 1 2
! 3
? 1 2
! 1
? 1 15
? 1 13
? 6 13
? 9 13
? 9 11
? 10 11

result:

wrong answer Too long queries, n = 15, now length 46 (test case 9)