結果

問題 No.2065 Sum of Min
ユーザー みここみここ
提出日時 2022-12-13 20:22:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 95,652 KB
実行使用メモリ 12,296 KB
最終ジャッジ日時 2024-04-25 04:31:36
合計ジャッジ時間 10,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 282 ms
12,040 KB
testcase_05 AC 270 ms
12,164 KB
testcase_06 AC 282 ms
12,036 KB
testcase_07 AC 298 ms
12,172 KB
testcase_08 AC 340 ms
12,040 KB
testcase_09 AC 313 ms
12,036 KB
testcase_10 AC 319 ms
12,040 KB
testcase_11 AC 320 ms
12,296 KB
testcase_12 AC 366 ms
12,036 KB
testcase_13 AC 356 ms
12,040 KB
testcase_14 AC 355 ms
12,164 KB
testcase_15 AC 352 ms
12,296 KB
testcase_16 AC 361 ms
12,040 KB
testcase_17 AC 366 ms
12,168 KB
testcase_18 AC 355 ms
12,164 KB
testcase_19 AC 357 ms
12,036 KB
testcase_20 AC 362 ms
12,040 KB
testcase_21 AC 352 ms
12,296 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    }
    sort(z, z + n);
    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 + q);
    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