//ome47
#include "bits/stdc++.h"
using namespace std;
#define intt long long
const intt mxN = 3e5 + 5;
const intt LG = 20;
const intt inf = 1e18;
intt n, m, k;
vector<intt> seg(4 * mxN), lazy(4 * mxN);
vector<vector<intt>> idx, f;
vector<array<intt,3>> sh;
intt a[mxN], need[mxN], mid[mxN], sol[mxN], sag[mxN];
void push(intt node, intt l, intt r) {
if(!lazy[node]) return;
seg[node] += (r - l + 1) * lazy[node];
if(l != r) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
void upd(intt node, intt l, intt r, intt ql, intt qr, intt val) {
push(node, l, r);
if(ql > r || qr < l || ql > qr) return;
if(ql <= l && r <= qr) {
lazy[node] += val;
push(node, l, r);
return;
}
intt mid = (l + r) / 2;
upd(node * 2, l, mid, ql, qr, val);
upd(node * 2 + 1, mid + 1, r, ql, qr, val);
seg[node] = seg[node * 2] + seg[node * 2 + 1];
}
intt get(intt node, intt l, intt r, intt ql, intt qr) {
push(node, l, r);
if(ql > r || qr < l || ql > qr) return 0ll;
if(ql <= l && r <= qr) {
push(node, l, r);
return seg[node];
}
intt mid = (l + r) / 2;
return get(node * 2, l, mid, ql, qr) + get(node * 2 + 1, mid + 1, r, ql, qr);
}
void _() {
cin >> n >> m;
idx.assign(n + 10, vector<intt> {});
for(intt i = 1; i <= m; i++) {
cin >> a[i];
idx[a[i]].push_back(i);
}
for(intt i = 1; i <= n; i++) {
cin >> need[i];
}
cin >> k;
sh.push_back({-1,-1});
for(intt i = 0; i < k; i++) {
intt l, r, a;
cin >> l >> r >> a;
sh.push_back({l, r, a});
}
for(intt i = 1; i <= n; i++) {
sol[i] = 1;
sag[i] = k;
}
vector<intt> ans(n + 1, -1);
for(intt reps = 0; ; reps++) {
seg.assign(4 * m + 1, 0ll);
lazy.assign(4 * m + 1, 0ll);
f.assign(k + 5, vector<intt> {});
bool c = 0;
for(intt i = 1; i <= n; i++) {
if(sol[i] <= sag[i]) {
c=1;
}
mid[i] = (sol[i] + sag[i]) / 2;
f[(sol[i] + sag[i]) / 2].push_back(i);
}
if(!c) break;
for(intt s = 1; s <= k; s++) {
if(sh[s][0] <= sh[s][1]) {
upd(1, 1, m, sh[s][0], sh[s][1], sh[s][2]);
} else {
upd(1, 1, m, sh[s][0], m, sh[s][2]);
upd(1, 1, m, 1, sh[s][1], sh[s][2]);
}
intt amiri=0;
for(intt i = 0; i < (intt)f[s].size(); i++) {
intt p = f[s][i];
for(intt j = 0; j < (intt)idx[p].size(); j++) {
amiri += get(1, 1, m, idx[p][j], idx[p][j]);
if(need[p] <= amiri) {
break;
}
}
if(amiri >= need[p]) {
ans[p] = mid[p];
sag[p] = mid[p] - 1;
} else {
sol[p] = mid[p] + 1;
}
amiri = 0;
}
}
}
for(intt i = 1; i <= n; i++) {
if(ans[i] == -1) {
cout << "NIE" << endl;
} else {
cout << ans[i] << endl;
}
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
intt t = 1;
// cin >> t;
while(t--){
cout << endl;
_();
}
}
// ⠀⠀⠀⠀⠀⠀⠀⢀⣤⣦⣶⣤⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣤⢀⣀⡀⣠⣄⣠⣶⣿⣿⣿⣿⣿⣿⣿⣷⣾⡦⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠻⡳⢛⠛⠒⠚⢛⣿⣿⠟⠋⠉⠛⠛⢿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀
// ⢛⡛⢿⣿⠟⠻⠛⣿⣇⣶⣖⣤⣀⣄⡰⣹⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀
// ⢿⠿⠿⠿⠿⠿⠿⢭⣐⠠⢼⣬⠽⢈⢁⡿⠛⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣛⣱⣤⣤⣤⣀⣄⣄⣗⢌⠋⠉⢙⣴⣧⢤⣤⣤⣤⣦⡀⠀⠀⠀⠀⢺⡿
// ⣿⣿⣿⠟⠛⠋⠀⡬⠼⢠⠍⠂⠀⠨⡇⠀⡏⠉⠛⢿⣧⠀⠀⠀⠀⢸⣀
// ⣟⠄⠀⠀⠀⠀⠀⢡⠀⠀⠀⠀⠀⡠⠁⢀⠁⠀⠀⠀⠘⣗⢀⠄⢶⣼⣾
// ⠀⠀⠀⢠⣦⠇⠀⠀⠁⠒⠒⠒⠈⠀⠀⠀⣞⢶⡀⠀⠀⠹⣧⣠⡞⣸⣏
// ⠀⠀⢀⡞⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣦⡀⠀⠈⠫⣕⣻⡇
// ⠀⠀⣾⣧⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⣿⣿⣿⣷⣦⡠⡤⠀⣿⡇
// ⠠⢿⣿⣿⠂⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠴⣿⣿⣿⣿⠟⠋⢀⣤⣿⣷
// ⣀⣀⣀⣙⣃⣠⣤⣔⣤⣢⣵⣒⣒⣢⣄⣤⣄⣛⣋⣉⣀⣀⣤⣿⣿⣿⣿
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |