結果

問題 No.8085 Math...?
ユーザー siman
提出日時 2023-01-09 19:51:21
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,120 bytes
コンパイル時間 4,845 ms
コンパイル使用メモリ 145,704 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 22:13:33
合計ジャッジ時間 8,533 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll mod_pow(ll x, ll n, ll mod = MOD) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }

    x = x * x % mod;
    n >>= 1;
  }

  return res;
}

ll mod_inverse(ll x, ll mod = MOD) {
  return mod_pow(x, mod - 2, mod);
}

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

  vector<ll> A;
  vector<ll> B;

  for (int i = 0; i < Q; ++i) {
    ll a, b;
    cin >> a >> b;

    A.push_back(a);
    B.push_back(b);
  }

  vector<ll> C = A;
  sort(C.begin(), C.end());
  ll i = 1;
  ll val = 1;
  map<ll, ll> memo;

  for (ll c : C) {
    while (i <= c && val > 0) {
      val *= i;
      val %= MOD;
      ++i;
    }

    memo[c] = val;
  }

  for (int i = 0; i < A.size(); ++i) {
    ll a = A[i];
    ll b = B[i];
    ll v1 = memo[a];
    ll v2 = b * (1LL + b) * mod_inverse(2);

    cout << v1 * v2 % MOD  << endl;
  }

  return 0;
}
0