結果

問題 No.877 Range ReLU Query
ユーザー minatominato
提出日時 2020-05-26 20:13:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,456 bytes
コンパイル時間 4,647 ms
コンパイル使用メモリ 246,852 KB
実行使用メモリ 16,676 KB
最終ジャッジ日時 2024-04-21 04:32:12
合計ジャッジ時間 19,666 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,888 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,812 KB
testcase_04 AC 2 ms
6,812 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 844 ms
8,276 KB
testcase_12 AC 710 ms
8,064 KB
testcase_13 AC 464 ms
7,396 KB
testcase_14 AC 461 ms
6,944 KB
testcase_15 AC 1,083 ms
9,728 KB
testcase_16 AC 1,514 ms
9,340 KB
testcase_17 AC 1,608 ms
9,728 KB
testcase_18 AC 1,558 ms
9,728 KB
testcase_19 AC 1,900 ms
9,728 KB
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = 570;

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;
    }
}
0