#include <bits/stdc++.h>
#ifdef local
#include "../../local.hpp"
#else
#define dbg(...)
#endif
using i64 = long long;
std::vector<int> t;
void build(int v, int l, int r) {
t[v] = 0;
if (l == r) {
t[v] = 0;
return;
}
int mid = (l + r) / 2;
build(v + v, l, mid);
build(v + v + 1, mid + 1, r);
}
void upd(int v, int l, int r, int ql, int qr, i64 x) {
if (ql <= l && r <= qr) {
t[v] += x;
return;
}
if (ql > r || qr < l) {
return;
}
int mid = (l + r) / 2;
upd(v + v, l, mid, ql, qr, x);
upd(v + v + 1, mid + 1, r, ql, qr, x);
}
i64 get(int v, int l, int r, int pos, i64 sum) {
sum += t[v];
if (l == r) {
return sum;
}
int mid = (l + r) / 2;
if (pos <= mid) {
return get(v + v, l, mid, pos, sum);
} else {
return get(v + v + 1, mid + 1, r, pos, sum);
}
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
#ifdef local
freopen("program.in", "r", stdin);
freopen("program.out", "w", stdout);
freopen("program.err", "w", stderr);
#endif
int n, m;
std::cin >> n >> m;
std::vector<int> o(m + 1);
for (int i = 1; i <= m; i++) {
std::cin >> o[i];
}
std::vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
std::cin >> p[i];
}
int k;
std::cin >> k;
std::vector<int> l(k + 1), r(k + 1), a(k + 1);
for (int i = 1; i <= k; i++) {
std::cin >> l[i] >> r[i] >> a[i];
}
std::map<int, std::vector<int>> ow;
for (int i = 1; i <= m; i++) {
ow[o[i]].push_back(i);
}
std::vector<int> lo(n + 1, 1), hi(n + 1, k + 1);
t.assign(m + 100, 0);
bool chk = true;
std::map<int, std::set<int>> wrk;
while (chk) {
chk = false;
build(1, 1, m);
for (int i = 1; i <= n; i++) {
if (lo[i] == hi[i]) {
continue;
}
int m = (lo[i] + hi[i]) / 2;
wrk[m].insert(i);
}
for (int q = 1; q <= k; q++) {
if (l[q] <= r[q]) {
upd(1, 1, m, l[q], r[q], a[q]);
} else {
upd(1, 1, m, 1, r[q], a[q]);
upd(1, 1, m, l[q], m, a[q]);
}
for (auto x : wrk[q]) {
chk = true;
i64 su = 0;
for (auto pls : ow[x]) {
su += get(1, 1, m, pls, 0);
if (su >= p[x]) {
break;
}
}
if (su >= p[x]) {
hi[x] = q;
} else {
lo[x] = q + 1;
}
}
}
for (int i = 1; i <= k; i++) {
wrk[i].clear();
}
}
for (int i = 1; i <= n; i++) {
if (lo[i] <= k) {
std::cout << lo[i] << "\n";
} else {
std::cout << "NIE\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
349 ms |
14004 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
401 ms |
15468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
243 ms |
14072 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
376 ms |
12624 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2455 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2566 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |