#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct st{
ll l, r;
ll x;
};
vector<ll> sol;
template<class T>
struct BIT{
vector<T> bit;
explicit BIT(int N) : bit(N, 0) {}
void add(int pos, T val) {
for (; pos < (int) bit.size(); pos += pos & -pos) {
bit[pos] += val;
}
}
T sum(int r) {
T res{};
for (; r > 0; r -= r & -r) {
res += bit[r];
}
return res;
}
T sum(int l, int r) { return sum(r) - sum(l - 1); }
};
BIT<ll> bit(1);
vector<vector<ll>> own;
vector<ll> v;
vector<st> q;
void apply(int i, int p) {
if (q[i].l <= q[i].r) {
bit.add(q[i].l, q[i].x * p);
bit.add(q[i].r + 1, -q[i].x * p);
} else {
bit.add(1, q[i].x * p);
bit.add(q[i].r + 1, -q[i].x * p);
bit.add(q[i].l, q[i].x * p);
}
}
void solve(int lo, int hi, vector<int> const &ind) {
if (lo == hi - 1) {
for (int i : ind) {
sol[i] = lo;
}
return;
}
int mid = (lo + hi) / 2;
for (int i = lo; i < mid; ++i) {
apply(i, 1);
}
vector<int> l, r;
for (int i : ind) {
ll suma = 0;
for (int a : own[i]) {
suma += bit.sum(a);
if (suma >= v[i]) break;
}
if (suma >= v[i]) {
l.push_back(i);
} else r.push_back(i);
}
solve(mid, hi, r);
for (int i = lo; i < mid; ++i) {
apply(i, -1);
}
solve(lo, mid, l);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
bit.bit.resize(n + 10);
sol.resize(n);
own.resize(n);
for (int i = 1; i <= m; ++i) {
ll a;
cin >> a;
--a;
own[a].push_back(i);
}
v.resize(n);
for (auto &a : v) cin >> a;
ll k;
cin >> k;
q.resize(k);
for (int i = 0; i < k; ++i) {
cin >> q[i].l >> q[i].r >> q[i].x;
}
vector<int> tmp(n);
iota(begin(tmp), end(tmp), 0);
solve(0, k, tmp);
bit.bit.assign(n + 10, 0);
for (int i = 0; i < k; ++i) {
apply(i, 1);
}
for (int i = 0; i < n; ++i) {
ll suma = 0;
for (int a : own[i]) {
suma += bit.sum(a);
if (suma >= v[i]) break;
}
if (suma < v[i]) {
sol[i] = -1;
}
}
for (auto a : sol) {
if (a == -1) {
cout << "NIE\n";
} else cout << a + 1 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
60 ms |
3188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
2668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
3892 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
236 ms |
35948 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
209 ms |
33900 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |