結果
問題 | No.2065 Sum of Min |
ユーザー |
|
提出日時 | 2022-09-03 01:20:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 181 ms / 2,000 ms |
コード長 | 684 bytes |
コンパイル時間 | 861 ms |
コンパイル使用メモリ | 79,768 KB |
実行使用メモリ | 8,172 KB |
最終ジャッジ日時 | 2024-11-16 09:07:15 |
合計ジャッジ時間 | 6,321 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream>#include<algorithm>#include<atcoder/fenwicktree>using namespace std;int N,Q;int L[1<<17],R[1<<17];long ans[1<<17];main(){cin>>N>>Q;atcoder::fenwick_tree<long>C(N),A(N);vector<pair<int,int> >qs;for(int i=0;i<N;i++){int a;cin>>a;qs.push_back(make_pair(a,i));C.add(i,1);}for(int i=0;i<Q;i++){int x;cin>>L[i]>>R[i]>>x;L[i]--;qs.push_back(make_pair(x,~i));}sort(qs.begin(),qs.end());for(pair<int,int>p:qs){if(p.second>=0){C.add(p.second,-1);A.add(p.second,p.first);}else{int i=~p.second;ans[i]=C.sum(L[i],R[i])*p.first+A.sum(L[i],R[i]);}}for(int i=0;i<Q;i++)cout<<ans[i]<<"\n";}