-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHORRIBLE.cpp
More file actions
84 lines (83 loc) · 1.61 KB
/
HORRIBLE.cpp
File metadata and controls
84 lines (83 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define RFOR(i,a,b) for(ll i=a;i>=b;--i)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define sz(a) ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
typedef long long ll;
typedef long double ld;
map<ll,ll> counter;
ll arr[200002],seg[800010],lazy[800010];
void lazyupdate(ll s,ll e,ll index)
{
if(lazy[index])
{
seg[index]+=(e-s+1)*lazy[index];
if(s!=e)
{
lazy[index<<1]+=lazy[index];
lazy[(index<<1)+1]+=lazy[index];
}
lazy[index]=0;
}
return;
}
ll query(ll s,ll e,ll l,ll r,ll index)
{
lazyupdate(s,e,index);
if(e<l || s>r )return 0;
if(s>=l && e<=r)
return seg[index];
ll q1,q2,mid=(s+e)/2;
q1=query(s,mid,l,r,index<<1);
q2=query(mid+1,e,l,r,(index<<1)+1);
return (q1+q2);
}
void update(ll s,ll e,ll index,ll start,ll end,ll upd)
{
lazyupdate(s,e,index);
if(end<s||start>e || s>e)return;
if(start<=s && end>=e)
{
seg[index]+=(e-s+1)*upd;
if(s!=e)
{
lazy[index<<1]+=upd;
lazy[(index<<1)+1]+=upd;
}
return;
}
ll mid=(s+e)/2;
update(s,mid,index<<1,start,end,upd);
update(mid+1,e,(index<<1)+1,start,end,upd);
seg[index]=(seg[index<<1]+seg[(index<<1)+1]);
return;
}
int main()
{
ll m,n,type,t,c,v,p,q;
cin>>t;
while(t--)
{
FOR(i,1,600020)seg[i]=0,lazy[i]=0;
cin>>n>>c;
while(c--)
{
cin>>type>>p>>q;
if(type)
cout<<query(1,n,p,q,1)<<endl;
else
{
cin>>v;
update(1,n,1,p,q,v);
}
}
}
return 0;
}