// QuangBuiCP
// https://oj.uz/problem/view/POI11_met
#include "bits/stdc++.h"
using namespace std;
int main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif // LOCAL
int n, m;
cin >> n >> m;
vector<vector<int>> properties(n);
for (int i = 0; i < m; ++i) {
int who;
cin >> who;
properties[--who].push_back(i);
}
vector<int64_t> target(n);
for (int i = 0; i < n; ++i) {
cin >> target[i];
}
int events;
cin >> events;
vector<tuple<int, int, int64_t>> event(events);
for (auto& [l, r, collectable] : event) {
cin >> l >> r >> collectable;
l--, r--;
}
vector<vector<int>> candidates(events + 1);
vector<int> L(n, 0), R(n, events - 1);
vector<int> answer(n, -1);
for (int step = 0; step < 20; ++step) {
for (int i = 0; i < n; ++i) {
if (L[i] > R[i]) {
continue;
}
int mid = (L[i] + R[i]) / 2;
candidates[mid].push_back(i);
}
vector<int64_t> fenw(m + 1, 0);
auto Update = [&fenw, &m](int x, int64_t val) {
while (x <= m) {
fenw[x] += val;
x |= x + 1;
}
};
auto UpdateRange = [&fenw, &m, &Update](int l, int r, int64_t val) {
Update(l, val);
Update(r + 1, -val);
};
auto Query = [&fenw](int x) {
int64_t res = 0;
while (x >= 0) {
res += fenw[x];
x &= x + 1;
x--;
}
return res;
};
for (int mid = 0; mid < events; ++mid) {
auto [l, r, collectable] = event[mid];
if (l <= r) {
UpdateRange(l, r, collectable);
} else {
UpdateRange(l, m - 1, collectable);
UpdateRange(0, r, collectable);
}
for (int who : candidates[mid]) {
int64_t sum = 0;
for (int land : properties[who]) {
sum += Query(land);
if (sum >= target[who]) {
break;
}
}
if (sum >= target[who]) {
answer[who] = mid;
R[who] = mid - 1;
} else {
L[who] = mid + 1;
}
}
candidates[mid].clear();
}
}
for (int i = 0; i < n; ++i) {
if (answer[i] == -1) {
cout << "NIE\n";
} else {
cout << answer[i] + 1 << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
3784 KB |
Output is correct |
2 |
Correct |
100 ms |
6608 KB |
Output is correct |
3 |
Correct |
66 ms |
5428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
4812 KB |
Output is correct |
2 |
Correct |
75 ms |
4868 KB |
Output is correct |
3 |
Correct |
92 ms |
6696 KB |
Output is correct |
4 |
Correct |
16 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
4052 KB |
Output is correct |
2 |
Correct |
73 ms |
7116 KB |
Output is correct |
3 |
Correct |
27 ms |
2392 KB |
Output is correct |
4 |
Correct |
65 ms |
5956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
3028 KB |
Output is correct |
2 |
Correct |
87 ms |
5580 KB |
Output is correct |
3 |
Correct |
51 ms |
4044 KB |
Output is correct |
4 |
Correct |
99 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
976 ms |
32672 KB |
Output is correct |
2 |
Correct |
511 ms |
15696 KB |
Output is correct |
3 |
Correct |
129 ms |
11860 KB |
Output is correct |
4 |
Correct |
1530 ms |
58316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
934 ms |
31128 KB |
Output is correct |
2 |
Correct |
521 ms |
15684 KB |
Output is correct |
3 |
Correct |
110 ms |
10280 KB |
Output is correct |
4 |
Correct |
1593 ms |
65536 KB |
Output is correct |