QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278868#7630. Yet Another Maximize Permutation SubarraysmaspyAC ✓397ms59988kbC++2018.9kb2023-12-07 21:37:592023-12-07 21:37:59

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 21:37:59]
  • 评测
  • 测评结果:AC
  • 用时:397ms
  • 内存:59988kb
  • [2023-12-07 21:37:59]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sm = 0;
  for (auto &&a: A) sm += a;
  return sm;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

#line 2 "library/ds/hashmap.hpp"

// u64 -> Val
template <typename Val, int LOG = 20, bool KEEP_IDS = false>
struct HashMap {
  static constexpr int N = (1 << LOG);
  u64* key;
  Val* val;
  vc<int> IDS;
  bitset<N> used;
  const int shift;
  const u64 r = 11995408973635179863ULL;
  HashMap() : key(new u64[N]), val(new Val[N]), shift(64 - LOG) {}
  u32 hash(u64 x) {
    static const u64 FIXED_RANDOM
        = std::chrono::steady_clock::now().time_since_epoch().count();
    return (u64(x + FIXED_RANDOM) * r) >> shift;
  }

  int index(const u64& k) {
    int i = 0;
    for (i = hash(k); used[i] && key[i] != k; (i += 1) &= (N - 1)) {}
    return i;
  }

  Val& operator[](const u64& k) {
    int i = index(k);
    if (!used[i]) { set_used(i), key[i] = k, val[i] = Val{}; }
    return val[i];
  }

  Val get(const u64& k, Val default_value) {
    int i = index(k);
    if (!used[i]) return default_value;
    return val[i];
  }

  bool count(const u64& k) {
    int i = index(k);
    return used[i] && key[i] == k;
  }

  void set_used(int i) {
    used[i] = 1;
    if constexpr (KEEP_IDS) IDS.eb(i);
  }

  void reset() {
    static_assert(KEEP_IDS);
    for (auto&& i: IDS) used[i] = 0;
    IDS.clear();
  }

  // f(key, val)
  template <typename F>
  void enumerate_all(F f) {
    static_assert(KEEP_IDS);
    for (auto&& i: IDS) f(key[i], val[i]);
  }
};
#line 1 "library/ds/fastset.hpp"
// 64-ary tree
// space: (N/63) * u64
struct FastSet {
  static constexpr u32 B = 64;
  int n, log;
  vvc<u64> seg;

  FastSet() {}
  FastSet(int n) { build(n); }

  template <typename F>
  FastSet(int n, F f) {
    build(n, f);
  }

  void build(int m) {
    seg.clear();
    n = m;
    do {
      seg.push_back(vc<u64>((m + B - 1) / B));
      m = (m + B - 1) / B;
    } while (m > 1);
    log = len(seg);
  }
  template <typename F>
  void build(int n, F f) {
    build(n);
    FOR(i, n) { seg[0][i / B] |= u64(f(i)) << (i % B); }
    FOR(h, log - 1) {
      FOR(i, len(seg[h])) {
        seg[h + 1][i / B] |= u64(bool(seg[h][i])) << (i % B);
      }
    }
  }

  bool operator[](int i) const { return seg[0][i / B] >> (i % B) & 1; }
  void insert(int i) {
    for (int h = 0; h < log; h++) {
      seg[h][i / B] |= u64(1) << (i % B), i /= B;
    }
  }
  void add(int i) { insert(i); }
  void erase(int i) {
    u64 x = 0;
    for (int h = 0; h < log; h++) {
      seg[h][i / B] &= ~(u64(1) << (i % B));
      seg[h][i / B] |= x << (i % B);
      x = bool(seg[h][i / B]);
      i /= B;
    }
  }
  void remove(int i) { erase(i); }

  // min[x,n) or n
  int next(int i) {
    assert(i <= n);
    chmax(i, 0);
    for (int h = 0; h < log; h++) {
      if (i / B == seg[h].size()) break;
      u64 d = seg[h][i / B] >> (i % B);
      if (!d) {
        i = i / B + 1;
        continue;
      }
      i += lowbit(d);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += lowbit(seg[g][i / B]);
      }
      return i;
    }
    return n;
  }

  // max [0,x], or -1
  int prev(int i) {
    assert(i >= -1);
    if (i >= n) i = n - 1;
    for (int h = 0; h < log; h++) {
      if (i == -1) break;
      u64 d = seg[h][i / B] << (63 - i % B);
      if (!d) {
        i = i / B - 1;
        continue;
      }
      i -= __builtin_clzll(d);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += topbit(seg[g][i / B]);
      }
      return i;
    }
    return -1;
  }

  // [l, r)
  template <typename F>
  void enumerate(int l, int r, F f) {
    for (int x = next(l); x < r; x = next(x + 1)) f(x);
  }

  string to_string() {
    string s(n, '?');
    for (int i = 0; i < n; ++i) s[i] = ((*this)[i] ? '1' : '0');
    return s;
  }
};
#line 6 "main.cpp"

ll eval(vc<int> A) {
  int N = len(A);
  vc<int> pos(N);
  FOR(i, N) pos[A[i]] = i;
  vi L(N), R(N);
  L[0] = R[0] = pos[0];
  FOR(i, 1, N) {
    ll p = pos[i];
    L[i] = min(L[i - 1], p);
    R[i] = max(R[i - 1], p);
  }
  ll ans = 0;
  FOR(i, N) {
    if (R[i] - L[i] == i) ++ans;
  }
  return ans;
}

void solve() {
  static HashMap<int, 21, true> MP;
  MP.reset();

  LL(N);
  VEC(int, A, N);
  for (auto& x: A) --x;

  if (N == 1) { return print(1, 1); }

  FastSet ss(N, [&](int i) -> int { return 1; });
  // print(A);
  vc<int> pos(N);
  FOR(i, N) pos[A[i]] = i;

  ll now = eval(A);
  ll best = 0;
  pi ANS = {0, 0};

  struct Data {
    ll mi1, mi2, ma2, ma1;
    ll sm;
  };

  auto add = [&](Data x, ll idx) -> Data {
    x.sm += idx;
    if (idx < x.mi1) {
      x.mi2 = x.mi1;
      x.mi1 = idx;
    }
    elif (idx < x.mi2) { x.mi2 = idx; }
    if (idx > x.ma1) {
      x.ma2 = x.ma1;
      x.ma1 = idx;
    }
    elif (idx > x.ma2) { x.ma2 = idx; }
    return x;
  };

  vc<Data> dat(N);
  {
    int a = pos[0], b = pos[1];
    if (a > b) swap(a, b);
    dat[1] = Data{a, b, a, b, a + b};
  }
  FOR(i, 2, N) dat[i] = add(dat[i - 1], pos[i]);

  // 各 position が現在完成している区間のいくつに入っているか
  vc<int> CNT(N + 1);
  FOR(x, 1, N) {
    Data d = dat[x];
    int L = d.mi1, R = d.ma1;
    if (R - L == x) CNT[L]++, CNT[R + 1]--;
  }
  CNT = cumsum<int>(CNT, 0);
  POP(CNT);

  auto get_key = [&](u64 p, u64 q) -> u64 {
    if (p > q) swap(p, q);
    return (p << 32) | q;
  };

  // 新たに完成する場所があったとして、そこに対する加点
  ss.erase(pos[0]);
  FOR(x, 1, N - 1) {
    ss.erase(pos[x]);
    Data F = dat[x];
    int a = F.mi1, b = F.mi2, c = F.ma2, d = F.ma1;

    // 新しく作る場所を決めて調べる
    vc<pair<int, int>> range;
    // a をのこさない -> b,d はのこす
    range.eb(b, d);
    range.eb(b - 1, d);
    range.eb(b, d + 1);
    // d をのこさない -> a,c はのこす
    range.eb(a, c);
    range.eb(a - 1, c);
    range.eb(a, c + 1);

    vc<pair<int, int>> MAKE;

    for (auto& [L, R]: range) {
      if (L == a && R == d) continue;
      if (L < 0 || R >= N) continue;
      if (R - L != x) continue;
      int p = ss.next(L);
      assert(p <= R);
      if (a < L) { MAKE.eb(a, p); }
      if (R < d) { MAKE.eb(p, d); }
    }
    UNIQUE(MAKE);
    for (auto& [a, b]: MAKE) {
      // if (a == 0 && b == 2) print(x, a, b);
      auto key = get_key(a, b);
      MP[key]++;
    }
  }

  MP.enumerate_all([&](u64 key, int get) -> void {
    u64 p = key >> 32;
    u64 q = key & u32(-1);
    int miss = abs(CNT[p] - CNT[q]);
    if (chmax(best, get - miss)) ANS = {p, q};
  });

  // print(now + best);
  print(ANS.fi + 1, ANS.se + 1);
}

signed main() {
  INT(T);
  FOR(T) solve();

  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 24556kb

input:

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

output:

1 1
1 2
1 4
1 3
1 1
4 9
2 4
1 5

result:

ok 8 cases

Test #2:

score: 0
Accepted
time: 0ms
memory: 24584kb

input:

10
9
6 2 8 3 4 5 7 1 9
17
15 10 11 9 4 5 17 1 2 7 6 8 14 12 13 16 3
19
5 10 12 11 14 6 15 19 2 18 8 1 16 13 7 4 3 17 9
18
5 8 10 6 4 7 9 2 11 3 18 1 13 17 12 14 16 15
2
1 2
8
8 7 6 5 4 1 3 2
9
1 2 3 4 9 7 5 8 6
11
1 11 3 4 2 9 7 6 8 10 5
6
1 6 5 2 3 4
11
7 8 10 1 9 11 4 2 3 5 6

output:

3 8
7 17
8 12
9 12
1 1
5 8
5 9
2 5
1 3
4 6

result:

ok 10 cases

Test #3:

score: 0
Accepted
time: 3ms
memory: 24664kb

input:

10
18
10 13 12 1 2 3 4 5 6 8 9 7 17 11 15 14 16 18
8
3 1 4 2 6 5 8 7
12
10 9 1 7 6 5 3 2 8 4 11 12
15
15 14 12 13 10 5 9 7 8 6 1 2 3 4 11
6
5 4 3 2 1 6
14
13 3 4 2 10 5 8 1 7 12 9 11 6 14
1
1
1
1
5
5 2 1 4 3
17
1 8 9 7 10 6 2 5 4 3 11 17 13 15 16 14 12

output:

1 13
3 4
3 9
6 15
1 1
5 8
1 1
1 1
2 4
1 5

result:

ok 10 cases

Test #4:

score: 0
Accepted
time: 0ms
memory: 24736kb

input:

9
4
4 2 3 1
5
5 2 3 1 4
8
7 8 6 5 3 2 1 4
17
15 16 13 12 14 1 3 4 2 5 6 7 9 11 10 8 17
2
1 2
17
16 14 11 8 5 4 3 15 2 6 7 9 10 12 13 1 17
8
1 5 6 7 2 3 4 8
15
10 7 13 2 8 4 1 15 6 5 11 14 3 12 9
7
2 4 3 1 5 6 7

output:

1 4
2 3
1 2
5 16
1 1
8 16
1 4
3 7
1 5

result:

ok 9 cases

Test #5:

score: 0
Accepted
time: 0ms
memory: 25104kb

input:

9
80
78 77 73 72 69 70 66 64 62 63 61 60 58 57 56 54 53 55 50 51 49 43 44 38 36 35 34 33 27 25 24 26 19 17 14 16 15 9 1 5 2 3 4 6 8 7 10 11 12 13 18 20 21 22 23 28 31 30 29 32 37 41 42 39 40 45 46 47 48 52 59 68 65 67 71 75 74 76 79 80
52
49 48 35 31 30 32 27 25 1 23 22 21 17 15 16 14 13 12 9 10 11 ...

output:

39 40
9 28
61 65
2 11
2 135
92 149
1 66
12 32
51 63

result:

ok 9 cases

Test #6:

score: 0
Accepted
time: 0ms
memory: 25488kb

input:

8
151
150 151 149 148 129 131 130 125 126 124 128 127 123 119 115 117 122 121 116 120 118 111 112 113 110 109 108 107 105 106 103 104 102 100 98 101 99 97 96 95 80 79 72 73 71 68 69 70 56 51 47 50 48 49 46 33 35 27 34 31 30 29 32 26 28 25 24 23 22 21 20 17 19 18 16 11 12 7 5 6 1 4 3 2 10 8 9 14 13 1...

output:

58 63
2 12
2 10
1 32
35 85
4 12
70 163
86 170

result:

ok 8 cases

Test #7:

score: 0
Accepted
time: 2ms
memory: 25688kb

input:

7
144
144 143 142 141 139 137 138 136 135 133 131 130 129 127 125 120 119 116 117 109 108 107 105 104 103 80 99 100 98 95 92 91 89 88 85 81 101 79 73 72 64 63 61 59 60 58 57 56 52 51 50 45 43 44 42 41 36 34 32 33 31 30 29 27 26 21 22 20 19 13 12 11 9 5 4 3 2 1 6 7 8 10 16 17 15 14 18 24 23 25 28 35 ...

output:

26 37
19 22
53 141
40 96
69 75
29 101
16 19

result:

ok 7 cases

Test #8:

score: 0
Accepted
time: 3ms
memory: 27144kb

input:

8
487
487 486 485 484 481 480 479 477 475 472 473 469 465 464 463 458 453 452 451 450 448 449 446 435 434 433 432 431 430 429 428 427 426 419 418 414 413 408 406 405 396 390 391 389 384 386 385 382 381 380 379 376 374 375 373 372 370 371 369 368 366 367 360 359 357 356 355 354 353 351 349 350 345 34...

output:

365 413
125 976
804 936
73 490
324 794
381 498
59 609
17 1097

result:

ok 8 cases

Test #9:

score: 0
Accepted
time: 0ms
memory: 28460kb

input:

8
403
402 400 399 398 394 393 395 396 391 390 389 388 387 386 385 384 383 376 373 372 371 370 366 368 369 367 364 360 361 359 355 356 352 351 350 349 341 340 338 339 336 335 327 326 325 324 319 318 317 315 314 313 311 308 310 309 307 306 305 304 299 302 300 301 296 293 290 288 289 287 286 285 284 28...

output:

218 245
228 282
2 1464
482 565
213 289
100 596
224 747
199 1465

result:

ok 8 cases

Test #10:

score: 0
Accepted
time: 6ms
memory: 28136kb

input:

9
464
427 67 114 302 21 32 268 339 309 366 432 286 88 10 347 290 353 248 249 261 360 9 284 191 405 17 464 110 341 349 188 49 33 235 451 100 81 95 410 457 355 62 381 266 37 351 189 402 107 263 184 246 350 94 186 438 93 233 279 441 158 140 379 417 55 156 439 342 278 320 13 435 142 265 270 36 173 218 7...

output:

382 388
736 1473
697 850
515 568
63 208
397 530
343 399
433 725
19 200

result:

ok 9 cases

Test #11:

score: 0
Accepted
time: 15ms
memory: 29832kb

input:

7
2236
2234 2235 2236 2222 2221 2220 2219 2212 2213 2208 2209 2206 2205 2207 2197 2196 2194 2193 2192 2195 2191 2189 2188 2190 2180 2181 2175 2176 2177 2179 2178 2171 2168 2166 2165 2170 2167 2164 2169 2155 2154 2153 2152 2151 2129 2125 2126 2123 2120 2122 2121 2119 2117 2114 2115 2107 2106 2105 210...

output:

1500 1939
9639 14094
15053 16385
105 709
11301 14867
1907 12653
1596 8769

result:

ok 7 cases

Test #12:

score: 0
Accepted
time: 16ms
memory: 29940kb

input:

9
14132
14128 14132 14131 14129 14130 14126 14117 14115 14114 14111 14110 14112 14108 14105 14104 14103 14102 14101 14100 14091 14093 14092 14090 14088 14082 14083 14081 14077 14075 14073 14072 14074 14071 14068 14067 14060 14059 14058 14057 14056 14055 14053 14052 14051 14043 14042 14038 14034 1403...

output:

2533 2905
12072 14624
5335 6106
702 1000
1216 4140
1306 9473
54 87
2160 5749
1432 1647

result:

ok 9 cases

Test #13:

score: 0
Accepted
time: 16ms
memory: 29708kb

input:

9
11668
122 3358 10900 8761 11606 6985 11355 6706 11563 3705 7295 627 11650 6491 8905 8408 1648 3401 4976 9571 8524 2075 10416 9513 3700 3565 4160 5098 8140 909 3951 11517 7913 9256 10863 3141 5284 5805 784 4403 3751 8015 10058 6313 3547 8244 726 719 9645 9538 8839 10802 681 4118 9712 8591 4722 6306...

output:

207 216
355 16303
10573 11147
1503 2840
5422 5651
313 472
9101 9799
535 6035
1766 2792

result:

ok 9 cases

Test #14:

score: 0
Accepted
time: 121ms
memory: 39792kb

input:

7
193626
193626 193625 193622 193621 193624 193623 193620 193617 193618 193619 193605 193606 193587 193578 193575 193574 193555 193563 193558 193561 193566 193554 193571 193570 193556 193567 193557 193560 193562 193559 193568 193553 193569 193565 193564 193573 193572 193550 193549 193547 193548 1935...

output:

82765 139831
58002 116795
6379 14664
35585 36836
10542 30649
24113 38850
490 1448

result:

ok 7 cases

Test #15:

score: 0
Accepted
time: 159ms
memory: 41228kb

input:

10
55747
55745 55744 55737 55734 55731 55729 55726 55724 55723 55725 55721 55720 55719 55718 55715 55713 55706 55705 55702 55701 55697 55695 55694 55692 55690 55687 55686 55685 55683 55681 55682 55680 55678 55669 55667 55666 55662 55654 55653 55649 55648 55645 55644 55643 55642 55641 55628 55627 556...

output:

25048 28220
49747 85833
41617 167132
5147 11329
331 1530
5963 53264
3056 30379
126366 133195
6947 31910
90122 92794

result:

ok 10 cases

Test #16:

score: 0
Accepted
time: 149ms
memory: 39988kb

input:

8
161886
161886 161884 161883 161881 161880 161877 161874 161873 161871 161872 161869 161868 161866 161865 161862 161858 161856 161855 161852 161851 161845 161846 161841 161839 161837 161836 161834 161833 161830 161828 161826 161820 161819 161821 161818 161817 161815 161810 161809 161807 161803 1618...

output:

14047 145753
48602 66627
15190 48450
35562 48992
54249 54651
33403 41987
78930 82807
5621 39152

result:

ok 8 cases

Test #17:

score: 0
Accepted
time: 397ms
memory: 57064kb

input:

8
477214
477214 477209 477208 477207 477206 477204 477205 477199 477198 477200 477196 477192 477193 477189 477190 477188 477185 477184 477182 477181 477180 477174 477173 477172 477171 477170 477163 477164 477162 477157 477158 477156 477155 477154 477151 477145 477146 477134 477135 477133 477132 4771...

output:

69720 198310
151 10152
127265 139375
101073 402556
175992 198298
129760 142366
5990 14234
191453 368817

result:

ok 8 cases

Test #18:

score: 0
Accepted
time: 269ms
memory: 59988kb

input:

7
104640
80979 94896 93379 84998 101575 69108 32621 13413 19543 63751 74406 100342 91227 41571 7722 15382 88496 71052 98146 91567 98194 76721 20313 26614 79982 69719 85888 82373 104512 10114 34784 77042 99044 54249 83799 63420 72841 67390 96124 80151 102095 44828 82307 74818 58750 94133 63179 74514 ...

output:

37997 40810
46196 108910
85667 108875
11560 27356
25500 36269
218547 334416
31523 85710

result:

ok 7 cases

Test #19:

score: 0
Accepted
time: 237ms
memory: 58788kb

input:

7
3719
3719 3718 3715 3712 3710 3711 3701 3700 3698 3696 3692 3690 3687 3686 3683 3682 3681 3678 3677 3676 3675 3673 3674 3670 3669 3664 3663 3661 3660 3658 3659 3655 3654 3651 3650 3643 3641 3635 3634 3633 3631 3632 3630 3628 3629 3627 3626 3624 3622 3618 3617 3614 3611 3610 3606 3605 3604 3599 359...

output:

2315 3633
38218 40408
11209 21572
70030 115100
207417 216701
150862 161659
58611 264533

result:

ok 7 cases

Extra Test:

score: 0
Extra Test Passed