結果
| 問題 | No.2065 Sum of Min |
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-09-02 22:21:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 1,571 bytes |
| コンパイル時間 | 2,146 ms |
| コンパイル使用メモリ | 189,236 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2024-11-16 04:13:02 |
| 合計ジャッジ時間 | 6,106 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
54 | for(auto [x,l,r,y]:query){
| ^
ソースコード
#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;
}
houren