金泽的地图(区间更新+求区间内的和+用前缀和计算)
题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/4107.html
AC代码:
#include<iostream>
#include<cmath>
#include<stack>
#include<iomanip>
#include<queue>
#include<cstring>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
# define inf 0x3f3f3f3f
# define ll long long
const int maxn = 100000+100;
ll a[maxn];
int main()
{
ll n,m;
while(~scanf("%lld %lld",&n,&m))
{
memset(a,0,sizeof(a));
ll maxx=0;
ll t1,t2,t3;
for(int i=1; i<=n; i++)
{
scanf("%lld %lld %lld",&t1,&t2,&t3);
maxx=max(maxx,t2);
a[t1]+=t3;
a[t2+1]-=t3;
}
for(int i=1; i<=maxx; i++)
{
a[i]+=a[i-1];
}
for(int i=1; i<=maxx; i++)
{
a[i]+=a[i-1];
}
for(int i=1; i<=m; i++)
{
scanf("%d %d",&t1,&t2);
printf("%lld\n",a[t2]-a[t1-1]);
}
}
return 0;
}