結果
| 問題 |
No.877 Range ReLU Query
|
| コンテスト | |
| ユーザー |
Cinnamoroll
|
| 提出日時 | 2019-09-06 22:15:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 134 ms / 2,000 ms |
| コード長 | 6,638 bytes |
| コンパイル時間 | 2,173 ms |
| コンパイル使用メモリ | 191,600 KB |
| 実行使用メモリ | 13,092 KB |
| 最終ジャッジ日時 | 2024-11-08 10:05:01 |
| 合計ジャッジ時間 | 4,920 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
// warm heart, wagging tail,and a smile just for you!
//
// ▒█████▒▒
// ██████████▒
// ▒████████████▒
// ██████████████████
// ████████████████████▒
// ▒██████████████████████▒
// ▒███████████████████████
// ▒████▒▒▒▒▒▒█████████████████▒
// ███▒▒▒▒▒▒██████████████████████▒▒▒
// ▒██▒▒███████████████████████▒▒▒▒▒██████
// ▒█████████████████████████▒▒▒▒▒▒█████████▒
// ▒█████████████████████▒▒▒▒▒▒██████████████
// ▒████ ████▒▒▒▒▒████ ████▒
// ▒█████▒ ████ ▒▒▒▒███████ ████ ██████▒
// ▒██▒▒▒▒▒ ██████ █████████ ██████ ██▒▒▒██▒
// █████████ ████████ █████████ ████████ ▒▒▒▒█████
// ▒█████████ ██████ ████████▒ ██████ █████████
// ▒██████████ ████ █████▒▒▒▒▒▒ ████ ██████████
// ████████████ ▒▒▒▒▒▒▒████████ ███████████▒
// ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
// ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
// ▒▒▒▒▒▒▒▒▒██████████████ ███████▒▒▒▒███████████
// █████████████████████████ ███████▒▒▒██████████████▒
// █████████████████████████████ ███████▒▒▒██████████████████▒
// ██████████████████████████████████████████████████████████████████████
// ██████████████████████████████████████████████████████████████████▒
// ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
template <typename T>
struct SegmentTree{
using F = function<T(T,T)>;
int n;
F f;
T ti;
vector<T> dat;
SegmentTree(){};
SegmentTree(F f,T ti):f(f),ti(ti){}
void init(int n_){
n=1;
while(n<n_) n<<=1;
dat.assign(n<<1,ti);
}
void build(const vector<T> &v){
int n_=v.size();
init(n_);
for(int i=0;i<n_;i++) dat[n+i]=v[i];
for(int i=n-1;i;i--)
dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
}
void update(int k,T x){
dat[k+=n]=x;
while(k>>=1)
dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
}
void add(int k,T x){
dat[k+=n]+=x;
while(k>>=1)
dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
}
T query(int a,int b){
T vl=ti,vr=ti;
for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
if(l&1) vl=f(vl,dat[l++]);
if(r&1) vr=f(dat[--r],vr);
}
return f(vl,vr);
}
template<typename C>
int find(int a, int b, C &check, T x, int k=1, int l=0, int r=-1){
if(r<0)r=n;
if(!check(f(x,dat[k]))||r<=a||b<=l)return -1;
if(r-l==1)return l;
int xl = find(a,b,check,x,(k<<1),l,(l+r)/2);
if(xl>=0)return xl;
x = f(x,dat[(k<<1)]);
return find(a,b,check,x,(k<<1)|1,(l+r)/2,r);
}
template<typename C>
int find(int a, int b, C &check){
T x=ti;
return find(a,b,check,x);
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin >> n >> q;
vector<P> a(n);
REP(i,n) cin >> a[i].fs, a[i].sc = i;
sort(a.rbegin(),a.rend());
auto f = [](int a,int b){return a+b;};
SegmentTree<int> seg1(f,0), seg2(f,0);
seg1.build(vec(n,0));
seg2.build(vec(n,0));
vec ans(q); using T = tuple<int,int,int,int>;
vector<T> b(q);
REP(i,q){
int x,y,z,w;
cin >> w >> x >> y >> z;
b[i] = T(z,x-1,y,i);
}
sort(b.rbegin(),b.rend());
int id = 0;
REP(i,q){
int x,l,r,in;
tie(x,l,r,in) = b[i];
while(id<n&&a[id].fs >= x){
seg1.update(a[id].sc,a[id].fs);
seg2.update(a[id].sc,1);
id++;
}
ans[in] = seg1.query(l,r) - seg2.query(l,r)*x;
}
REP(i,q) cout << ans[i] << "\n";
return 0;
}
Cinnamoroll