#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const int N = 3e5 + 1;
int n, m, k, p[N], lq[N], rq[N], aq[N], l[N], mid[N], r[N];
ll sum[N];
vector<int> own[N], mids[N];
bool update() {
for (int i = 1; i <= k + 1; ++i) {
mids[i].clear();
}
for (int i = 1; i <= m; ++i) {
sum[i] = 0;
}
bool ret = false;
for (int i = 1; i <= n; ++i) {
mid[i] = (l[i] + r[i]) / 2;
mids[mid[i]].pb(i);
if (r[i] - l[i] > 1) {
ret = true;
}
}
return ret;
}
void modify(int id, int val) {
for (; id <= m; id += id & -id) {
sum[id] += val;
}
}
ll get(int id) {
ll ret = 0;
for (; id; id -= id & -id) {
ret += sum[id];
}
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int o;
cin >> o;
own[o].pb(i);
}
for (int i = 1; i <= n; ++i) {
cin >> p[i];
}
cin >> k;
for (int i = 1; i <= k; ++i) {
cin >> lq[i] >> rq[i] >> aq[i];
}
lq[k + 1] = 1;
rq[k + 1] = m;
aq[k + 1] = (int) 1e9;
for (int i = 1; i <= n; ++i) {
l[i] = 0;
r[i] = k + 1;
}
while (update() == true) {
for (int i = 1; i <= k + 1; ++i) {
if (lq[i] > rq[i]) {
modify(1, aq[i]);
modify(rq[i] + 1, -aq[i]);
modify(lq[i], aq[i]);
}
else {
modify(lq[i], aq[i]);
modify(rq[i] + 1, -aq[i]);
}
for (int idx : mids[i]) {
ll s = 0;
for (int o : own[idx]) {
s += get(o);
if (s >= p[idx]) {
break;
}
}
if (s >= p[idx]) {
r[idx] = i;
}
else {
l[idx] = i;
}
}
}
}
for (int i = 1; i <= n; ++i) {
if (r[i] == k + 1) {
cout << "NIE";
}
else {
cout << r[i];
}
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23132 KB |
Output is correct |
2 |
Correct |
6 ms |
23128 KB |
Output is correct |
3 |
Correct |
6 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23132 KB |
Output is correct |
2 |
Correct |
5 ms |
23164 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
23864 KB |
Output is correct |
2 |
Correct |
80 ms |
25792 KB |
Output is correct |
3 |
Correct |
73 ms |
25684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
24852 KB |
Output is correct |
2 |
Correct |
74 ms |
24904 KB |
Output is correct |
3 |
Correct |
80 ms |
25684 KB |
Output is correct |
4 |
Correct |
27 ms |
24892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
24264 KB |
Output is correct |
2 |
Correct |
66 ms |
26464 KB |
Output is correct |
3 |
Correct |
37 ms |
23296 KB |
Output is correct |
4 |
Correct |
73 ms |
25816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
23384 KB |
Output is correct |
2 |
Correct |
73 ms |
24872 KB |
Output is correct |
3 |
Correct |
57 ms |
23652 KB |
Output is correct |
4 |
Correct |
101 ms |
26960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
730 ms |
36592 KB |
Output is correct |
2 |
Correct |
507 ms |
25184 KB |
Output is correct |
3 |
Correct |
172 ms |
26188 KB |
Output is correct |
4 |
Correct |
1386 ms |
63444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
834 ms |
35336 KB |
Output is correct |
2 |
Correct |
623 ms |
25080 KB |
Output is correct |
3 |
Correct |
153 ms |
26960 KB |
Output is correct |
4 |
Correct |
1519 ms |
65536 KB |
Output is correct |