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>
using namespace std;
typedef long long ll;
const int N = 2e5;
template <typename T>
struct fenwick_tree{
vector <T> t;
fenwick_tree(int n){
t.resize(n + 1);
fill(t.begin(), t.end(), 0);
}
T f(int pos){
T res = 0;
for(int i = pos; i > 0; i -= i & -i) res += t[i];
return res;
}
void u(int pos, T val){
for(int i = pos; i < (int)t.size(); i += i & -i) t[i] += val;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
fenwick_tree <long long> x(n), y(n);
for (int i = 1; i <= n; i++) {
x.u(i, 1);
y.u(i, 1);
}
vector <int> P(q), D(q), L(q);
for (int i = 0; i < q; i++) {
cin >> P[i] >> D[i] >> L[i];
}
for (int i = q - 1; i >= 0; i--) {
if (D[i] == 1) {
int l = 0, r = n + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (x.f(mid) <= P[i]) l = mid;
else r = mid;
}
y.u(1, -2 * L[i]);
y.u(l + 1, 2 * L[i]);
}else {
int l = 0, r = n + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (y.f(mid) <= P[i]) l = mid;
else r = mid;
}
x.u(r, 2 * L[i]);
}
}
for (int i = 1; i <= n; i++) {
cout << (x.f(i) - y.f(i)) / 2 << "\n";
}
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... |