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;
const int mxN = 3e5+3;
vector<int> a[mxN];
vector<array<int, 3>> v;
int p[mxN], ans[mxN], n, m, k, c = -1;
long long st[4*mxN], lz[4*mxN];
void push(int i, int l, int r) {
if (lz[i]) {
int mid = (l + r)/2;
lz[2*i] += lz[i];
st[2*i] += (mid - l + 1) * lz[i];
lz[2*i+1] += lz[i];
st[2*i+1] += (r - mid) * lz[i];
lz[i] = 0;
}
}
void update(int l, int r, long long x, int i = 1, int l2 = 0, int r2 = m-1) {
if (l <= l2 && r2 <= r) {
st[i] += x * (r2 - l2 + 1);
lz[i] += x;
return;
}
push(i, l2, r2);
int m2 = (l2 + r2)/2;
if (l <= m2) {
update(l, r, x, 2*i, l2, m2);
}
if (m2+1 <= r) {
update(l, r, x, 2*i+1, m2+1, r2);
}
st[i] = st[2*i] + st[2*i+1];
}
long long sum(int idx, int i = 1, int l2 = 0, int r2 = m-1) {
if (l2 == r2) {
return st[i];
}
push(i, l2, r2);
int m2 = (l2 + r2)/2;
return (idx <= m2 ? sum(idx, 2*i, l2, m2) : sum(idx, 2*i+1, m2+1, r2));
}
void solve(int l, int r, vector<int> b) {
int mid = (l + r)/2;
while (c < mid) {
++c;
if (v[c][0] <= v[c][1]) {
update(v[c][0], v[c][1], v[c][2]);
}
else {
update(v[c][0], m-1, v[c][2]);
update(0, v[c][1], v[c][2]);
}
}
while (c > mid) {
if (v[c][0] <= v[c][1]) {
update(v[c][0], v[c][1], -v[c][2]);
}
else {
update(v[c][0], m-1, -v[c][2]);
update(0, v[c][1], -v[c][2]);
}
--c;
}
vector<int> L, R;
for (auto x : b) {
long long s = 0;
for (auto i : a[x]) {
s += sum(i);
}
if (s >= p[x]) {
L.push_back(x);
ans[x] = mid;
}
else {
R.push_back(x);
}
}
b.clear();
if (l < mid && L.size()) {
solve(l, mid-1, L);
}
if (mid < r && R.size()) {
solve(mid+1, r, R);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
fill(ans, ans+n, -1);
for (int i = 0; i < m; ++i) {
int x;
cin >> x;
--x;
a[x].push_back(i);
}
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
cin >> k;
for (int i = 0; i < k; ++i) {
int l, r, x;
cin >> l >> r >> x;
--l, --r;
v.push_back({l, r, x});
}
vector<int> v(n);
iota(v.begin(), v.end(), 0);
solve(0, k-1, v);
for (int i = 0; i < n; ++i) {
cout << (ans[i] == -1 ? "NIE" : to_string(ans[i]+1)) << '\n';
}
}
# | 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... |