#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct st{
int l, r;
ll x;
};
int const N = 300010;
vector<int> own[N];
st q[N];
ll mx[N];
template<class T>
struct BIT{
vector<T> bit;
BIT(int N) : bit(N, 0) {}
void add(int pos, T val) {
for (; pos < (int) bit.size(); pos += pos & -pos) {
bit[pos] += val;
}
}
T sum(int r) {
T res{};
for (; r > 0; r -= r & -r) {
res += bit[r];
}
return res;
}
T sum(int l, int r) { return sum(r) - sum(l - 1); }
};
int sol[N];
BIT<ll> bit(N);
void add(int i, int p) {
if (q[i].l <= q[i].r) {
bit.add(q[i].l, q[i].x * p);
bit.add(q[i].r + 1, -q[i].x * p);
} else {
bit.add(1, q[i].x * p);
bit.add(q[i].r + 1, -q[i].x * p);
bit.add(q[i].l, q[i].x * p);
}
}
void solve(int lo, int hi, vector<int> const &ind) {
if (lo == hi) {
for (int i : ind) {
sol[i] = lo;
}
return;
}
int mid = (lo + hi) / 2;
for (int i = lo; i <= mid; ++i) {
add(i, 1);
}
vector<int> l, r;
for (int i : ind) {
ll suma = 0;
for (int a : own[i]) {
suma += bit.sum(a);
if (suma >= mx[i]) break;
}
if (suma >= mx[i]) {
l.push_back(i);
} else r.push_back(i);
}
solve(mid + 1, hi, r);
for (int i = lo; i <= mid; ++i) {
add(i, -1);
}
solve(lo, mid, l);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int a;
cin >> a;
own[a].push_back(i);
}
for (int i = 1; i <= n; ++i) {
cin >> mx[i];
}
int k;
cin >> k;
for (int i = 1; i <= k; ++i) {
cin >> q[i].l >> q[i].r >> q[i].x;
}
vector<int> tmp(n);
iota(begin(tmp), end(tmp), 1);
solve(1, k + 1, tmp);
for (int i = 1; i <= n; ++i) {
if (sol[i] > k) {
cout << "NIE\n";
} else cout << sol[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9836 KB |
Output is correct |
2 |
Correct |
8 ms |
9836 KB |
Output is correct |
3 |
Correct |
8 ms |
9836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9836 KB |
Output is correct |
2 |
Correct |
9 ms |
9836 KB |
Output is correct |
3 |
Correct |
9 ms |
9836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
11292 KB |
Output is correct |
2 |
Correct |
148 ms |
13164 KB |
Output is correct |
3 |
Correct |
107 ms |
11500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
11244 KB |
Output is correct |
2 |
Correct |
124 ms |
11372 KB |
Output is correct |
3 |
Correct |
138 ms |
12556 KB |
Output is correct |
4 |
Correct |
37 ms |
11116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
11232 KB |
Output is correct |
2 |
Correct |
149 ms |
12912 KB |
Output is correct |
3 |
Correct |
126 ms |
10604 KB |
Output is correct |
4 |
Correct |
108 ms |
11648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
10860 KB |
Output is correct |
2 |
Correct |
124 ms |
11340 KB |
Output is correct |
3 |
Correct |
92 ms |
10988 KB |
Output is correct |
4 |
Correct |
135 ms |
12396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1041 ms |
24688 KB |
Output is correct |
2 |
Correct |
611 ms |
15736 KB |
Output is correct |
3 |
Correct |
734 ms |
13764 KB |
Output is correct |
4 |
Correct |
1233 ms |
26620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
978 ms |
22884 KB |
Output is correct |
2 |
Correct |
601 ms |
15732 KB |
Output is correct |
3 |
Correct |
529 ms |
13036 KB |
Output is correct |
4 |
Correct |
1326 ms |
28944 KB |
Output is correct |