結果

問題 No.2065 Sum of Min
ユーザー GetDigit()GetDigit()
提出日時 2022-11-03 11:02:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 173,580 KB
実行使用メモリ 11,272 KB
最終ジャッジ日時 2023-09-24 20:46:13
合計ジャッジ時間 5,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <vector>
using namespace std;

int search(int x,vector<int> a,int N){
    if(x <= a[0]){
        return -1;
    }
    if(x > a[N-1]){
        return N;
    }
    int left = 0,right = N-1;
    int mid;
    while(1){
        mid = (left+right)/2;
        if(a[mid] >= x){
            right = mid;
        }
        if(a[mid + 1] < x){
            left = mid;
        }
        if(a[mid] < x && x <= a[mid+1]){
            break;
        }
    }
    return mid;
}

long get_ans(int N,int p,int x,vector<int> a,vector<long> a_sum){
    int n = search(x,a,N);
    long ans;
    long temp = ((long)p-(long)n)*(long)x;
    if(n < p){
        ans = a_sum[n+1] + temp;
    } else {
        ans = a_sum[p+1];
    }
    return ans;
}

int main(){
    int N,Q;
    cin >> N >> Q;
    vector<int> a(N,0);
    vector<long> a_sum(N+1,0);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
        a_sum[i+1] = a_sum[i] + (long)a[i];
    }
    int l,r,x;
    for(int i=0;i<Q;i++){
        cin >> l >> r >> x;
        cout << get_ans(N,r - 1,x,a,a_sum) - get_ans(N,l - 2,x,a,a_sum) << "\n";
    }
}
0