#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 100005; const int maxm = 200010; const int maxt = 200010; const LL inf = (1LL<<60); struct node{ int u,v,kind; LL ind; bool operator < (node a)const{ if( u == a.u && v == a.v)return kind < a.kind; if( u == a.u)return v < a.v; return u > a.u; } }p[maxn+maxm+maxt]; LL s[maxn],res[maxt]; LL b[maxn]; int n; int lowbit(int x){ return x&(-x); } void update(int x,LL val){ while( x <= n){ b[x] = min(b[x],val); x += lowbit(x); } } LL query(int x){ LL res = inf; while( x ){ res = min(res,b[x]); x -= lowbit(x); } return res; } int main(){ int i,m; while(~scanf("%d %d",&n,&m)){ for( i = 2; i <= n; i++){ scanf("%lld",&s[i]); s[i] += s[i-1]; } for(i = 0; i < m; i++){ scanf("%d %d %lld",&p[i].u,&p[i].v,&p[i].ind); p[i].kind = 0; } int t;scanf("%d",&t); for( ; i < m+t; i ++){ scanf("%d %d",&p[i].u,&p[i].v); p[i].kind = 1;p[i].ind =i-m; } sort(p,p+m+t); // for(int i = 0; i < m+t; i++)cout << p[i].u << " " << p[i].v << " " << p[i].ind << " " << p[i].kind << endl; memset(b,0,sizeof(b)); memset(res,0,sizeof(res));//當u == v時距離爲0 for(int i = 0; i < m+t; i++){ if( p[i].kind == 0 && p[i].u < p[i].v) update(p[i].v, p[i].ind - (s[p[i].v] - s[p[i].u]) ); else if( p[i].kind == 1 && p[i].u < p[i].v) res[p[i].ind] = (s[p[i].v] - s[p[i].u]) + query(p[i].v); } for(int i = 0; i <= n+1;i++)b[i] = inf; for(int i = 0; i < m+t; i++){ if( p[i].kind == 0 && p[i].u > p[i].v) update(p[i].v,p[i].ind + (s[p[i].u] - s[p[i].v])); else if( p[i].kind == 1 && p[i].u > p[i].v){ // int ans = query(p[i].v);cout << ans << endl; res[p[i].ind] = query(p[i].v) - (s[p[i].u] - s[p[i].v]); } } for(int i = 0; i < t; i++) printf("%lld\n",res[i]); } return 0; } /* 5 3 1 2 3 4 2 4 2 1 3 2 5 1 3 5 1 4 4 2 3 1 1 3 1 5 */