#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
long long array[10005];
int main()
{
long long i, j, k;
long long test, n, u, qur, last, first, value, index;
scanf("%lld", &test);
while(test--)
{
scanf("%lld%lld", &n, &u);
for(i=0; i<n; i++)
{
array[i]=0;
}
while(u--)
{
scanf("%lld%lld%lld", &first, &last, &value);
array[first]+=value;
array[last+1]-=value;
}
for(i=1; i<n; i++)
{
array[i] += array[i-1];
}
scanf("%lld", &qur);
while(qur--)
{
scanf("%lld", &index);
printf("%lld\n", array[index]);
}
}
return 0;
}
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
long long array[10005];
int main()
{
long long i, j, k;
long long test, n, u, qur, last, first, value, index;
scanf("%lld", &test);
while(test--)
{
scanf("%lld%lld", &n, &u);
for(i=0; i<n; i++)
{
array[i]=0;
}
while(u--)
{
scanf("%lld%lld%lld", &first, &last, &value);
array[first]+=value;
array[last+1]-=value;
}
for(i=1; i<n; i++)
{
array[i] += array[i-1];
}
scanf("%lld", &qur);
while(qur--)
{
scanf("%lld", &index);
printf("%lld\n", array[index]);
}
}
return 0;
}
Awesome solution and it was a bit humiliating.How did you come up with this when segment and bit trees are the usual ways to solve?
ReplyDeletecan you explain me why this method works ?
ReplyDelete