結果

問題 No.877 Range ReLU Query
ユーザー 👑 emthrmemthrm
提出日時 2019-09-06 21:59:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,512 ms / 2,000 ms
コード長 2,011 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 127,796 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 21:59:36
合計ジャッジ時間 9,655 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 478 ms
6,940 KB
testcase_12 AC 399 ms
6,940 KB
testcase_13 AC 288 ms
6,940 KB
testcase_14 AC 306 ms
6,940 KB
testcase_15 AC 605 ms
6,940 KB
testcase_16 AC 822 ms
6,940 KB
testcase_17 AC 814 ms
6,944 KB
testcase_18 AC 800 ms
6,940 KB
testcase_19 AC 930 ms
6,940 KB
testcase_20 AC 1,512 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  const int B = 316;
  int n, q; cin >> n >> q;
  int sz = (n + B - 1) / B;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<vector<int> > block(sz);
  REP(i, n) block[i / B].emplace_back(a[i]);
  vector<vector<long long> > rui(sz);
  REP(i, sz) {
    sort(ALL(block[i]));
    int szsz = block[i].size();
    REP(j, szsz) rui[i].emplace_back((j == 0 ? 0 : rui[i].back()) + block[i][j]);
  }
  while (q--) {
    int query, l, r; long long x; cin >> query >> l >> r >> x; --l; --r;
    int l_b = l / B, r_b = r / B;
    long long ans = 0;
    if (l_b == r_b) {
      FOR(i, l, r + 1) ans += max(a[i] - x, 0LL);
    } else {
      FOR(i, l, B * (l_b + 1)) ans += max(a[i] - x, 0LL);
      FOR(i, l_b + 1, r_b) {
        int sz = block[i].size();
        int idx = lower_bound(ALL(block[i]), x) - block[i].begin();
        int cnt = sz - idx;
        ans += rui[i][sz - 1] - (idx == 0 ? 0 : rui[i][idx - 1]) - x * cnt;
      }
      FOR(i, B * r_b, r + 1) ans += max(a[i] - x, 0LL);
    }
    cout << ans << '\n';
  }
  return 0;
}
0