結果

問題 No.2065 Sum of Min
ユーザー hourenhouren
提出日時 2022-09-02 22:21:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 185,484 KB
実行使用メモリ 9,620 KB
最終ジャッジ日時 2023-08-10 04:35:36
合計ジャッジ時間 6,039 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 61 ms
9,284 KB
testcase_05 AC 64 ms
9,428 KB
testcase_06 AC 71 ms
9,512 KB
testcase_07 AC 61 ms
9,420 KB
testcase_08 AC 82 ms
9,408 KB
testcase_09 AC 82 ms
9,432 KB
testcase_10 AC 77 ms
9,488 KB
testcase_11 AC 78 ms
9,528 KB
testcase_12 AC 84 ms
9,352 KB
testcase_13 AC 85 ms
9,348 KB
testcase_14 AC 83 ms
9,528 KB
testcase_15 AC 86 ms
9,428 KB
testcase_16 AC 84 ms
9,428 KB
testcase_17 AC 87 ms
9,284 KB
testcase_18 AC 86 ms
9,620 KB
testcase_19 AC 84 ms
9,316 KB
testcase_20 AC 83 ms
9,312 KB
testcase_21 AC 84 ms
9,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:54:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   54 |     for(auto [x,l,r,y]:query){
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).rbegin(),(x).rend()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
template <typename T>
struct BIT{
    int n;
    vector<T> data;
    BIT(int n=0) : n(n), data(n+1){}
    T sum(int i){
        T res = 0;
        for(; i; i -= i&-i){
            res += data[i];
        }
        return res;
    }
    void add(int i, T x){
        for(; i <= n; i += i&-i){
            data[i] += x;
        }
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    vector<ll> a(n);
    vector<P> b(n);
    BIT<ll> bit(n), s(n);
    rep(i,n){
        cin >> a[i];
        bit.add(i+1,a[i]);
        b[i] = {a[i],i+1};
    }
    sort(all(b));
    vector<T> query(q);
    rep(i,q){
        int l,r,x;
        cin >> l >> r >> x;
        l--;
        query[i] = {x,l,r,i};
    }
    sort(all(query));
    vector<ll> ans(q);
    int now = 0;
    for(auto [x,l,r,y]:query){
        while(now<n && b[now].first>x){
            bit.add(b[now].second, -a[b[now].second-1]);
            s.add(b[now].second, 1);
            now++;
        }
        ans[y] = bit.sum(r)-bit.sum(l) + x*(s.sum(r)-s.sum(l));
    }
    rep(i,q) cout << ans[i] << "\n";
    return 0;
}
0