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 long long long
const int N = 300005;
int n, m, q, l[N], r[N], a[N], b[N];
long want[N], fen[N], val[N];
vector<int> own[N], check[N];
void add(int i, int val) {
for (; i<=m; i+=i&(-i)) fen[i] += val;
return;
}
long sum(int i) {
long ret = 0;
for (; i>0; i-=i&(-i)) ret += fen[i];
return ret;
}
int main() {
cin >> n >> m;
for (int i=1; i<=m; i++) {
int x;
cin >> x;
own[x].push_back(i);
}
for (int i=1; i<=n; i++) cin >> want[i];
cin >> q;
for (int i=1; i<=q; i++) cin >> a[i] >> b[i] >> val[i];
fill_n(l, N, 1);
fill_n(r, N, q+1);
int time = 20;
while (time--) {
fill_n(check, N, vector<int>());
for (int i=1; i<=n; i++) {
if (l[i] < r[i]) check[(l[i]+r[i])/2].push_back(i);
}
fill_n(fen, N, 0);
for (int i=1; i<=q; i++) {
if (a[i] <= b[i]) add(a[i], val[i]), add(b[i]+1, -val[i]);
else add(1, val[i]), add(b[i]+1, -val[i]), add(a[i], val[i]);
for (auto j : check[i]) {
long nowsum = 0;
for (auto area : own[j]) nowsum += sum(area), nowsum = min(nowsum, (long)1e9);
if (nowsum >= want[j]) r[j] = i;
else l[j] = i+1;
}
}
}
for (int i=1; i<=n; i++) {
if (l[i] == q+1) cout << "NIE" << endl;
else cout << l[i] << endl;
}
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... |