#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define INF int(1e9)
using namespace std;
const int N = 6e5 + 7, M = N;
typedef long long LL;
int n, m, k;
struct Node{
// 1 insert // 2 query
int op;
int x1, y1, x2, y2, v;
// query_id
int id;
}q[N], lq[N], rq[N];
LL tr[M];
int ans[M];
vector<int> adj[N];
int require[N];
inline int lowbit(int x){
return x & -x;
}
inline void update(int x,int v){
for(int i = x;i <= m;i += lowbit(i))
tr[i] += v;
}
inline LL query(int x){
LL ans = 0;
for(int i = x;i;i -= lowbit(i))
ans += tr[i];
return ans;
}
void solve(int vl,int vr,int ql,int qr){
// cerr << vl << ' ' << vr << ' ' << ql << ' ' << qr << endl;
if(vl > vr || ql > qr) return ;
if(vl == vr){
for(int i = ql;i <= qr;i ++ )
if(q[i].op == 2)
ans[q[i].id] = vr;
return ;
}
int mid = vl + vr >> 1;
int nl = 0, nr = 0;
for(int i = ql;i <= qr;i ++ ){
// insert
if(q[i].op == 1){
if(q[i].id <= mid){
update(q[i].x1, q[i].v);
update(q[i].y1 + 1, -q[i].v);
if(q[i].x2){
update(q[i].x2, q[i].v);
update(q[i].y2 + 1, -q[i].v);
}
lq[ ++ nl] = q[i];
}
else{
rq[ ++ nr] = q[i];
}
}
// query
else{
int id = q[i].id;
LL n = 0;
for(int i = 0;i < adj[id].size();i ++ ){
int t = adj[id][i];
n += query(t);
if(n >= require[id]) break;
}
if(require[id] <= n) lq[ ++ nl] = q[i];
else require[id] -= n, rq[ ++ nr] = q[i];
}
}
// clear
for(int i = ql;i <= qr;i ++ ){
if(q[i].op == 1){
if(q[i].id <= mid){
update(q[i].x1, -q[i].v);
update(q[i].y1 + 1, q[i].v);
if(q[i].x2){
update(q[i].x2, -q[i].v);
update(q[i].y2 + 1, q[i].v);
}
}
}
}
for(int i = 1;i <= nl;i ++ ) q[ql + i - 1] = lq[i];
for(int i = 1;i <= nr;i ++ ) q[ql + nl + i - 1] = rq[i];
solve(vl, mid, ql, ql + nl - 1);
solve(mid + 1, vr, ql + nl, qr);
}
int main(){
freopen("D:\\in.in", "r", stdin);
freopen("out.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1;i <= m;i ++ ){
int x; scanf("%d", &x);
adj[x].push_back(i);
}
for(int i = 1;i <= n;i ++ ){
int x; scanf("%d", &x);
require[i] = x;
}
scanf("%d", &k);
int l, r;
for(int i = 1;i <= k;i ++ ){
int v;
scanf("%d%d%d", &l, &r, &v);
q[i].v = v, q[i].op = 1, q[i].id = i;
if(l <= r){
q[i].x1 = l, q[i].y1 = r;
}else{
q[i].x1 = l, q[i].y1 = m;
q[i].x2 = 1, q[i].y2 = r;
}
}
for(int i = k + 1;i <= k + n;i ++ ){
q[i].op = 2;
q[i].id = i - k;
}
q[n + k + 1].op = 1, q[n + k + 1].x1 = 1;
q[n + k + 1].y1 = m, q[n + k + 1].id = k + 1;
q[n + k + 1].v = INF;
solve(1, k + 1, 1, n + k + 1);
for(int i = 1;i <= n;i ++ )// cout << ans[i] << endl;
if(ans[i] > k) puts("NIE");
else printf("%d\n", ans[i]);
return 0;
}
Orz