結果

問題 No.1742 Binary Indexed Train
ユーザー kusaf_
提出日時 2024-07-31 03:03:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 160 ms / 3,000 ms
コード長 544 bytes
コンパイル時間 2,784 ms
コンパイル使用メモリ 246,024 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-31 03:04:03
合計ジャッジ時間 8,236 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, Q;
  cin >> N >> Q;

  while(Q--) {
    ll L, R;
    cin >> L >> R;

    ll ans = 0;
    auto rec = [&](auto rec, ll l, ll r) -> void {
      if(L <= l && r <= R) {
        ans++;
        return;
      }
      if(r - l == 1) { return; }
      ll m = (l + r) / 2;
      if(m <= R) { rec(rec, m, r); }
      if(L <= m) { rec(rec, l, m); }
    };
    rec(rec, 0, 1LL << N);

    cout << ans << "\n";
  }
}
0