結果
| 問題 |
No.876 Range Compress Query
|
| コンテスト | |
| ユーザー |
rokahikou1
|
| 提出日時 | 2021-02-16 21:31:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,463 bytes |
| コンパイル時間 | 1,742 ms |
| コンパイル使用メモリ | 175,768 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 10:56:04 |
| 合計ジャッジ時間 | 4,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 16 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define DOUBLE(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define STRING(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
int to;
T cost;
edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
for(auto &a : v)
read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }
/* SegmentTree(0-indexed) */
template <class Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
const F f;
const Monoid e;
int n;
vector<Monoid> dat;
SegmentTree(int _n, const F _f, const Monoid &_e) : f(_f), e(_e) {
n = 1;
while(n < _n)
n *= 2;
dat.assign(2 * n, e);
}
SegmentTree(vector<Monoid> v, const F _f, const Monoid &_e) : f(_f), e(_e) {
int sz = v.size();
n = 1;
while(n < sz)
n *= 2;
dat.resize(2 * n);
for(int i = 0; i < sz; i++)
set(i, v[i]);
build();
}
void set(int k, Monoid a) { dat[k + n] = a; }
void build() {
for(int i = n - 1; i > 0; i--) {
dat[i] = f(dat[2 * i], dat[2 * i + 1]);
}
}
void update(int k, const Monoid &a) {
k += n;
dat[k] = a;
while(k >>= 1) {
dat[k] = f(dat[k * 2], dat[k * 2 + 1]);
}
}
Monoid at(int a) { return query(a, a + 1); }
// query for [a,b)
Monoid query(int a, int b) {
Monoid vl = e, vr = e;
a += n, b += n;
for(; a < b; a >>= 1, b >>= 1) {
if(a & 1)
vl = f(vl, dat[a++]);
if(b & 1)
vr = f(dat[--b], vr);
}
return f(vl, vr);
}
};
// Range min Query
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4865222
// template <class Monoid> struct RminQ : SegmentTree<Monoid> {
// static auto f(Monoid a, Monoid b) { return min(a, b); }
// RminQ(int n, const Monoid &e = numeric_limits<Monoid>::max())
// : SegmentTree<Monoid>(n, f, e) {}
// RminQ(vector<Monoid> v, const Monoid &e = numeric_limits<Monoid>::max())
// : SegmentTree<Monoid>(v, f, e) {}
// };
// // Range sum Query
// // https://judge.yosupo.jp/submission/24445
// template <class Monoid> struct RsumQ : SegmentTree<Monoid> {
// static auto f(Monoid a, Monoid b) { return a + b; }
// RsumQ(int n, const Monoid &e = 0) : SegmentTree<Monoid>(n, f, e) {}
// RsumQ(vector<Monoid> v, const Monoid &e = 0)
// : SegmentTree<Monoid>(v, f, e) {}
// };
using S = int;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
INT(n, q);
VEC(ll, a, n);
vector<ll> b;
b.push_back(INF);
for(int i = 0; i < n - 1; i++) {
b.push_back(a[i + 1] - a[i]);
}
b.push_back(INF);
auto op = [](S a, S b) { return a + b; };
S e = 0;
SegmentTree<S> segtree(n + 1, op, e);
rep(i, n + 1) {
if(b[i] != 0)
segtree.set(i, 1);
}
segtree.build();
rep(i, q) {
INT(qq);
if(qq == 1) {
INT(l, r, x);
l--;
b[l] += x;
b[r] -= x;
segtree.update(l, b[l] != 0);
segtree.update(r, b[r] != 0);
} else {
INT(l, r);
l--;
cout << segtree.query(l, r) << endl;
}
}
}
rokahikou1