結果

問題 No.2735 Demarcation
ユーザー 👑 emthrmemthrm
提出日時 2024-04-20 02:59:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,814 bytes
コンパイル時間 3,301 ms
コンパイル使用メモリ 287,036 KB
実行使用メモリ 17,356 KB
最終ジャッジ日時 2024-04-20 02:59:31
合計ジャッジ時間 8,374 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 53 ms
11,096 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int L = 87;
  int n; cin >> n;
  vector<int> x(n);
  for (int& x_i : x) cin >> x_i;
  vector<int> v(n, 0);
  FOR(i, 1, n) v[i] = v[i - 1] + (x[i] == x[i - 1]);
  int q; cin >> q;
  while (q--) {
    int l, r; ll s; cin >> l >> r >> s; --l; --r;
    if (r - l <= 60 && (1LL << (r - l)) <= s) {
      cout << "-1\n";
    } else if (const int adj = v[r] - v[l]; adj > 60 || (1LL << adj) > s) {
      cout << 0 << '\n';
    } else if (r - l + 1 > L) {
      cout << 1 << '\n';
    } else {
      int ans = 1;
      for (; ; ++ans) {
        vector<ll> dp(r - l + 2, 0);
        dp[0] = 1;
        map<int, int> num;
        for (int i = l, j = l; i <= r; ++i) {
          ++num[x[i]];
          for (; num.size() > ans + 1; ++j) {
            if (--num[x[j]] == 0) num.erase(x[j]);
          }
          FOR(x, j, i + 1) dp[i - l + 1] += dp[x - l];
        }
        if (dp[r - l + 1] > s) break;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
0