Language: C++

#include <iostream>
#include <vector>
using namespace std;
//
struct segtree{
	//
	int n;
	vector<longlong> dat,laz;
	//
	segtree(int n_){
		init(n_);
	}
	//
	void init(int n_){
		n=1;
		while(n<n_){
			n*=2;
		}
		dat.resize(2*n-1,0);
		laz.resize(2*n-1,0);
	}
	//
	void eval(int l,int k){
		if(k*2+1<n*2-1){
			laz[k*2+1]+=laz[k];
			laz[k*2+2]+=laz[k];
		}
		dat[k]+=laz[k]*l;
		laz[k]=0;
	}
	//[a,b)
	int update(int a,int b,int x,int k=0,int l=0,int r=-1){
		if(r==-1){
			r=n;
		}
		eval(r-l,k);
		if(r<=a||b<=l){
			return dat[k]+laz[k]*(r-l);
		}else if(a<=l&&r<=b){
			return dat[k]+(laz[k]+=x)*(r-l);
		}else{
			eval(r-l,k);
			int va=update(a,b,x,k*2+1,l,(l+r)/2);
			int vb=update(a,b,x,k*2+2,(l+r)/2,r);
			return dat[k]=va+vb;
		}
	}
	//[a,b)
	int query(int a,int b,int k=0,int l=0,int r=-1){
		if(r==-1){
			r=n;
		}
		eval(r-l,k);
		if(r<=a||b<=l){
			return 0;
		}else if(a<=l&&r<=b){
			return dat[k];
		}else{
			int va=query(a,b,k*2+1,l,(l+r)/2);
			int vb=query(a,b,k*2+2,(l+r)/2,r);
			return va+vb;
		}
	}
	//
};
int main(){
	int N,Q;
	cin>>N>>Q;
	segtree seg(N);
	while(Q--){
		int C;
		cin>>C;
		if(C==1){
			int S,T;
			cin>>S>>T;
			S--;T--;
			cout<<seg.query(S,T+1)<<endl;
		}else{
			int S,T,X;
			cin>>S>>T>>X;
			S--;T--;
			seg.update(S,T+1,X);
		}
	}
	return 0;
}


Compiler output:
a.cc:8:16: error: 'longlong' was not declared in this scope
    8 |         vector<longlong> dat,laz;
      |                ^~~~~~~~
a.cc:8:24: error: template argument 1 is invalid
    8 |         vector<longlong> dat,laz;
      |                        ^
a.cc:8:24: error: template argument 2 is invalid
a.cc: In member function 'void segtree::init(int)':
a.cc:19:21: error: request for member 'resize' in '((segtree*)this)->segtree::dat', which is of non-class type 'int'
   19 |                 dat.resize(2*n-1,0);
      |                     ^~~~~~
a.cc:20:21: error: request for member 'resize' in '((segtree*)this)->segtree::laz', which is of non-class type 'int'
   20 |                 laz.resize(2*n-1,0);
      |                     ^~~~~~
a.cc: In member function 'void segtree::eval(int, int)':
a.cc:25:28: error: invalid types 'int[int]' for array subscript
   25 |                         laz[k*2+1]+=laz[k];
      |                            ^
a.cc:25:40: error: invalid types 'int[int]' for array subscript
   25 |                         laz[k*2+1]+=laz[k];
      |                                        ^
a.cc:26:28: error: invalid types 'int[int]' for array subscript
   26 |                         laz[k*2+2]+=laz[k];
      |                            ^
a.cc:26:40: error: invalid types 'int[int]' for array subscript
   26 |                         laz[k*2+2]+=laz[k];
      |                                        ^
a.cc:28:20: error: invalid types 'int[int]' for array subscript
   28 |                 dat[k]+=laz[k]*l;
      |                    ^
a.cc:28:28: error: invalid types 'int[int]' for array subscript
   28 |                 dat[k]+=laz[k]*l;
      |                            ^
a.cc:29:20: error: invalid types 'int[int]' for array subscript
   29 |                 laz[k]=0;
      |                    ^
a.cc: In member function 'int segtree::update(int, int, int, int, int, int)':
a.cc:38:35: error: invalid types 'int[int]' for array subscript
   38 |                         return dat[k]+laz[k]*(r-l);
      |                                   ^
a.cc:38:42: error: invalid types 'int[int]' for array subscript
   38 |                         return dat[k]+laz[k]*(r-l);
      |                                          ^
a.cc:40:35: error: invalid types 'int[int]' for array subscript
   40 |                         return dat[k]+(laz[k]+=x)*(r-l);
      |                                   ^
a.cc:40:43: error: invalid types 'int[int]' for array subscript
   40 |                         return dat[k]+(laz[k]+=x)*(r-l);
      |                                           ^
a.cc:45:35: error: invalid types 'int[int]' for array subscript
   45 |                         return dat[k]=va+vb;
      |                                   ^
a.cc: In member function 'int segtree::query(int, int, int, int, int)':
a.cc:57:35: error: invalid types 'int[int]' for array subscript
   57 |                         return dat[k];
      |                                   ^