#include #define ll long long int #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; //note x>0 struct node { ll val; int pos; int l; int r; }; bool comp(node a,node b) { if(a.val==b.val) { return a.l>b.l; } else { return a.val0){ ans=ans+bit[x]; x-=(x & (-x)); } return ans; } ll rsum(int l,int r) { return pref(r)-pref(l-1); } ll bit1[N]; void upd1(int x,ll val){ while(x<=n) { bit1[x]+=val; x+=(x & (-x)); } } ll pref1(ll x) { ll ans=0; while(x>0){ ans=ans+bit1[x]; x-=(x & (-x)); } return ans; } ll rsum1(int l,int r) { return pref1(r)-pref1(l-1); } int main() { fast; int i,j,q; cin>>n>>q; node a[n+q]; ll p[n+1]={0}; for(i=0;i>x; p[i+1]=p[i]+x; a[i].val=x; a[i].pos=-1; a[i].l=0; a[i].r=i+1; } for(i=0;i>t; ll l,r,x; cin>>l>>r>>x; a[i+n].val=x; a[i+n].pos=i; a[i+n].l=l; a[i+n].r=r; } sort(a,a+n+q,comp); ll ans[q]; for(i=0;i