//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound
using namespace std;
typedef long long ll;
//17 SEVENTEEN
const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 3e5 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }
ll zxc = 1, n, m, q, a[N], t[4 * N], uv[4 * N];
ll l[N], r[N], x[N];
ll p[N], cur[N], lw[N], hg[N];
vector<ll> v[N], vq[N];
void recalc(ll v) {
t[v] = t[left(v)] + t[right(v)];
}
void push(ll v, ll tl, ll tr) {
if (!uv[v]) return;
if (tl < tr) {
uv[left(v)] += uv[v];
uv[right(v)] += uv[v];
}
t[v] += uv[v] * 1ll * (tr - tl + 1);
uv[v] = 0;
}
ll get(ll v, ll tl, ll tr, ll l, ll r) {
push(v, tl, tr);
if(l <= tl && tr <= r) return t[v];
if(tr < l || r < tl) return 0;
ll tm = (tl + tr) / 2;
return get(left(v), tl, tm, l, r) + get(right(v), tm + 1, tr, l, r);
}
void upd(ll v, ll tl, ll tr, ll ql, ll qr, ll val) {
push(v, tl, tr);
if (tr < ql || qr < tl) return;
if (ql <= tl && tr <= qr) {
uv[v] += val;
push(v, tl, tr);
return;
}
int mid = (tl + tr) / 2;
upd(left(v), tl, mid, ql, qr, val);
upd(right(v), mid + 1, tr, ql, qr, val);
recalc(v);
}
void solve() {
cin >> n >> m;
for(ll i = 1; i <= m; i++) {
cin >> p[i];
v[p[i]].pb(i);
}
for(ll i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> q;
for(ll i = 1; i <= n; i++)
lw[i] = 1, hg[i] = q + 1;
for(ll i = 1; i <= q; i++) {
cin >> l[i] >> r[i] >> x[i];
}
ll ok = 1;
while(ok) {
ok = 0;
// cout << "OK\n";
for(ll i = 1; i <= 4 * m; i++) t[i] = uv[i] = 0;
for(ll i = 1; i <= n; i++) {
if(lw[i] != hg[i])
vq[(lw[i] + hg[i]) / 2].pb(i);
}
for(ll i = 1; i <= q; i++) {
if(l[i] <= r[i])
upd(1, 1, m, l[i], r[i], x[i]);
else upd(1, 1, m, l[i], m, x[i]), upd(1, 1, m, 1, r[i], x[i]);
while(!vq[i].empty()) {
ok = 1;
ll id = vq[i].back();
vq[i].pop_back();
ll sum = 0;
for(ll x : v[id]) {
sum += get(1, 1, m, x, x);
}
if(sum >= a[id]) hg[id] = i;
else lw[id] = i + 1;
}
}
}
for(ll i = 1; i <= n; i++) {
cout << (lw[i] <= q ? to_string(lw[i]) : "NIE") << "\n";
}
}
int main(/*Уверенно*/) {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
*/
// cin >> zxc;
while(zxc--) {
solve();
}
return 0;
}
// さよならさ いかなくちゃ
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
14540 KB |
Output is correct |
2 |
Correct |
13 ms |
14540 KB |
Output is correct |
3 |
Correct |
13 ms |
14540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
14540 KB |
Output is correct |
2 |
Correct |
12 ms |
14540 KB |
Output is correct |
3 |
Correct |
14 ms |
14716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
614 ms |
20556 KB |
Output is correct |
2 |
Correct |
706 ms |
23884 KB |
Output is correct |
3 |
Correct |
696 ms |
22920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
668 ms |
22020 KB |
Output is correct |
2 |
Correct |
738 ms |
22004 KB |
Output is correct |
3 |
Correct |
751 ms |
24144 KB |
Output is correct |
4 |
Correct |
166 ms |
21064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
21024 KB |
Output is correct |
2 |
Correct |
523 ms |
24480 KB |
Output is correct |
3 |
Correct |
260 ms |
15756 KB |
Output is correct |
4 |
Correct |
673 ms |
23400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
669 ms |
19844 KB |
Output is correct |
2 |
Correct |
626 ms |
21944 KB |
Output is correct |
3 |
Correct |
657 ms |
20192 KB |
Output is correct |
4 |
Correct |
845 ms |
25536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6075 ms |
61796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6093 ms |
59076 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |