結果
| 問題 | No.877 Range ReLU Query |
| コンテスト | |
| ユーザー |
tonegawa
|
| 提出日時 | 2020-08-12 18:27:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 265 ms / 2,000 ms |
| コード長 | 1,693 bytes |
| 記録 | |
| コンパイル時間 | 1,287 ms |
| コンパイル使用メモリ | 122,760 KB |
| 最終ジャッジ日時 | 2025-01-12 21:29:00 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, const char**)’:
main.cpp:53:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
53 | ll t;scanf("%lld", &t);
| ~~~~~^~~~~~~~~~~~
main.cpp:58:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | 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 BIT{
ll M=1;
vector<ll> dat;
BIT(ll N){
while(N>M) M*=2;
dat.resize(M*2-1, 0);
}
void update(ll x, ll k){
for(int i=k+1;i<=M;i+=(i&(-i))){
dat[i] += x;
}
}
ll sum(ll r){
ll ret = 0;
for(int k=r;k>0;k-=(k&(-k))) ret += dat[k];
return ret;
}
ll query(ll l, ll r){
return sum(r) - sum(l);
}
};
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;
BIT seg(n+1), cnt(n+1);
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);
ans[d] = S - num * a;
}
}
for(int i=0;i<q;i++) printf("%lld\n", ans[i]);
return 0;
}
tonegawa