結果

問題 No.877 Range ReLU Query
ユーザー tkmst201
提出日時 2019-09-06 23:09:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,596 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 177,112 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2024-06-24 21:06:17
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:119:28: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
  119 |         REP(i, Q) printf("%d\n", ans[i]);
      |                           ~^     ~~~~~~
      |                            |          |
      |                            int        ll {aka long long int}
      |                           %lld
main.cpp:88:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   88 |                 scanf("%d", &a);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//
struct SegTree {
int n;
vector<pll> dat, sum;
SegTree(int _n) {
n = 1;
while (n < _n) n *= 2;
dat.resize(n * 2 - 1, pll(INF, 0));
sum.resize(n * 2 - 1, pll(0, 0));
}
pll add(pll a, pll b) {
return pll(a.fi + b.fi, a.se + b.se);
}
void update(int pos, pll x) {
int i = pos + n - 1;
dat[i] = min(dat[i], x);
while (i > 0) {
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
i = pos + n - 1;
if (dat[i].se != -1) sum[i] = pll(x.fi, 1);
else sum[i] = pll(0, 0);
while (i > 0) {
i = (i - 1) / 2;
sum[i] = add(sum[i * 2 + 1], sum[i * 2 + 2]);
}
}
void set(int i, pll x) {
dat[i + n - 1] = x;
update(i, x);
}
pll sumquery(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
if (r <= a || b <= l) return pll(0, 0);
if (a <= l && r <= b) return sum[k];
return add(sumquery(a, b, k * 2 + 1, l, (l + r) / 2), sumquery(a, b, k * 2 + 2, (l + r) / 2, r));
}
// [a,b), k[l,r)
pll minquery(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0) r = n;
if (r <= a || b <= l) return pll(INF, 0);
if (a <= l && r <= b) return dat[k];
return min( minquery(a, b, k * 2 + 1, l, (l + r) / 2), minquery(a, b, k * 2 + 2, (l + r) / 2, r) );
}
};
int N, Q;
ll ans[112345];
int main() {
cin >> N >> Q;
SegTree seg(N);
REP(i, N) {
int a;
scanf("%d", &a);
seg.set(i, pll(a, i));
}
vector<P> v;
REP(i, Q) {
int q, l, r;
cin >> q >> l >> r;
l--; r--;
if (q == 1) {
int x; cin >> x;
v.push_back(P(pii(x, i), pii(l, r)));
}
}
sort(ALL(v));
REP(i, Q) {
int x = v[i].fi.fi;
int qidx = v[i].fi.se;
int l = v[i].se.fi;
int r = v[i].se.se + 1;
pll cur;
while ((cur = seg.minquery(0, N)).fi <= x) {
seg.set(cur.se, pll(INF, -1));
}
cur = seg.sumquery(l, r);
ans[qidx] = cur.fi - cur.se * x;
}
REP(i, Q) printf("%d\n", ans[i]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0