結果

問題 No.752 mod数列
ユーザー ei1333333ei1333333
提出日時 2018-11-09 22:45:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,420 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 206,864 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-08-13 11:57:42
合計ジャッジ時間 7,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 21 ms
4,576 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 21 ms
4,508 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 210 ms
4,380 KB
testcase_21 AC 212 ms
4,380 KB
testcase_22 AC 211 ms
4,380 KB
testcase_23 AC 218 ms
4,380 KB
testcase_24 AC 219 ms
4,384 KB
testcase_25 AC 86 ms
4,872 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 237 ms
4,428 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 16 ms
4,380 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< int64 > sum;
  sum.push_back(0);
  int64 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), 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