Language: C++

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e5+10, maxm=2e3+10, lg=22, mod=998244353, inf=1e18;

#define lc (v<<1)
#define rc (lc^1)
#define mid ((s+t)>>1)

struct segment{
	set<pll> s;
	bool ispor(ll l,ll r){
		if(s.empty()) return 0;
		auto it=s.lower_bound({l,-inf});
		return (it->F)<=l && (it->S)>=r;
	}
	bool iskal(ll l,ll r){
		if(s.empty()) return 1;
		auto it=s.lower_bound({l,-inf});
		if((it->F)<r) return 0;
		if(it==s.begin()) return 1;
		it--;
		return (it->S)<l;
	}
	void add(ll l,ll r){
		auto it=s.lower_bound({l,inf});
		if(it!=s.end() && (it->S)<=r) return s.erase(it), add(l,r);
		if(it!=s.end() && (it->F)<=r) return r=it->S, s.erase(it), add(l,r);
		if(it!=s.begin()){
			it--;
			if((it->S)>=r) return;
			if((it->S)>=l) return l=it->F, s.erase(it), add(l,r);
		}
		s.insert({l,r});
	}
}c[maxn];
struct node{
	ll sum,t2,pl;
	node(ll sum=0,ll t2=0,ll pl=0):sum(sum),t2(t2),pl(pl){}
}seg[maxn<<2];

ll n,q,p2[maxn];

void app(ll s,ll t,ll v,ll a,ll b){
	seg[v].sum=(seg[v].sum*p2[a]+(t-s)*b)%mod;
	seg[v].t2+=a;
	seg[v].pl=(seg[v].pl*p2[a]+b)%mod;
}
void shift(ll s,ll t,ll v){
	app(s,mid,lc,seg[v].t2,seg[v].pl);
	app(mid,t,rc,seg[v].t2,seg[v].pl);
}
void add(ll l,ll r,ll x,ll s=0,ll t=n,ll v=1){
	if(l>=t || r<=s) return;
	bool por=c[x].ispor(l,r), kal=c[x].iskal(l,r);
	if(l<=s && r>=t && (por||kal)) return app(s,t,v,por,kal);
	shift(s,t,v);
	add(l,r,x,s,mid,lc);
	add(l,r,x,mid,t,rc);
	seg[v]=node((seg[lc].sum+seg[rc].sum)%mod,0,0);
}
ll get(ll l,ll r,ll s=0,ll t=n,ll v=1){
	if(l>=t || r<=s) return 0;
	if(l<=s && r>=t) return seg[v].sum;
	return (get(l,r,s,mid,lc)+get(l,r,mid,t,rc))%mod;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	p2[0]=1; for(int i=1;i<maxn;i++) p2[i]=p2[i-1]*2%mod;
	cin>>n>>q;
	for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
	while(q--){
		ll ty; cin>>ty;
		if(ty==1){
			ll l,r,x; cin>>l>>r>>x;
			add(--l,r,x);
			c[x].add(l,r);
		}
		else{
			ll l,r; cin>>l>>r;
			cout<<get(--l,r)<<'\n';
		}
	}
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:90:30: error: 'a' was not declared in this scope
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |                              ^
a.cc:90:38: error: 'sum' was not declared in this scope
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |                                      ^~~
a.cc:90:61: error: 'l' was not declared in this scope
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |                                                             ^
a.cc:90:65: error: 'r' was not declared in this scope
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |                                                                 ^
a.cc:90:68: error: 'upd' was not declared in this scope
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |                                                                    ^~~
a.cc:90:85: error: expected ')' before ';' token
   90 |         for(int i=0;i<n;cin>>a[++i],(sum+=a[i] ? a[n+i]=get(l++,r):upd(l,--r,p2[i]));
      |            ~                                                                        ^
      |                                                                                     )