結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2025-04-28 04:26:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,569 bytes |
| コンパイル時間 | 3,633 ms |
| コンパイル使用メモリ | 286,020 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-28 04:26:43 |
| 合計ジャッジ時間 | 4,623 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define IO ios::sync_with_stdio(false),cin.tie(nullptr);
#define LB(v, x) (ll)(lower_bound(ALL(v),x)-(v).begin())
#define UQ(v) sort(ALL(v)),(v).erase(unique(ALL(v)),v.end())
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i, a, b) for(ll i=(ll)(a); (a)<(b) ? i<(b) : i>(b); i+=((a)<(b) ? 1 : -1))
#define chmax(a, b) ((a)<(b) ? ((a)=(b), 1) : 0)
#define chmin(a, b) ((a)>(b) ? ((a)=(b), 1) : 0)
template<typename T> using rpriority_queue=priority_queue<T,vector<T>,greater<T>>;
using ll=long long; const int INF=1e9+10; const ll INFL=4e18;
using ld=long double; using ull=uint64_t; using LL=__int128_t;
using VI=vector<int>; using VVI=vector<VI>; using VL=vector<ll>; using VVL=vector<VL>;
using PL=pair<ll,ll>; using VP=vector<PL>; using WG=vector<vector<pair<int,ll>>>;
template<typename Monoid>
struct SegTreeDyanamic {
using Type=typename Monoid::Type;
struct Node {
Type value;
array<int,2> to;
ll left,right;
Node(ll l, ll r) {
to.fill(-1);
left=l; right=r;
}
};
vector<Node> node;
ll mx=1e9;
vector<int> route;
SegTreeDyanamic(ll mx=1e9, int q=5e5) {
this->mx=mx;
node.reserve(q);
node.push_back(Node(0,mx));
route.reserve(100);
}
void set(ll i, Type v) {
ll left=0,right=mx,cur=0;
route.clear();
while(left<right-1) {
ll mid=(left+right)/2;
int nxt,toi;
if(i<mid) nxt=node[cur].to[0],toi=0; //左
else nxt=node[cur].to[1],toi=1; //右
if(nxt==-1) {
nxt=node.size();
node[cur].to[toi]=nxt;
if(toi==0) node.push_back(Node(left,mid));
else node.push_back(Node(mid,right));
}
if(i<mid) right=mid;
else left=mid;
route.push_back(cur);
cur=nxt;
}
reverse(ALL(route));
node[cur].value=v;
for(int r:route) {
int leftc=node[r].to[0],rightc=node[r].to[1];
Type leftv= leftc==-1 ? Monoid::id() : node[leftc].value;
Type rightv= rightc==-1 ? Monoid::id() : node[rightc].value;
node[r].value=Monoid::op(leftv,rightv);
}
}
Type fold(ll l, ll r) {
auto dfs=[&](auto&& dfs, int idx, ll left, ll right)-> Type {
if(right<l) return Monoid::id();
if(left>r) return Monoid::id();
if(l<=left&&right<=r) return node[idx].value;
ll mid=(left+right)/2;
int leftc=node[idx].to[0],rightc=node[idx].to[1];
Type leftv,rightv;
if(leftc==-1) leftv=Monoid::id();
else leftv=dfs(dfs,leftc,left,mid);
if(rightc==-1) rightv=Monoid::id();
else rightv=dfs(dfs,rightc,mid,right);
return Monoid::op(leftv,rightv);
};
return dfs(dfs,0,0,mx);
}
};
/// @brief ModInt
template<ll MOD>
struct ModInt{
ModInt(ll x=0){ value=(x>=0?x%MOD:MOD-(-x)%MOD); }
ModInt operator-() const { return ModInt(-value); }
ModInt operator+() const { return ModInt(*this); }
ModInt& operator+=(const ModInt& other) {
value+=other.value;
if(value>=MOD) value-=MOD;
return*this;
}
ModInt& operator-=(const ModInt& other) {
value+=MOD-other.value;
if(value>=MOD) value-=MOD;
return*this;
}
ModInt& operator*=(const ModInt other) {
value=value*other.value%MOD;
return*this;
}
ModInt& operator/=(ModInt other) {
(*this)*=other.inv();
return*this;
}
ModInt operator+(const ModInt& other) const { return ModInt(*this)+=other; }
ModInt operator-(const ModInt& other) const { return ModInt(*this)-=other; }
ModInt operator*(const ModInt& other) const { return ModInt(*this)*=other; }
ModInt operator/(const ModInt& other) const { return ModInt(*this)/=other; }
bool operator==(const ModInt& other) const { return value==other.value; }
bool operator!=(const ModInt& other) const { return value!=other.value; }
friend ostream& operator<<(ostream& os, const ModInt& x) { return os<<x.value; }
friend istream& operator>>(istream& is, ModInt& x) {
ll v;
is>>v;
x=ModInt<MOD>(v);
return is;
}
ModInt pow(ll x) const {
ModInt ret(1),mul(value);
while(x) {
if(x&1) ret*=mul;
mul*=mul;
x>>=1;
}
return ret;
}
ModInt inv() const { return pow(MOD-2); }
ll val() {return value; }
static constexpr ll get_mod() { return MOD; }
private:
ll value;
};
using Mod998=ModInt<998244353>;
using Mod107=ModInt<1000000007>;
using VM=vector<Mod998>;
using mint=Mod998;
//----------------------------------------------------------
struct Mon {
using Type=pair<mint,mint>;
static Type op(Type l, Type r) {
l.first=l.first*r.first;
l.second=r.first*l.second+r.second;
return l;
}
static Type id() { return { mint(1), mint(0) }; }
};
int main() {
IO;
ll N,Q; cin>>N>>Q;
SegTreeDyanamic<Mon> seg(N);
while(Q--) {
int t; cin>>t;
if(t==0) {
ll p,c,d; cin>>p>>c>>d;
seg.set(p,{c,d});
}
else {
ll l,r,x; cin>>l>>r>>x;
auto [a,b]=seg.fold(l,r);
mint ans=a*x+b;
cout<<ans<<'\n';
}
}
}
Today03