結果

問題 No.911 ラッキーソート
ユーザー tnakao0123tnakao0123
提出日時 2019-10-21 02:07:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,815 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 6,684 KB
最終ジャッジ日時 2023-09-15 14:52:51
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,500 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 70 ms
6,508 KB
testcase_14 AC 71 ms
6,640 KB
testcase_15 AC 70 ms
6,484 KB
testcase_16 AC 71 ms
6,576 KB
testcase_17 AC 71 ms
6,684 KB
testcase_18 AC 71 ms
6,584 KB
testcase_19 AC 70 ms
6,484 KB
testcase_20 AC 70 ms
6,604 KB
testcase_21 AC 69 ms
6,440 KB
testcase_22 AC 68 ms
6,484 KB
testcase_23 AC 63 ms
6,288 KB
testcase_24 AC 58 ms
5,980 KB
testcase_25 AC 37 ms
5,120 KB
testcase_26 AC 28 ms
4,768 KB
testcase_27 AC 14 ms
4,504 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,500 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 72 ms
6,548 KB
testcase_39 AC 66 ms
6,288 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 71 ms
6,528 KB
testcase_42 AC 45 ms
5,332 KB
testcase_43 AC 71 ms
6,492 KB
testcase_44 AC 42 ms
6,644 KB
testcase_45 AC 43 ms
6,496 KB
testcase_46 AC 42 ms
6,416 KB
testcase_47 AC 42 ms
6,544 KB
testcase_48 AC 39 ms
5,064 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], bits[BN + 1];

/* subroutines */

ll count(ll a) {
  ll c = 0;
  for (int k = BN; k >= 0; k--) {
    if (((a >> k) & 1) == 0) {
      if (! (bits[k] & 1)) break;
    }
    else {
      if (bits[k] & 1) c += dp[k];
      if (! (bits[k] & 2)) break;
    }
  }
  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);

  bits[BN] = 3;
  for (int k = BN - 1; k >= 0; k--) {
    ll bk = 1LL << k;

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

    ds[k] = ok0 + ok1;
    bits[k] = ok0 | (ok1 << 1);
    if (ds[k] == 0) {
      puts("0");
      return 0;
    }

    ll xk = (ok0) ? 0 : bk;
    for (int i = 0; i < n; i++) es[i] |= ((as[i] & bk) ^ xk);
  }

  dp[0] = 1;
  for (int k = 0; k < BN; k++) dp[k + 1] = dp[k] * ds[k];
  //for (int i = 0; i < BN; i++) putchar('0' + ds[i]); putchar('\n');

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