#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define int long long
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;
}
signed 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
30708 KB |
Output is correct |
2 |
Correct |
85 ms |
35652 KB |
Output is correct |
3 |
Correct |
74 ms |
32592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
31820 KB |
Output is correct |
2 |
Correct |
75 ms |
31832 KB |
Output is correct |
3 |
Correct |
93 ms |
35776 KB |
Output is correct |
4 |
Correct |
26 ms |
32344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
31060 KB |
Output is correct |
2 |
Correct |
74 ms |
36004 KB |
Output is correct |
3 |
Correct |
36 ms |
29276 KB |
Output is correct |
4 |
Correct |
73 ms |
33088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
29880 KB |
Output is correct |
2 |
Correct |
90 ms |
32976 KB |
Output is correct |
3 |
Correct |
66 ms |
31364 KB |
Output is correct |
4 |
Correct |
91 ms |
38352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1150 ms |
53256 KB |
Output is correct |
2 |
Incorrect |
776 ms |
31848 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
893 ms |
51592 KB |
Output is correct |
2 |
Incorrect |
912 ms |
31596 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |