結果

問題 No.911 ラッキーソート
ユーザー tnakao0123tnakao0123
提出日時 2019-10-21 01:14:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,623 bytes
コンパイル時間 3,396 ms
コンパイル使用メモリ 82,484 KB
実行使用メモリ 6,772 KB
最終ジャッジ日時 2023-09-15 14:52:46
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 74 ms
6,616 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 70 ms
6,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 75 ms
6,524 KB
testcase_44 AC 41 ms
6,540 KB
testcase_45 AC 43 ms
6,480 KB
testcase_46 AC 43 ms
6,552 KB
testcase_47 AC 42 ms
6,448 KB
testcase_48 AC 39 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 911.cc:  No.911 ラッキーソート - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int BN = 61;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N], es[MAX_N], dp[BN + 1];
int ds[BN];

/* subroutines */

ll count(ll a) {
  ll c = 0;
  for (int k = BN - 1; k >= 0; k--)
    if ((a >> k) & 1) c += dp[k];
  return c;
}

/* main */

int main() {
  int n;
  ll l, r;
  scanf("%d%lld%lld", &n, &l, &r);

  for (int i = 0; i < n; i++) scanf("%lld", as + i);

  for (int k = BN - 1; k >= 0; k--) {
    ll bk = 1LL << k;
    ll pe0 = es[0] | (as[0] & bk), pe1 = pe0 ^ bk;
    bool ok0 = true, ok1 = true;
    for (int i = 1; i < n; i++) {
      ll ei0 = es[i] | (as[i] & bk), ei1 = ei0 ^ bk;
      if (pe0 > ei0) ok0 = false;
      if (pe1 > ei1) ok1 = false;
      pe0 = ei0, pe1 = ei1;
    }

    int di = 0;
    if (ok0) di++;
    if (ok1) di++;
    if (di == 0) {
      puts("0");
      return 0;
    }
    ds[k] = di;

    for (int i = 0; i < n; i++) {
      es[i] |= (as[i] & bk);
      if (! ok0) es[i] ^= bk;
    }
  }

  dp[0] = 1;
  for (int k = 0; k < BN; k++) dp[k + 1] = dp[k] * ds[k];

  ll cl = count(l), cr = count(r + 1);
  //printf("cl=%lld, cr=%lld\n", cl, cr);
  printf("%lld\n", cr - cl);
  return 0;
}
0