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>
using namespace std;
#define ll long long
#define ld long double
#define int ll
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0); cin.sync_with_stdio(0)
struct query {
int l, r, x;
};
const int MN = 300005;
int n, m, a[MN], tgt[MN], l[MN], r[MN], q, bit[MN], fck1, fck2, fck3;
vector<int> pos[MN], chk[MN];
query qs[MN];
void upd(int x, int val) {
for (int i = x + 1; i < MN; i += i & -i) bit[i] += val;
}
int qry(int x) {
int ret = 0;
for (int i = x + 1; i > 0; i -= i & -i) ret += bit[i];
return ret;
}
int32_t main() {
boost();
cin >> n >> m;
for (int i = 1; i <= m; i++) cin >> a[i], pos[a[i]].push_back(i);
for (int i = 1; i <= n; i++) cin >> tgt[i];
cin >> q;
for (int i = 1; i <= q; i++) cin >> fck1 >> fck2 >> fck3, qs[i] = {fck1, fck2, fck3};
for (int i = 1; i < MN; i++) l[i] = 1, r[i] = q + 1;
for (;;) {
bool brk = true;
for (long long & i : bit) i = 0;
for (int i = 1; i <= n; i++) {
if (l[i] == r[i]) continue;
int mid = (l[i] + r[i]) / 2;
chk[mid].push_back(i);
}
for (int i = 1; i <= q; i++) {
if (qs[i].l <= qs[i].r) upd(qs[i].l, qs[i].x), upd(qs[i].r + 1, -qs[i].x);
else upd(1, qs[i].x), upd(qs[i].r + 1, -qs[i].x), upd(qs[i].l, qs[i].x);
while (!chk[i].empty()) {
int id = chk[i].back();
chk[i].pop_back();
int sum = 0;
for (int p : pos[id]) {
sum += qry(p);
if (sum >= tgt[id]) break;
}
if (sum >= tgt[id]) r[id] = i;
else l[id] = i + 1;
brk = false;
}
}
if (brk) break;
}
for (int i = 1; i <= n; i++) {
assert(l[i] == r[i]);
if (l[i] <= q) cout << r[i] << "\n";
else 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... |