結果
| 問題 | No.877 Range ReLU Query |
| コンテスト | |
| ユーザー |
tonegawa
|
| 提出日時 | 2020-08-12 18:26:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 450 ms / 2,000 ms |
| コード長 | 2,009 bytes |
| 記録 | |
| コンパイル時間 | 1,894 ms |
| コンパイル使用メモリ | 122,892 KB |
| 最終ジャッジ日時 | 2025-01-12 21:28:48 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:55:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | ll t;scanf("%lld", &t);
| ~~~~~^~~~~~~~~~~~
main.cpp:60:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
60 | ll a, b, c, d;scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
struct segtree{
ll M=1, INIT;
vector<ll> dat;
segtree(ll N, ll num){
INIT = num;
while(M<N) M*=2;
for(int i=0;i<M*2-1;i++) dat.push_back(num);
}
void update(ll x, ll k, ll l=0, int r=-1){
if(r==-1) r = M;
k+=M-1;
dat[k] += x;
while(k>0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2];
}
ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
if(r==-1) r = M;
if(b==-1) b = M;
if(r<=a || b<=l) return INIT;
if(a<=l && r<=b) return dat[k];
ll A = query(a, b, k*2+1, l, (l+r)/2);
ll B = query(a, b, k*2+2, (l+r)/2, r);
return A + B;
}
};
typedef tuple<ll, ll, ll, ll> tp; //x, l, r, idx
int main(int argc, char const *argv[]) {
ll n, q;std::cin >> n >> q;
segtree seg(n+1, 0), cnt(n+1, 0);
multiset<tp> st;
for(int i=0;i<n;i++){
ll t;scanf("%lld", &t);
st.insert(tp(-t, -1, i, 0));
}
vll ans(q);
for(int i=0;i<q;i++){
ll a, b, c, d;scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
st.insert(tp(-d,b,c,i));
}
for(auto itr = st.begin();itr!=st.end();itr++){
ll a = -get<0>(*itr);
ll b = get<1>(*itr);
ll c = get<2>(*itr);
ll d = get<3>(*itr);
if(b==-1) seg.update(a, c), cnt.update(1, c);
else{
ll S = seg.query(b-1, c);
ll num = cnt.query(b-1, c);
//std::cout << S << " " << num << " " << d << '\n';
ans[d] = S - num * a;
}
}
for(int i=0;i<q;i++) std::cout << ans[i] << '\n';
return 0;
}
tonegawa