結果

問題 No.2065 Sum of Min
ユーザー みここみここ
提出日時 2022-12-13 20:19:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 95,692 KB
実行使用メモリ 12,188 KB
最終ジャッジ日時 2024-04-25 04:29:24
合計ジャッジ時間 9,306 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <atcoder/segtree>
#include <iostream>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

ll op(ll a, ll b)
{
    return a + b;
}

ll e()
{
    return 0;
}

int main()
{
    int n, q;
    cin >> n >> q;
    int a[100005];
    P z[100005];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        z[i] = P(a[i], i);
    }
    int l[100005], r[100005], x[100005];
    P p[100005];
    for(int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i] >> x[i];
        l[i]--;
        p[i] = P(x[i], i);
    }
    sort(p, p + n);
    segtree<ll, op, e> sum(n), cnt(n);
    for(int i = 0; i < n; i++)
    {
        cnt.set(i, 1);
    }
    ll ans[100005];
    int u = 0;
    for(int t = 0; t < q; t++)
    {
        int i = p[t].second;
        while(u < n && z[u].first <= x[i])
        {
            int j = z[u++].second;
            sum.set(j, a[j]);
            cnt.set(j, 0);
        }
        ans[i] = sum.prod(l[i], r[i]) + x[i] * cnt.prod(l[i], r[i]);
    }
    for(int i = 0; i < q; i++)
    {
        cout << ans[i] << endl;
    }
}
0