結果

問題 No.911 ラッキーソート
ユーザー Iván SotoIván Soto
提出日時 2021-05-12 15:41:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 3,120 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 209,980 KB
実行使用メモリ 4,772 KB
最終ジャッジ日時 2023-10-24 05:08:47
合計ジャッジ時間 5,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 49 ms
4,772 KB
testcase_14 AC 50 ms
4,772 KB
testcase_15 AC 50 ms
4,772 KB
testcase_16 AC 52 ms
4,772 KB
testcase_17 AC 51 ms
4,772 KB
testcase_18 AC 52 ms
4,772 KB
testcase_19 AC 50 ms
4,772 KB
testcase_20 AC 52 ms
4,772 KB
testcase_21 AC 54 ms
4,772 KB
testcase_22 AC 54 ms
4,772 KB
testcase_23 AC 50 ms
4,508 KB
testcase_24 AC 46 ms
4,508 KB
testcase_25 AC 31 ms
4,348 KB
testcase_26 AC 22 ms
4,348 KB
testcase_27 AC 12 ms
4,348 KB
testcase_28 AC 7 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 50 ms
4,772 KB
testcase_39 AC 53 ms
4,772 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 52 ms
4,772 KB
testcase_42 AC 36 ms
4,348 KB
testcase_43 AC 51 ms
4,772 KB
testcase_44 AC 49 ms
4,772 KB
testcase_45 AC 50 ms
4,772 KB
testcase_46 AC 51 ms
4,772 KB
testcase_47 AC 49 ms
4,772 KB
testcase_48 AC 51 ms
4,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *  author: ivanzuki   
 *  created: Tue May 11 2021
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
template<typename T> void dout(string name, int idx, T arg) {
  cerr << name << " = " << to_string(arg);
}

template<typename T1, typename... T2> void dout(string names, int idx, T1 arg, T2... args) {
  cerr << names.substr(0, names.find(',')) << " = " << to_string(arg) << ", ";
  dout(names.substr(names.find(',') + 2), idx + 1, args...);
}

#ifdef LOCAL
#define debug(...) cerr << "[", dout(#__VA_ARGS__, 0, __VA_ARGS__), cerr << "]" << endl;
#else
#define debug(...) 42
#endif

const int B = 60;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long l, r;
  cin >> n >> l >> r;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> mask(B + 1);
  for (int i = 0; i + 1 < n; i++) {
    for (int bit = B; bit >= 0; bit--) {
      int b1 = (a[i] >> bit) & 1;
      int b2 = (a[i + 1] >> bit) & 1;
      if (b1 == 0 && b2 == 1) {
        mask[bit] |= 1;
        break;
      } else if (b1 == 1 && b2 == 0) {
        mask[bit] |= 2;
        break;
      }
    }
  }
  for (int bit = B; bit >= 0; bit--) {
    if (mask[bit] == 3) {
      cout << 0 << '\n';
      return 0;
    }
  }
  auto Solve = [&](long long mx) {
    vector<vector<long long>> dp(B + 2, vector<long long>(2, 0));
    dp[0][0] = 1;
    for (int bit = B; bit >= 0; bit--) {
      int i = B - bit;
      int b_mx = (mx >> bit) & 1;
      int b_x = mask[bit];
      if (b_x == 0) {  // it can any of 0 or 1
        if (b_mx == 0) {
          dp[i + 1][0] += dp[i][0];
          dp[i + 1][1] += 2 * dp[i][1];
        } else {
          dp[i + 1][1] += dp[i][0] + 2 * dp[i][1];
          dp[i + 1][0] += dp[i][0];
        }
      } else if (b_x == 1) {  // it must be 0
        if (b_mx == 0) {
          dp[i + 1][0] += dp[i][0];
          dp[i + 1][1] += dp[i][1];
        } else {
          dp[i + 1][1] += dp[i][0] + dp[i][1];
        }
      } else if (b_x == 2) {  // it must be 1
        if (b_mx == 0) {
          dp[i + 1][1] += dp[i][1];
        } else {
          dp[i + 1][0] += dp[i][0];
          dp[i + 1][1] += dp[i][1];
        }
      } else {
        assert(0);
      }
    }
    return dp[B + 1][0] + dp[B + 1][1];
  };
  long long ans = Solve(r) - (l - 1 < 0 ? 0 : Solve(l - 1));
  cout << ans << '\n';
  return 0;
}
0