이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int n, m, q;
ll sum;
struct Kind {
Kind *L, *R;
ll Cur = 0;
};
Kind *build(Kind *id, int l, int r) {
if (l == r) {
return id;
}
int md = (l + r) / 2;
id->L = build(new Kind(), l, md + 0);
id->R = build(new Kind(), md + 1, r);
return id;
}
Kind *update(Kind *id, int u, int v, int c, int l, int r) {
if (l > v || r < u) {
return id;
}
if (u <= l && r <= v) {
Kind *temp = new Kind();
temp->L = id->L;
temp->R = id->R;
temp->Cur = id->Cur + c;
return temp;
}
int md = (l + r) / 2;
Kind *temp = new Kind();
temp->L = update(id->L, u, v, c, l, md + 0);
temp->R = update(id->R, u, v, c, md + 1, r);
temp->Cur = id->Cur;
return temp;
}
void get(Kind *id, int u, int v, int l, int r) {
if (l > v || r < u) {
return;
}
sum += id->Cur;
if (l >= u && r <= v) {
return;
}
int md = (l + r) / 2;
get(id->L, u, v, l, md + 0),
get(id->R, u, v, md + 1, r);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
map<int, vector<int>> Ind;
for (int i = 1; i <= m; i++) {
int a;
cin >> a;
Ind[a].push_back(i);
}
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
int N = m;
while (N < m) {
N *= 2;
}
auto head = build(new Kind(), 1, N);
vector<Kind*> Head;
cin >> q;
int qq = q;
while (qq--) {
int l, r, x;
cin >> l >> r >> x;
if (l <= r) {
Head.push_back(update((Head.empty() ? head : Head.back()), l, r, x, 1, N));
}
else {
auto temp = update((Head.empty() ? head : Head.back()), l, m, x, 1, N);
Head.push_back(update(temp, 1, r, x, 1, N));
}
}
for (int i = 1; i <= n; i++) {
int l = 0, r = Head.size() - 1, res = -1;
while (l <= r) {
int md = (l + r) / 2;
auto cur = Head[md];
sum = 0;
for (auto pos : Ind[i]) {
get(cur, pos, pos, 1, N);
}
if (sum >= A[i]) {
res = md, r = md - 1;
}
else {
l = md + 1;
}
}
if (res == -1) {
cout << "NIE" << endl;
}
else {
cout << res + 1 << endl;
}
}
}
# | 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... |