結果
| 問題 |
No.877 Range ReLU Query
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2019-09-06 21:59:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 2,000 ms |
| コード長 | 2,475 bytes |
| コンパイル時間 | 1,274 ms |
| コンパイル使用メモリ | 109,584 KB |
| 実行使用メモリ | 8,988 KB |
| 最終ジャッジ日時 | 2024-11-08 10:02:53 |
| 合計ジャッジ時間 | 3,811 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <cassert>
typedef long long ll;
using namespace std;
#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v) out << item << ", ";
out << "\b\b}";
return out;
}
#endif
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010
/* Binary Indexed Tree(0-index) */
template <typename Type = int>
struct BIT{
int bit_size;
vector<Type> data;
BIT(int n){
bit_size = n;
data.assign(n+2, 0);
}
//add x to kth value
void add(int k, Type x){
k++;
while(k <= bit_size){
data[k] += x;
k += k & (-k);
}
}
//sum of [0,k)
Type query(int k){
Type rec = 0;
while(k > 0){
rec += data[k];
k -= k & (-k);
}
return rec;
}
//sum of [a, b)
Type query(int a, int b){
return query(b) - query(a);
}
};
int main(){
int N, Q, a[SIZE];
int l[SIZE], r[SIZE], x[SIZE];
vector<pair<int,int> > query;
priority_queue<pair<int,int> > pq;
scanf("%d%d", &N, &Q);
BIT<ll> bit1(N), bit2(N);
for(int i=0; i<N; i++) {
scanf("%d", a+i);
pq.push({-a[i], i});
bit1.add(i, 1);
bit2.add(i, a[i]);
}
for(int i=0; i<Q; i++) {
scanf("%*d%d%d%d", l+i, r+i, x+i);
l[i]--;
query.push_back({x[i], i});
}
sort(query.begin(), query.end());
ll ans[SIZE];
for(int i=0; i<Q; i++) {
int idx = query[i].second;
while(pq.size() && -pq.top().first <= query[i].first) {
//debug(pq.top().first);
bit1.add(pq.top().second, -1);
bit2.add(pq.top().second, pq.top().first);
pq.pop();
}
ll s = bit1.query(l[idx], r[idx]);
ll t = bit2.query(l[idx], r[idx]);
ans[idx] = t - s * query[i].first;
}
for(int i=0; i<Q; i++) {
printf("%lld\n", ans[i]);
}
return 0;
}
goodbaton