传送门:http://oi.cdshishi.net:8000/problempage.php?problem_id=2138
水题++上代码
#include<bits/stdc++.h>
#define in read()
using namespace std;
int in{
int cnt=0,f=1;char ch=0;
while(!isdigit(ch)){
ch=getchar();
if(ch=='-')f=-1;
}
while(isdigit(ch)){
cnt=cnt*10+ch-48;
ch=getchar();
}
return cnt*f;
} int n,m;int d[10000003];
int lowbit(int x){
return x&(-x);
}
void update(int x,int k){
while(x<=n){
d[x]+=k;
x+=lowbit(x);
}
}
int query(int x){
int ans=0;
while(x>0){
ans+=d[x];
x-=lowbit(x);
}
return ans;
}
int main(){
n=in;m=in;
int x,y,z;
while(m--){
x=in;y=in;z=in;
update(x,z);update(y+1,-z);
}
m=in;
while(m--){
x=in;
printf("%d\n",query(x));
}
return 0;
}