結果

問題 No.2395 区間二次変換一点取得
ユーザー erbowlerbowl
提出日時 2023-07-30 19:30:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 4,095 bytes
コンパイル時間 1,867 ms
コンパイル使用メモリ 210,156 KB
最終ジャッジ日時 2025-02-15 21:04:29
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Segment Tree
template<class Monoid, class Action> struct SegTree {
using FuncMonoid = function< Monoid(Monoid, Monoid) >;
using FuncAction = function< void(Monoid&, Action) >;
using FuncComposition = function< void(Action&, Action) >;
FuncMonoid FM;
FuncAction FA;
FuncComposition FC;
Monoid IDENTITY_MONOID;
Action IDENTITY_LAZY;
int SIZE, HEIGHT;
vector<Monoid> dat;
vector<Action> lazy;
SegTree() {}
SegTree(int n, const FuncMonoid fm, const FuncAction fa,
const FuncComposition fc,
const Monoid &identity_monoid, const Action &identity_lazy)
: FM(fm), FA(fa), FC(fc),
IDENTITY_MONOID(identity_monoid), IDENTITY_LAZY(identity_lazy) {
SIZE = 1, HEIGHT = 0;
while (SIZE < n) SIZE <<= 1, ++HEIGHT;
dat.assign(SIZE * 2, IDENTITY_MONOID);
lazy.assign(SIZE * 2, IDENTITY_LAZY);
}
void init(int n, const FuncMonoid fm, const FuncAction fa,
const FuncComposition fc,
const Monoid &identity_monoid, const Action &identity_lazy) {
FM = fm, FA = fa, FC = fc;
IDENTITY_MONOID = identity_monoid, IDENTITY_LAZY = identity_lazy;
SIZE = 1, HEIGHT = 0;
while (SIZE < n) SIZE <<= 1, ++HEIGHT;
dat.assign(SIZE * 2, IDENTITY_MONOID);
lazy.assign(SIZE * 2, IDENTITY_LAZY);
}
// set, a is 0-indexed
void set(int a, const Monoid &v) { dat[a + SIZE] = v; }
void build() {
for (int k = SIZE - 1; k > 0; --k)
dat[k] = FM(dat[k*2], dat[k*2+1]);
}
// update [a, b)
inline void evaluate(int k) {
if (lazy[k] == IDENTITY_LAZY) return;
if (k < SIZE) FC(lazy[k*2], lazy[k]), FC(lazy[k*2+1], lazy[k]);
FA(dat[k], lazy[k]);
lazy[k] = IDENTITY_LAZY;
}
inline void update(int a, int b, const Action &v, int k, int l, int r) {
evaluate(k);
if (a <= l && r <= b) FC(lazy[k], v), evaluate(k);
else if (a < r && l < b) {
update(a, b, v, k*2, l, (l+r)>>1);
update(a, b, v, k*2+1, (l+r)>>1, r);
dat[k] = FM(dat[k*2], dat[k*2+1]);
}
}
inline void update(int a, int b, const Action &v) {
update(a, b, v, 1, 0, SIZE);
}
// get [a, b)
inline Monoid get(int a, int b, int k, int l, int r) {
evaluate(k);
if (a <= l && r <= b)
return dat[k];
else if (a < r && l < b)
return FM(get(a, b, k*2, l, (l+r)>>1),
get(a, b, k*2+1, (l+r)>>1, r));
else
return IDENTITY_MONOID;
}
inline Monoid get(int a, int b) {
return get(a, b, 1, 0, SIZE);
}
inline Monoid operator [] (int a) {
return get(a, a + 1);
}
// debug
void print() {
for (int i = 0; i < SIZE; ++i) {
if (i) cout << ",";
cout << get(i, i+1);
}
cout << endl;
}
};
signed main(){
ll n,b,q;
std::cin >> n>>b>>q;
vector<tuple<ll,ll,ll>> memo(q+1);
vector<bool> done(q+1);
memo[0] = {1%b,1%b,1%b};
done[0] = true;
function<tuple<ll,ll,ll>(ll)> dfs = [&](ll cnt){
if(done[cnt]){
return memo[cnt];
}
done[cnt]=true;
auto [x,y,z] = dfs(cnt-1);
tuple<ll,ll,ll> tmp = {(x+1)%b, (3*y+2*(x+1)*z)%b, 3*z%b};
return memo[cnt] = tmp;
};
dfs(q);
// define segtree
auto fm = [&](ll a, ll b) {
return a+b;
};
auto fa = [&](ll &a, int d) {
if (d == 0) return;
a += d;
};
auto fc = [&](int &d, int e) {
d += e;
};
SegTree<ll, ll> seg(n+1, fm, fa, fc, 0, 0);
for (int i = 0; i < q; i++) {
ll l,m,r;
std::cin >> l>>m>>r;
seg.update(l,r+1, 1);
ll val = seg.get(m, m+1);
auto [x,y,z] = memo[val];
std::cout << x<<" "<<y<<" "<<z << std::endl;
}
};
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0