結果
| 問題 |
No.877 Range ReLU Query
|
| コンテスト | |
| ユーザー |
gasin
|
| 提出日時 | 2019-09-07 16:17:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,082 ms / 2,000 ms |
| コード長 | 2,854 bytes |
| コンパイル時間 | 1,217 ms |
| コンパイル使用メモリ | 80,928 KB |
| 実行使用メモリ | 182,224 KB |
| 最終ジャッジ日時 | 2024-11-08 10:15:51 |
| 合計ジャッジ時間 | 11,906 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
pl operator+(const pl &l, const pl &r) {
return pl(l.first+r.first, l.second+r.second);
}
// 区間和、要素更新のsegtree
template<typename T>
struct permanent_segtree {
struct NODE {
T val;
struct NODE *l, *r;
};
int n;
T unit;
vector<NODE*> roots;
void init(int n_, T unit_){
n = 1;
unit = unit_;
while(n < n_) n *= 2;
vector<NODE*> nodes;
rep(i,2*n-1) {
NODE* nn = new NODE();
nn->val = unit;
nodes.push_back(nn);
}
rep(i,2*n-1) {
if (i < n-1) {
nodes[i]->l = nodes[2*i+1];
nodes[i]->r = nodes[2*i+2];
}
}
roots.push_back(nodes[0]);
}
void app(int a, T x, NODE* root, int l, int r) {
int b = a+1;
if (r <= a || b <= l) return;
if (a <= l && r <= b) {
root->val = x;
return;
}
NODE* nl = new NODE(*(root->l));
NODE* nr = new NODE(*(root->r));
root->r = nr;
root->l = nl;
app(a, x, nl, l, (l+r)/2);
app(a, x, nr, (l+r)/2, r);
root->val = nr->val + nl->val;
}
void update(int k, T a){
NODE* nr = new NODE(*(roots.back()));
roots.push_back(nr);
app(k, a, nr, 0, n);
}
T sub_query(int a, int b, NODE* root, int l, int r){
if(r <= a || b <= l) return unit;
if(a <= l && r <= b) return root->val;
T vl = sub_query(a,b,root->l,l,(l+r)/2);
T vr = sub_query(a,b,root->r,(l+r)/2,r);
return vl + vr;
}
T query (int a, int b, int t) {
return sub_query(a, b, roots[t], 0, n);
}
};
permanent_segtree<pl> seg;
int n, q;
pl a[100000];
int main() {
cin >> n >> q;
seg.init(n, pl(0,0));
rep(i,n) {
cin >> a[i].first;
a[i].second = i;
}
sort(a, a+n, greater<pl>());
rep(i,n) {
seg.update(a[i].second, pl(a[i].first, 1));
}
rep(i,q) {
ll f, l, r, x;
cin >> f >> l >> r >> x;
l--; r--;
int st = -1, en = n;
while (en-st > 1) {
int mid = (st + en) / 2;
if (a[mid].first < x) en = mid;
else st = mid;
}
pl val = seg.query(l, r+1, st+1);
cout << val.first - val.second*x << endl;
}
}
gasin