This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, q;
#define MX 300003
int owner[MX];
int need[MX];
int L[MX], R[MX];
struct event{
int l, r, val;
};
event query[MX];
struct BIT{
int n;
vector<int> bit;
BIT(int _n = 0) {
n = _n;
bit.assign(n + 2, 0);
}
void up(int p, int val){
for (; p <= n; p += p & -p){
bit[p] += val;
}
}
void updaterange(int l, int r, int v){
up(l, v);
up(r + 1, -v);
}
int get(int x){
int res = 0;
while (x){
res += bit[x];
x -= x & -x;
}
return res;
}
int single(int x){
return get(x);
}
};
vector<int> OWN[MX];
int res[MX];
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; ++i) res[i] = -1;
for (int i = 1; i <= m; ++i) cin >> owner[i];
for (int i = 1; i <= n; ++i) cin >> need[i];
for (int i = 1; i <= m; ++i){
OWN[owner[i]].push_back(i);
}
cin >> q;
for (int i = 1; i <= q; ++i) cin >> query[i].l >> query[i].r >> query[i].val;
for (int i = 1; i <= n; ++i) L[i] = 1, R[i] = q;
bool process = true;
while (process){
process = false;
vector<vector<int>> G;
G.assign(q + 1, {});
BIT bit(m);
for (int i = 1; i <= n; ++i){
if (L[i] > R[i]) continue;
process = true;
G[(L[i] + R[i]) / 2].push_back(i);
}
for (int i = 1; i <= q; ++i){
event &T = query[i];
if (T.l <= T.r){
bit.updaterange(T.l, T.r, T.val);
} else {
bit.updaterange(T.l, m, T.val);
bit.updaterange(1, T.r, T.val);
}
for (int &x : G[i]){
int sum = 0;
for (int &y : OWN[x]){
if (sum >= need[x]) break;
sum += bit.single(y);
}
if (sum >= need[x]){
res[x] = i;
R[x] = i - 1;
} else {
L[x] = i + 1;
}
}
}
}
for (int i = 1; i <= n; ++i){
if (res[i] >= 0) cout << res[i] << '\n'; else
cout << "NIE" << '\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(__null);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |