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 fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int N = 300005;
vector <int> station[N];
int from[N], to[N], add[N], need[N], ans[N];
int point;
struct BIT {
int n;
vector <int> t;
void init(int size) {
n = size;
t.assign((n + 1) * 2, 0);
}
void update(int till, int val) {
while(till) {
t[till] += val;
till = till - (till & (-till));
}
}
int query(int ind) {
int res = 0;
while(ind <= n) {
res += t[ind];
ind = ind + (ind & (-ind));
}
return res;
}
}t;
void f(int l, int r, vector<int>&owner) {
if(owner.empty()) return;
if(l == r) {
for(auto it:owner) {
ans[it] = l;
}
return;
}
int m = (l + r) / 2;
int ul, ur, val;
auto upd = [&]() {
t.update(ul-1, -val);
t.update(ur, val);
if(ur < ul) {
t.update(t.n, val);
}
};
while(point < m) {
point++;
ul = from[point], ur = to[point], val = add[point];
upd();
}
while(point > m) {
ul = from[point], ur = to[point], val = -add[point];
upd();
point--;
}
// now point is at m
vector <int> left, right;
for(int it : owner) {
int sum = 0;
for(int itt : station[it])
sum += t.query(itt);
if(sum >= need[it])
left.push_back(it);
else
right.push_back(it);
}
owner.clear();
f(l, m, left);
f(m + 1, r, right);
}
int32_t main() {
fast
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int in;
cin >> in;
station[in].push_back(i+1);
}
for(int i = 1; i <= n; i++) {
cin >> need[i];
}
int q;
cin >> q;
for(int i = 1; i <= q; i++) {
cin >> from[i] >> to[i] >> add[i];
}
vector <int> owner(n);
for(int i = 0; i < n; i++) owner[i] = i+1;
from[q+1] = 1, to[q+1] = m, add[q+1] = 0;
t.init(m);
f(1, q + 1, owner);
for(int i = 1; i <= n; i++) {
if(ans[i] > q) cout << "NIE\n";
else cout << ans[i] << "\n";
}
}
# | 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... |