problem statement is here
#include<stdio.h>
int main(){
long long a,b,c,w,x,y,z,q,i,t,n,ar[100007],br[100006],l;
scanf("%lld",&t);
while(t--){
ar[0]=0;br[0]=0;
scanf("%lld %lld",&n,&q);
for(i=1;i<=n;i++){
scanf("%lld",&l);
ar[i]=ar[i-1]+l;
br[i]=br[i-1]+(l*i);
// printf("%lld %lld\n",ar[i],br[i]);
}
while(q--){
scanf("%lld %lld %lld %lld",&w,&x,&y,&z);
a=(w-x)*(ar[x+z]-ar[x+y-1]);
b=br[x+z]-br[x+y-1];
c=a+b;
c%=1000000007;
printf("%lld\n",c);
}
}
return 0;
}
#include<stdio.h>
int main(){
long long a,b,c,w,x,y,z,q,i,t,n,ar[100007],br[100006],l;
scanf("%lld",&t);
while(t--){
ar[0]=0;br[0]=0;
scanf("%lld %lld",&n,&q);
for(i=1;i<=n;i++){
scanf("%lld",&l);
ar[i]=ar[i-1]+l;
br[i]=br[i-1]+(l*i);
// printf("%lld %lld\n",ar[i],br[i]);
}
while(q--){
scanf("%lld %lld %lld %lld",&w,&x,&y,&z);
a=(w-x)*(ar[x+z]-ar[x+y-1]);
b=br[x+z]-br[x+y-1];
c=a+b;
c%=1000000007;
printf("%lld\n",c);
}
}
return 0;
}
No comments:
Post a Comment