結果

問題 No.752 mod数列
ユーザー ei1333333ei1333333
提出日時 2018-11-09 22:46:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 205,660 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-08-13 11:58:46
合計ジャッジ時間 7,850 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 22 ms
4,976 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 18 ms
5,052 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 22 ms
5,120 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 214 ms
4,380 KB
testcase_21 AC 216 ms
4,380 KB
testcase_22 AC 212 ms
4,380 KB
testcase_23 AC 221 ms
4,380 KB
testcase_24 AC 218 ms
4,376 KB
testcase_25 AC 87 ms
5,244 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 239 ms
4,952 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 16 ms
4,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;


int main() {
  int P, Q;
  cin >> P >> Q;

  vector< pair< pair< int, int >, int > > rad;
  int ptr = 1;
  while(ptr <= P) {
    int ok = ptr, ng = P + 1;
    int real = P / ptr;
    while(ng - ok > 1) {
      int mid = (ok + ng) / 2;
      if(P / mid == real) ok = mid;
      else ng = mid;
    }
    rad.emplace_back(make_pair(ptr, ok), P / ptr);
    ptr = ok + 1;
  }

  vector< __int128_t > sum;
  sum.push_back(0);
  __int128_t add = 0LL;
  for(auto &p : rad) {
    auto range = p.first;
    auto val = p.second;
    int latte = range.first;
    int malta = range.second;
    add += val * (1LL * latte * (latte - 1) / 2);
    add -= val * (1LL * malta * (malta + 1) / 2);
    sum.push_back(add);
  }

  auto get = [&](int L) {
    __int128_t add = 1LL * P * L;
    auto it1 = lower_bound(begin(rad), end(rad), make_pair(make_pair(L - 1, -1), L)) - begin(rad);
    --it1;
    add += sum[it1];
    for(int i = it1; i < rad.size(); i++) {
      auto &p = rad[i];
      auto range = p.first;
      auto val = p.second;
      int latte = range.first;
      int malta = min(range.second, L);
      if(latte > malta) break;
      add += val * (1LL * latte * (latte - 1) / 2);
      add -= val * (1LL * malta * (malta + 1) / 2);
    }
    return (int64) add;
  };

  while(Q--) {
    int L, R;
    cin >> L >> R;
    cout << get(R) - get(L - 1) << endl;
  }

}

0