이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 3e5 +100;
const int k = 550;
int n, m, q;
pair<pii, int> queries[maxn];
vector<int> segments[maxn];
int o[maxn];
ll p[maxn];
ll p1[maxn];
bool mark[maxn];
int ans[maxn];
ll add[maxn];
int IndToGroup(int index) {
return (index-1)/k +1;
}
int Sgroup(int gr) {
return (gr-1) * k +1;
}
int Fgroup(int gr) {
return min(gr * k, q);
}
void calAns(int x, int gr) {
int val = p1[x];
int start = Sgroup(gr);
int finish = Fgroup(gr);
for (int s : segments[x]) {
for (int i = start; i <= finish; i++) {
int l = queries[i].first.first;
int r = queries[i].first.second;
int a = queries[i].second;
if (l <= r) {
if (l <= s && s <= r) {
val -= a;
if (val <= 0) {
ans[x] = i;
mark[x] = true;
return;
}
}
} else {
if (s <= l) {
val -= a;
if (val <= 0) {
ans[x] = i;
mark[x] = true;
return;
}
} else if (s >= r) {
val -= a;
if (val <= 0) {
ans[x] = i;
mark[x] = true;
return;
}
}
}
}
}
}
void update(int last) {
int gr = IndToGroup(last);
for (int i = 1; i <= m; i++) {
add[i] = 0;
}
for (int i = 1; i <= n; i++) {
p1[i] = p[i];
}
for (int i = Sgroup(gr); i <= last; i++) {
int l = queries[i].first.first;
int r = queries[i].first.second;
int a = queries[i].second;
if (r >= l) {
add[l] += a;
add[r+1] -= a;
} else {
add[1] += a;
add[r+1] -= a;
add[l] += a;
add[m+1] -= a;
}
}
ll cnt = 0;
for (int i = 1; i <= m; i++) {
cnt += add[i];
p[o[i]] -= cnt;
}
for (int i = 1; i <= n; i++) {
if (p[i] <= 0 && !mark[i]) {
calAns(i, gr);
}
}
}
int main () {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> o[i];
segments[o[i]].push_back(i);
}
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
cin >> q;
int last_gr = 1;
for (int i = 1; i <= q; i++) {
int gr = IndToGroup(i);
if (last_gr != gr) {
update(i -1);
}
int l, r, a;
cin >> l >> r >> a;
queries[i] = {{l, r}, a};
}
update(q);
for (int i = 1; i <= n; i++) {
if (ans[i] == 0) {
cout << "NIE" << endl;
} else {
cout << ans[i] << 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... |