import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] content = br.readLine().split(" ");
int mod = (int)1e9+7;
int len = Integer.parseInt(content[0]);
int cnt = Integer.parseInt(content[1]);
long[][] data = new long[len+10][6];
content = br.readLine().split(" ");
for(int i=1;i<=content.length;i++)
for(int j=1;j<=5;j++){
data[i][j] = (data[i-1][j]+(long)Math.pow(Integer.parseInt(content[i-1]),j))%mod;
}
while(cnt-->0){
content = br.readLine().split(" ");
int l = Integer.parseInt(content[0]);
int r = Integer.parseInt(content[1]);
int k = Integer.parseInt(content[2]);
// 相减会溢出
System.out.println((data[r][k]+mod-data[l-1][k])%mod);
}
br.close();
}
}
暂存 区间次方和
最新推荐文章于 2024-06-16 09:46:44 发布