結果

問題 No.880 Yet Another Segment Tree Problem
ユーザー ecotteaecottea
提出日時 2022-06-19 20:49:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 14,500 bytes
コンパイル時間 4,216 ms
コンパイル使用メモリ 236,960 KB
実行使用メモリ 26,112 KB
最終ジャッジ日時 2024-10-12 00:02:28
合計ジャッジ時間 30,170 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 4 ms
6,816 KB
testcase_02 WA -
testcase_03 AC 5 ms
6,820 KB
testcase_04 AC 4 ms
6,816 KB
testcase_05 AC 3 ms
6,820 KB
testcase_06 AC 3 ms
6,820 KB
testcase_07 AC 4 ms
6,816 KB
testcase_08 WA -
testcase_09 AC 5 ms
6,816 KB
testcase_10 AC 4 ms
6,816 KB
testcase_11 AC 1,022 ms
18,376 KB
testcase_12 AC 991 ms
18,596 KB
testcase_13 AC 708 ms
18,348 KB
testcase_14 AC 980 ms
19,172 KB
testcase_15 AC 1,043 ms
19,316 KB
testcase_16 AC 1,109 ms
19,220 KB
testcase_17 AC 1,278 ms
19,280 KB
testcase_18 AC 1,262 ms
19,380 KB
testcase_19 AC 572 ms
19,192 KB
testcase_20 AC 589 ms
19,248 KB
testcase_21 AC 596 ms
19,068 KB
testcase_22 AC 576 ms
19,272 KB
testcase_23 AC 613 ms
19,216 KB
testcase_24 WA -
testcase_25 AC 533 ms
19,408 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 954 ms
19,220 KB
testcase_30 AC 1,003 ms
19,232 KB
testcase_31 AC 1,083 ms
19,272 KB
testcase_32 AC 197 ms
19,476 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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

#ifndef HIDDEN_IN_VS //
//
#define _CRT_SECURE_NO_WARNINGS
//
#include <bits/stdc++.h>
using namespace std;
//
using ll = long long; // -2^63 2^63 = 9 * 10^18int -2^31 2^31 = 2 * 10^9
using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;
//
const double PI = acos(-1);
const vi DX = { 1, 0, -1, 0 }; // 4
const vi DY = { 0, 1, 0, -1 };
const int INF = 1001001001; const ll INFL = 4004004004004004004LL;
const double EPS = 1e-12; // 調
//
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;
//
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define YES(b) {cout << ((b) ? "YES\n" : "NO\n");}
#define rep(i, n) for(int i = 0, i##_len = ll(n); i < i##_len; ++i) // 0 n-1
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s t
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s t
#define repe(v, a) for(const auto& v : (a)) // a
#define repea(v, a) for(auto& v : (a)) // a
#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} //
#define EXIT(a) {cout << (a) << endl; exit(0);} //
//
template <class T> inline ll pow(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // true
    
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // true
    
//
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }
// Visual Studio
#ifdef _MSC_VER
#include "local.hpp"
// gcc
#else
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
#define gcd __gcd
#define dump(...)
#define dumpel(v)
#define input_from_file(f)
#define output_to_file(f)
#endif
#endif //
//--------------AtCoder --------------
#include <atcoder/all>
using namespace atcoder;
//using mint = modint1000000007;
using mint = modint998244353;
//using mint = modint; // mint::set_mod(m);
istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;
//----------------------------------------
//Segment tree beats!
/*
* Lazy_segtree<S, op, e, F, act, comp, id, fail>(int n) : O(n)
* v[0..n) = e()
* (S, op, e, F, act, comp, id, fail)
*
* Lazy_segtree<S, op, e, F, act, comp, id, fail>(vS v) : O(n)
* v[0..n)
*
* set(int i, S x) : O(α log n)
* v[i] = x
*
* S get(int i) : O(α log n)
* v[i]
*
* S prod(int l, int r) : O(α log n)
* Πv[l..r) e()
*
* apply(int i, F f) : O(α log n)
* v[i] = f( v[i] )
*
* apply(int l, int r, F f) : O(α log n)
* v[l..r) = f( v[l..r) )
*
* int max_right(int l, function<bool(S)> g) : O(α log n)
* g( Πv[l..r) ) = true r
* g( e() ) = true g 調
*
* int min_left(int r, function<bool(S)> g) : O(α log n)
* g( Πv[l..r) ) = true l
* g( e() ) = true g 調
*/
template <class S, S(*op)(S, S), S(*e)(),
class F, S(*act)(F, S), F(*comp)(F, F), F(*id)(), S(*fail)()>
class Segtree_beats {
// : https://rsm9.hatenablog.com/entry/2021/02/01/220408
int n; // 2
int actual_n; //
// 2 * n v[0] 使
// v[1] v[i] v[i / 2] v[2 * i], v[2 * i + 1]
// 0-indexed i v[i + n]
vector<S> v;
//
vector<F> lazy;
// O(1)
void eval(int k) {
//
if (lazy[k] == id()) return;
//
if (k < n) {
//
lazy[k * 2] = comp(lazy[k], lazy[k * 2]);
lazy[k * 2 + 1] = comp(lazy[k], lazy[k * 2 + 1]);
}
//
v[k] = act(lazy[k], v[k]);
lazy[k] = id();
//
if (v[k] == fail()) {
eval(k * 2);
eval(k * 2 + 1);
v[k] = op(v[k * 2], v[k * 2 + 1]);
}
}
// k : [kl..kr) : v[k]
void set_sub(int i, S x, int k, int kl, int kr) {
//
eval(k);
//
if (kr <= i || i < kl) return;
//
if (kl == i && kr == i + 1) {
v[k] = x;
return;
}
//
set_sub(i, x, k * 2, kl, (kl + kr) / 2);
set_sub(i, x, k * 2 + 1, (kl + kr) / 2, kr);
v[k] = op(v[k * 2], v[k * 2 + 1]);
}
// k : [kl..kr) : v[k]
S prod_sub(int l, int r, int k, int kl, int kr) {
//
eval(k);
// e()
if (kr <= l || r <= kl) return e();
//
if (l <= kl && kr <= r) return v[k];
//
S vl = prod_sub(l, r, k * 2, kl, (kl + kr) / 2);
S vr = prod_sub(l, r, k * 2 + 1, (kl + kr) / 2, kr);
return op(vl, vr);
}
// k : [kl, kr) : v[k]
void apply_sub(int l, int r, F f, int k, int kl, int kr) {
//
eval(k);
//
if (kr <= l || r <= kl) return;
//
if (l <= kl && kr <= r) {
//
lazy[k] = comp(f, lazy[k]);
eval(k);
return;
}
//
apply_sub(l, r, f, k * 2, kl, (kl + kr) / 2);
apply_sub(l, r, f, k * 2 + 1, (kl + kr) / 2, kr);
v[k] = op(v[k * 2], v[k * 2 + 1]);
}
// k : [kl..kr) : v[k]
int max_right_sub(int l, int r, S& x, int k, int kl, int kr, const function<bool(S)>& g) {
//
eval(k);
//
if (kr <= l || r <= kl) return r;
// g( op( v[kl, kr) ) ) = true
if (g(op(x, v[k]))) {
x = op(x, v[k]);
return r;
}
//
if (k >= n) return k - n;
//
int pos = max_right_sub(l, r, x, k * 2, kl, (kl + kr) / 2, g);
if (pos != r) return pos;
//
return max_right_sub(l, r, x, k * 2 + 1, (kl + kr) / 2, kr, g);
}
// k : [kl..kr) : v[k]
int min_left_sub(int l, int r, S& x, int k, int kl, int kr, const function<bool(S)>& g) {
//
eval(k);
//
if (kr <= l || r <= kl) return l - 1;
// g( op( v[kl, kr) ) ) = true
if (g(op(v[k], x))) {
x = op(v[k], x);
return l - 1;
}
//
if (k >= n) return k - n;
//
int pos = min_left_sub(l, r, x, k * 2 + 1, (kl + kr) / 2, kr, g);
if (pos != l - 1) return pos;
//
return min_left_sub(l, r, x, k * 2, kl, (kl + kr) / 2, g);
}
public:
// v[0..n) = e()
Segtree_beats(int n_) : actual_n(n_) {
// 2 n
int pow2 = 1;
while (pow2 < n_) pow2 *= 2;
n = pow2;
// 2 * n
v = vector<S>(2 * n, e());
lazy = vector<F>(2 * n, id());
}
// v[0..n)
Segtree_beats(vector<S>& v_) : Segtree_beats(sz(v_)) {
// verify : https://atcoder.jp/contests/abc256/tasks/abc256_h
//
rep(i, sz(v_)) v[i + n] = v_[i];
//
repir(i, n - 1, 1) v[i] = op(v[i * 2], v[i * 2 + 1]);
}
Segtree_beats() : n(0), actual_n(0) {} //
// v[i] = x
void set(int i, S x) {
set_sub(i, x, 1, 0, n);
}
// v[i]
S get(int i) {
return prod(i, i + 1);
}
// op( v[l..r) ) e()
S prod(int l, int r) {
// verify : https://atcoder.jp/contests/abc256/tasks/abc256_h
return prod_sub(l, r, 1, 0, n);
}
// v[i] = f( v[i] )
void apply(int i, F f) {
apply(i, i + 1, f);
}
// v[l..r) = f( v[l..r) )
void apply(int l, int r, F f) {
// verify : https://atcoder.jp/contests/abc256/tasks/abc256_h
apply_sub(l, r, f, 1, 0, n);
}
// g( op( v[l..r) ) ) = true r
int max_right(int l, const function<bool(S)>& g) {
S x = e();
return max_right_sub(l, actual_n, x, 1, 0, n, g);
}
// g( op( v[l..r) ) ) = true l
int min_left(int r, const function<bool(S)>& g) {
S x = e();
return min_left_sub(0, r, x, 1, 0, n, g) + 1;
}
#ifdef _MSC_VER
friend ostream& operator<<(ostream& os, Segtree_beats seg) {
rep(i, seg.actual_n) os << seg.get(i) << " ";
return os;
}
#endif
};
//GCD, max,
/*
* S ∋ x = {s, m, g, c, b} :
* c sGCD g mc b = true
* F ∋ f : f >= 0 f(x) = gcd(x, f) GCD
* f < 0 f(x) = -f
*/
struct SA02 {
ll s, m, g, c; bool b;
bool operator==(const SA02& y) const { return s == y.s && m == y.m && c == y.c && b == y.b; }
#ifdef _MSC_VER
friend ostream& operator<<(ostream& os, SA02 s) {
os << "(" << s.s << "," << s.m << "," << s.g << "," << s.c << "," << s.b << ")";
return os;
}
#endif
};
using FA02 = ll;
SA02 failA02() { return SA02{ -1, -1, -1, -1, false }; }
SA02 opA02(SA02 x, SA02 y) {
bool b = (x.c == 0 || y.c == 0 || (x.b && y.b && x.m == y.m));
return SA02{ x.s + y.s, max(x.m, y.m), gcd(x.m, y.m), x.c + y.c, b };
}
SA02 eA02() { return SA02{ 0, -INFL, 0, 0, true }; }
SA02 actA02(FA02 f, SA02 x) {
if (f == 0 || x.c == 0) return x;
if (f < 0) return SA02{ -f * x.c, -f, -f, x.c, true };
if (x.g % f == 0) return SA02{ f * x.c, f, f, x.c, true };
if (x.b) { ll g = gcd(x.m, f); return SA02{ g * x.c, g, gcd(g, f), x.c, true }; }
return failA02();
}
FA02 compA02(FA02 f, FA02 g) {
if (f < 0 || g == 0) return f;
if (f == 0) return g;
if (g < 0) return -gcd(f, -g);
return gcd(f, g);
}
FA02 idA02() { return 0; }
#define GCDUp_MaxAdd_iamonoid SA02, opA02, eA02, FA02, actA02, compA02, idA02, failA02
int main() {
// input_from_file("input.txt");
// output_to_file("output.txt");
int n, q;
cin >> n >> q;
vector<SA02> a(n);
rep(i, n) {
ll av;
cin >> av;
a[i] = SA02{av, av, av, 1, true};
}
Segtree_beats<GCDUp_MaxAdd_iamonoid> seg(a);
rep(i, q) {
int t;
cin >> t;
if (t == 1) {
int l, r; ll x;
cin >> l >> r >> x;
l--;
seg.apply(l, r, -x);
}
else if (t == 2) {
int l, r; ll x;
cin >> l >> r >> x;
l--;
seg.apply(l, r, x);
}
else if (t == 3) {
int l, r;
cin >> l >> r;
l--;
cout << seg.prod(l, r).m << endl;
}
else if (t == 4) {
int l, r;
cin >> l >> r;
l--;
cout << seg.prod(l, r).s << endl;
}
dump(seg);
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0