結果
| 問題 | No.877 Range ReLU Query |
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2020-05-26 20:18:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,456 bytes |
| 記録 | |
| コンパイル時間 | 3,795 ms |
| コンパイル使用メモリ | 250,896 KB |
| 最終ジャッジ日時 | 2025-01-10 15:48:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 TLE * 4 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
cout << x << " ";
print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int B = 575;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N,Q; cin >> N >> Q;
vector<int> A(N);
rep(i,N) cin >> A[i];
int sz = (N-1)/B+1;
vector<map<int, int>> bucket(sz);
vector<vector<ll>> S(sz);
rep(i,N) {
bucket[i/B][A[i]]++;
S[i/B].emplace_back(A[i]);
}
rep(i,sz) {
int cur = 0;
for (auto &j : bucket[i]) {
j.second += cur;
cur = j.second;
}
int M = S[i].size();
S[i].emplace_back(0);
sort(all(S[i]));
rep(j,M) S[i][j+1] += S[i][j];
}
while (Q--) {
int t,l,r,x; cin >> t >> l >> r >> x;
--l; --r;
ll ans = 0;
if (l/B==r/B) {
for (int i = l; i <= r; i++) ans += max(A[i]-x,0);
} else {
for (int i = l; i/B == l/B; i++) ans += max(A[i]-x,0);
for (int i = l/B+1; i < r/B; i++) {
auto it = bucket[i].upper_bound(x);
if (it==bucket[i].begin()) {
ans += S[i][B] - ll(x)*B;
} else {
--it;
ans += S[i][B] - S[i][it->second] - ll(x)*(B - it->second);
}
}
for (int i = r/B*B; i <= r; i++) ans += max(A[i]-x,0);
}
cout << ans << ln;
}
}
minato