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<stdio.h>
#define MAXN 200005
typedef long long lint;
lint X[MAXN], L[MAXN];
int D[MAXN];
lint segX[4 * MAXN], segY[4 * MAXN];
void mkseg(int idx, int l, int r, lint seg[]) {
seg[idx] = r - l + 1;
if(l < r) {
int m = (l + r) / 2;
mkseg(idx * 2, l, m, seg);
mkseg(idx * 2 + 1, m + 1, r, seg);
}
}
int lb(int idx, int l, int r, lint x, lint seg[]) {
//if(idx == 1) printf("lb(x = %lld)\n", x);
if(seg[idx] < x) return r + 1;
if(x <= 0 || l == r) return l;
int m = (l + r) / 2;
return x <= seg[idx * 2] ? lb(idx * 2, l, m, x, seg) : lb(idx * 2 + 1, m + 1, r, x - seg[idx * 2], seg);
}
void updseg(int idx, int l, int r, int x, lint y, lint seg[]) {
//if(idx == 1) printf("updseg(x = %d, y = %lld)\n", x, y);
seg[idx] += y;
if(l < r) {
int m = (l + r) / 2;
if(x <= m) updseg(idx * 2, l, m, x, y, seg);
else updseg(idx * 2 + 1, m + 1, r, x, y, seg);
}
}
void print(int idx, int l, int r, lint x, lint y) {
if(l == r) printf("%lld\n", (y + segY[idx] - x - segX[idx]) / 2);
else {
int m = (l + r) / 2;
print(idx * 2, l, m, x, y);
print(idx * 2 + 1, m + 1, r, x + segX[idx * 2], y + segY[idx * 2]);
}
}
int main() {
int N, Q;
lint x0 = 0ll;
scanf("%d%d", &N, &Q);
for(int i = 0; i < Q; i++) scanf("%lld%d%lld", X + i, D + i, L + i);
mkseg(1, 0, N - 1, segX);
mkseg(1, 0, N - 1, segY);
for(int i = Q - 1; i >= 0; i--) {
if(D[i] == 1) {
int t = lb(1, 0, N - 1, X[i] + 1, segY);
if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segX);
x0 -= 2 * L[i];
}
else {
int t = lb(1, 0, N - 1, X[i] + 1 - x0, segX);
if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segY);
}
//for(int i = 1; i < 26; i++) printf("i = %d, segX = %lld, segY = %lld\n", i, segX[i], segY[i]);
//printf("\n");
}
print(1, 0, N - 1, x0, 0);
return 0;
}
Compilation message (stderr)
2016_ho_t5.cpp: In function 'int main()':
2016_ho_t5.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~
2016_ho_t5.cpp:52:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 0; i < Q; i++) scanf("%lld%d%lld", X + i, D + i, L + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |