結果
| 問題 |
No.877 Range ReLU Query
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2019-09-06 22:14:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 394 ms / 2,000 ms |
| コード長 | 2,458 bytes |
| コンパイル時間 | 1,168 ms |
| コンパイル使用メモリ | 97,980 KB |
| 実行使用メモリ | 17,392 KB |
| 最終ジャッジ日時 | 2024-11-08 10:04:47 |
| 合計ジャッジ時間 | 6,264 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define int long long
template<typename T> class segtree{
private:
int n,sz;
vector<T> node;
public:
segtree(vector<T>& v) : sz((int)v.size()){
n = 1;
while(n < sz){
n *= 2;
}
node.resize(2*n-1,0);
for(int i = 0; i < sz; i++){
node[i+n-1] = v[i];
}
for(int i=n-2; i>=0; i--){
node[i] = node[i*2+1]+node[i*2+2];
}
}
void update(int k,T a){
k += n-1;
node[k] = a;
while(k>0){
k = (k-1)/2;
node[k] = node[2*k+1]+node[2*k+2];
}
}
T query(int a,int b,int k=0,int l=0,int r=-1){
if(r < 0) r = n;
if(r <= a || b <= l){
return 0;
}
if(a <= l && r <= b){
return node[k];
}else{
T vl = query(a,b,2*k+1,l,(l+r)/2);
T vr = query(a,b,2*k+2,(l+r)/2,r);
return vl+vr;
}
}
void print(){
for(int i = 0; i < sz; i++){
cout<<query(i,i+1)<< " ";
}
cout<<endl;
}
};
signed main(){
int n,q;
cin >> n >> q;
vector<int>a(n);
rep(i,n)cin >> a[i];
vector<int>b(n,1);
segtree<int>sg(a),sg2(b);
vector<pair<pair<int,int>,pair<int,int> > >s;
rep(i,n){
s.push_back(MP(MP(a[i],i),MP(0,0)));
}
rep(i,q){
int a,b,c,d;
cin >> a >> b >> c >> d;
s.push_back(MP(MP(d,inf+i),MP(b,c)));
}
sort(s.begin(),s.end());
vector<int> res(q);
rep(i,n+q){
if(s[i].first.second<inf){
sg.update(s[i].first.second,0);
sg2.update(s[i].first.second,0);
}else{
int l = s[i].second.first-1;
int r = s[i].second.second;
int query = (s[i].first.second)-inf;
res[query] = sg.query(l,r)-s[i].first.first*sg2.query(l,r);
}
}
rep(i,q){
cout << res[i] << endl;
}
return 0;
}
mtsd