結果

問題 No.752 mod数列
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-11-10 08:17:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,640 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 172,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 00:41:08
合計ジャッジ時間 4,054 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 22 ms
5,376 KB
testcase_16 AC 30 ms
5,376 KB
testcase_17 AC 37 ms
5,376 KB
testcase_18 AC 29 ms
5,376 KB
testcase_19 AC 34 ms
5,376 KB
testcase_20 AC 35 ms
5,376 KB
testcase_21 AC 41 ms
5,376 KB
testcase_22 AC 36 ms
5,376 KB
testcase_23 AC 40 ms
5,376 KB
testcase_24 AC 39 ms
5,376 KB
testcase_25 AC 15 ms
5,376 KB
testcase_26 AC 34 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 34 ms
5,376 KB
testcase_30 AC 44 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int P, Q, RP, A[101010];
ll B[101010], C[101010];
vector<pair<int, int>> v;
//---------------------------------------------------------------------------------------------------
ll g(int L, int R) {
    int n = R - L + 1;
    return 1LL * (L + R) * n / 2;
}
//---------------------------------------------------------------------------------------------------
ll f(int x) {
    if (x <= RP) return B[x];

    ll res = B[RP];
    if (P < x) {
        res += 1LL * P * (x - P);
        x = P;
    }

    int id = upper_bound(all(v), make_pair(x, -1)) - v.begin() - 1;
    res += C[id];

    int l = v[id].first + 1;
    int r = x;
    if (l <= r) {
        int n = r - l + 1;
        res += 1LL * n * P;
        res -= g(l, r) * v[id+1].second;
    }
    

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> P >> Q;

    for (RP = 1; RP * RP <= P; RP++) A[RP] = P / RP;
    rep(i, 1, RP+1) B[i] = B[i - 1] + P % i;
    rrep(i, RP - 1, 1) v.push_back({ A[i], i });

    int n = v.size();

    rep(i, 1, n) {
        C[i] = C[i - 1];
        int l = v[i - 1].first + 1;
        int r = v[i].first;
        int n = r - l + 1;
        C[i] += 1LL * n * P;
        C[i] -= g(l, r) * v[i].second;
    }

    rep(q, 0, Q) {
        int L, R; cin >> L >> R;
        ll ans = f(R) - f(L - 1);
        printf("%lld\n", ans);
    }
}
0