#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using Pll = pair; using Pii = pair; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = { { 0, 1}, {-1, 0}, {0,-1}, {1, 0} }; const int MAX_N = 100000; template class RSQ { public: int n, m; T zero = 0; T data[4*MAX_N]; T values[4*MAX_N]; RSQ(int m, T init_value=0): m(m) { // 2のべき乗にする n = 1; while(n < m) n <<= 1; zero = init_value; for(int i=0;i<2*n-1;++i){ data[i] = init_value; values[i] = init_value; } } void bottom_up_update(int i) { while(i){ i = (i-1)/2; data[i] = data[2*i+1] + data[2*i+2]; } } void update(int s, int t, T x){ s += n-1; t += n-1; if(s > n-1) values[s-1] += x; data[s-1] = values[s-1]?1:0; if(t > n-1) values[t-1] -= x; data[t-1] = values[t-1]?1:0; bottom_up_update(s-1); bottom_up_update(t-1); // for(int i=0;i<2*n-1;++i) { // cerr << data[i] << " "; // } // cerr << endl; // for(int i=n-1;i<2*n-1;++i) { // cerr << values[i] << " "; // } // cerr << endl; } // [s, t) T find(int s, int t, int k, int kl, int kr){ if(kr <= s || t <= kl) return zero; if(s <= kl && kr <= t) return data[k]; int kc = (kl+kr)/2; T vl = find(s, t, 2*k+1, kl, kc); T vr = find(s, t, 2*k+2, kc, kr); return vl + vr; } T find(int s, int t) { return find(s, t, 0, 0, n); } }; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int n, q, query, l, r; ll a; cin >> n >> q; RSQ tree(n); for(int i=0;i> a; tree.update(i, i+1, a); } for(int i=0;i> query >> l >> r; --l; --r; if(query == 1) { cin >> a; tree.update(l, r+1, a); } else { cout << tree.find(l, r) + 1 << endl; } } }