This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef local
#include "../../local.hpp"
#else
#define dbg(...)
#endif
using i64 = long long;
int n, m;
std::vector<int> tree;
void add(int x, i64 val) {
while (x <= m) {
tree[x] += val;
x += (x & -x);
}
}
i64 sum(int x) {
i64 s = 0;
while (x > 0) {
s += tree[x];
x -= (x & -x);
}
return s;
}
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
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];
}
dbg(n, m);
dbg(o);
dbg(p);
dbg(k);
dbg(l, r, a);
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, 0 + 1), hi(n + 1, k + 1);
dbg(lo, hi);
tree.assign(m + 1, 0);
dbg(tree);
bool chk = true;
std::map<int, std::vector<int>> wrk;
while (chk) {
chk = false;
tree.assign(m + 1, 0);
dbg(tree);
for (int i = 1; i <= n; i++) {
if (lo[i] == hi[i]) {
continue;
}
int m = lo[i] + (hi[i] - lo[i]) / 2;
dbg(m);
wrk[m].push_back(i);
}
for (int q = 1; q <= k; q++) {
if (l[q] <= r[q]) {
add(l[q], a[q]);
add(r[q] + 1, -a[q]);
} else {
add(1, a[q]);
add(r[q] + 1, -a[q]);
add(l[q], a[q]);
}
dbg(tree);
while (!wrk[q].empty()) {
chk = true;
auto x = wrk[q].back();
wrk[q].pop_back();
i64 su = 0;
for (auto pls : ow[x]) {
su += sum(pls);
if (su >= p[x]) {
break;
}
}
dbg(su);
if (su >= p[x]) {
hi[x] = q;
} else {
lo[x] = q + 1;
}
}
}
}
for (int i = 1; i <= n; i++) {
if (lo[i] <= k) {
std::cout << lo[i] << "\n";
} else {
std::cout << "NIE\n";
}
}
return 0;
}
# | 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... |