結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 32 ms
5,376 KB
testcase_17 AC 42 ms
5,376 KB
testcase_18 AC 33 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 40 ms
5,376 KB
testcase_21 AC 39 ms
5,376 KB
testcase_22 AC 39 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
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 += g(P + 1, x);
        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