xay loves sequence
题号:NC225186
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You are given an array of a of size n , . We define as the minimum number of operations to make .

In one operation, first you choose an interval , then you can choose either or .

has q queries: given l,r,k , you need to calculate .

输入描述:

The first line cointains n,q , denoting the length of the array a and the number of queries.

The second line contains n integers, denoting a_i .

In the next q lines, each line contains l,r,k .

It's guaranteed that  , and for every k,  .

输出描述:

For each queries, print  .
示例1

输入

复制
4 1
154376203 796925591 750050718 538329124 
1 4 977068593

输出

复制
593115672
示例2

输入

复制
6 2
1 1 4 5 1 4 
3 5 10
1 4 11

输出

复制
5
5