#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 + 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;
}
}
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 || own[i].size() == 0) {
cout << "NIE";
}
else {
cout << r[i];
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
7 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 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 |
52 ms |
30576 KB |
Output is correct |
2 |
Correct |
94 ms |
35628 KB |
Output is correct |
3 |
Correct |
72 ms |
32712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
32020 KB |
Output is correct |
2 |
Correct |
76 ms |
32000 KB |
Output is correct |
3 |
Correct |
94 ms |
36104 KB |
Output is correct |
4 |
Correct |
25 ms |
32120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
31032 KB |
Output is correct |
2 |
Correct |
74 ms |
35964 KB |
Output is correct |
3 |
Correct |
35 ms |
29468 KB |
Output is correct |
4 |
Correct |
72 ms |
33232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
29796 KB |
Output is correct |
2 |
Correct |
85 ms |
31952 KB |
Output is correct |
3 |
Correct |
56 ms |
30292 KB |
Output is correct |
4 |
Correct |
89 ms |
37076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
926 ms |
53272 KB |
Output is correct |
2 |
Incorrect |
803 ms |
32100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
961 ms |
51300 KB |
Output is correct |
2 |
Incorrect |
881 ms |
31840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |