結果

問題 No.2065 Sum of Min
ユーザー ripityripity
提出日時 2022-10-30 14:42:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 5,005 ms
コンパイル使用メモリ 277,396 KB
実行使用メモリ 28,052 KB
最終ジャッジ日時 2023-09-21 12:31:58
合計ジャッジ時間 17,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 236 ms
28,052 KB
testcase_05 AC 223 ms
25,640 KB
testcase_06 AC 274 ms
21,724 KB
testcase_07 AC 157 ms
13,436 KB
testcase_08 AC 356 ms
22,192 KB
testcase_09 AC 382 ms
27,888 KB
testcase_10 AC 381 ms
25,592 KB
testcase_11 AC 375 ms
25,740 KB
testcase_12 AC 442 ms
27,728 KB
testcase_13 AC 431 ms
27,628 KB
testcase_14 AC 429 ms
27,664 KB
testcase_15 AC 429 ms
27,500 KB
testcase_16 AC 425 ms
27,532 KB
testcase_17 AC 429 ms
27,660 KB
testcase_18 AC 428 ms
27,636 KB
testcase_19 AC 426 ms
27,736 KB
testcase_20 AC 421 ms
27,548 KB
testcase_21 AC 427 ms
27,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main() {
  int N, Q;
  cin >> N >> Q;
  vector<long long> A(N+1), P(N+1);
  vector<pair<long long, int>> B(N+2);
  fenwick_tree<long long> bin(N+1), val(N+1);
  for( int i = 1; i <= N; i++ ) {
    cin >> A[i];
    B[i] = make_pair(A[i], i);
  }
  B[N+1] = make_pair(1<<30, 1<<30);
  sort(B.begin(), B.end());
  for( int i = 1; i <= N; i++ ) {
    P[B[i].second] = i;
  }
  vector<int> L(Q+1), R(Q+1);
  vector<long long> X(Q+1);
  vector<vector<long long>> query(N+1, vector<long long>());
  map<pair<int, long long>, long long> res;
  for( int i = 1; i <= Q; i++ ) {
    cin >> L[i] >> R[i] >> X[i];
    query[L[i]-1].emplace_back(X[i]);
    query[R[i]].emplace_back(X[i]);
  }
  for( int i = 1; i <= N; i++ ) {
    bin.add(P[i], 1);
    val.add(P[i], A[i]);
    for( long long& x : query[i] ) {
      pair<long long, int> y = make_pair(x, N+1);
      pair<int, long long> key = make_pair(i, x);
      int k = upper_bound(B.begin(), B.end(), y)-B.begin();
      res[key] = val.sum(0, k)+x*bin.sum(k, N+1);
    }
  }
  for( int i = 1; i <= Q; i++ ) {
    pair<int, long long> keyl = make_pair(L[i]-1, X[i]), keyr = make_pair(R[i], X[i]);
    cout << res[keyr]-res[keyl] << '\n';
  }
}
0