#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N = 3e5 + 4;
int n, m, k, p[N], lq[N], rq[N], aq[N], l[N], mid[N], r[N], sum[N];
vector<int> own[N], mids[N];
bool update() {
for (int i = 1; i <= k; ++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;
}
}
int get(int id) {
int 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]) {
int s = 0;
for (int o : own[idx]) {
s += get(o);
}
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 |
9 ms |
23132 KB |
Output is correct |
2 |
Correct |
5 ms |
23132 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
23240 KB |
Output is correct |
2 |
Correct |
5 ms |
23128 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
24656 KB |
Output is correct |
2 |
Correct |
78 ms |
26704 KB |
Output is correct |
3 |
Correct |
69 ms |
26456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
25932 KB |
Output is correct |
2 |
Correct |
72 ms |
25880 KB |
Output is correct |
3 |
Correct |
78 ms |
26964 KB |
Output is correct |
4 |
Correct |
24 ms |
25180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
25000 KB |
Output is correct |
2 |
Correct |
58 ms |
27356 KB |
Output is correct |
3 |
Correct |
36 ms |
23816 KB |
Output is correct |
4 |
Correct |
77 ms |
26932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
24420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
717 ms |
43336 KB |
Output is correct |
2 |
Incorrect |
478 ms |
32344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
650 ms |
42024 KB |
Output is correct |
2 |
Incorrect |
457 ms |
30868 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |