結果
問題 | No.2065 Sum of Min |
ユーザー | shobonvip |
提出日時 | 2022-09-02 22:32:32 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,893 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 4,240 ms |
コンパイル使用メモリ | 263,548 KB |
実行使用メモリ | 6,164 KB |
最終ジャッジ日時 | 2023-08-10 04:48:32 |
合計ジャッジ時間 | 23,898 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,384 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,384 KB |
testcase_04 | AC | 489 ms
5,976 KB |
testcase_05 | AC | 804 ms
5,952 KB |
testcase_06 | AC | 962 ms
5,792 KB |
testcase_07 | AC | 578 ms
5,888 KB |
testcase_08 | AC | 536 ms
5,900 KB |
testcase_09 | AC | 263 ms
6,148 KB |
testcase_10 | AC | 1,871 ms
6,004 KB |
testcase_11 | AC | 1,893 ms
6,164 KB |
testcase_12 | AC | 886 ms
5,972 KB |
testcase_13 | AC | 863 ms
5,796 KB |
testcase_14 | AC | 866 ms
5,796 KB |
testcase_15 | AC | 876 ms
5,888 KB |
testcase_16 | AC | 871 ms
5,844 KB |
testcase_17 | AC | 874 ms
5,800 KB |
testcase_18 | AC | 888 ms
5,980 KB |
testcase_19 | AC | 889 ms
5,996 KB |
testcase_20 | AC | 895 ms
5,920 KB |
testcase_21 | AC | 884 ms
5,840 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; typedef modint998244353 mint; typedef long long ll; int main(){ int n,q; cin >> n >> q; int b = int(pow(n, 0.5) + 1); vector<ll> a(n), dat(n), pfix(n); for (int i=0; i<n; i++){ cin >> a[i]; dat[i] = a[i]; } for (int i=0; i<b; i++){ sort(dat.begin() + min(n, i*b), dat.begin() + min(n, (i+1)*b)); ll tmp = 0; for (int j=i*b; j<min(n, (i+1)*b); j++){ tmp += dat[j]; pfix[j] = tmp; } } for (int cases=0; cases<q; cases++){ int l,r; ll x; cin >> l >> r >> x; l--; int tl = l+b-(l%b), tr = r-(r%b); ll ans = 0; for (int i=l; i<min(r,tl); i++){ ans += min(x, a[i]); } for (int i=tl/b; i<tr/b; i++){ int targ = lower_bound(dat.begin() + i*b, dat.begin() + (i+1)*b, x) - dat.begin() - i*b; ans += (b-targ) * x; if (targ > 0) ans += pfix[i*b+targ-1]; } for (int i=max(tl,tr); i<r; i++){ ans += min(x, a[i]); } cout << ans << endl; } }