Submission #126319

# Submission time Handle Problem Language Result Execution time Memory
126319 2019-07-07T11:46:49 Z imyujin None (JOI16_ho_t5) C++14
100 / 100
145 ms 15736 KB
#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 ub(int idx, int l, int r, lint x, lint seg[]) {
	if(seg[idx] <= x) return r + 1;
	if(x < 0 || l == r) return l;
	int m = (l + r) / 2;
	return x < seg[idx * 2] ? ub(idx * 2, l, m, x, seg) : ub(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[]) {
	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 = ub(1, 0, N - 1, X[i], segY);
			if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segX);
			x0 -= 2 * L[i];
		}
		else {
			int t = ub(1, 0, N - 1, X[i] - x0, segX);
			if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segY);
		}
	}

	print(1, 0, N - 1, x0, 0);
	return 0;
}

Compilation message

2016_ho_t5.cpp: In function 'int main()':
2016_ho_t5.cpp:49: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:50: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
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 624 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 532 KB Output is correct
39 Correct 4 ms 632 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 4 ms 632 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 4 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 3 ms 632 KB Output is correct
47 Correct 3 ms 632 KB Output is correct
48 Correct 3 ms 632 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 4 ms 632 KB Output is correct
51 Correct 3 ms 632 KB Output is correct
52 Correct 4 ms 632 KB Output is correct
53 Correct 3 ms 632 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 4 ms 636 KB Output is correct
56 Correct 4 ms 636 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 504 KB Output is correct
59 Correct 3 ms 632 KB Output is correct
60 Correct 4 ms 632 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 632 KB Output is correct
65 Correct 3 ms 632 KB Output is correct
66 Correct 3 ms 504 KB Output is correct
67 Correct 3 ms 632 KB Output is correct
68 Correct 3 ms 632 KB Output is correct
69 Correct 3 ms 504 KB Output is correct
70 Correct 2 ms 504 KB Output is correct
71 Correct 2 ms 504 KB Output is correct
72 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 4 ms 624 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 532 KB Output is correct
39 Correct 4 ms 632 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 4 ms 632 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 4 ms 632 KB Output is correct
44 Correct 4 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 3 ms 632 KB Output is correct
47 Correct 3 ms 632 KB Output is correct
48 Correct 3 ms 632 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 4 ms 632 KB Output is correct
51 Correct 3 ms 632 KB Output is correct
52 Correct 4 ms 632 KB Output is correct
53 Correct 3 ms 632 KB Output is correct
54 Correct 4 ms 632 KB Output is correct
55 Correct 4 ms 636 KB Output is correct
56 Correct 4 ms 636 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 504 KB Output is correct
59 Correct 3 ms 632 KB Output is correct
60 Correct 4 ms 632 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 632 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 632 KB Output is correct
65 Correct 3 ms 632 KB Output is correct
66 Correct 3 ms 504 KB Output is correct
67 Correct 3 ms 632 KB Output is correct
68 Correct 3 ms 632 KB Output is correct
69 Correct 3 ms 504 KB Output is correct
70 Correct 2 ms 504 KB Output is correct
71 Correct 2 ms 504 KB Output is correct
72 Correct 2 ms 504 KB Output is correct
73 Correct 139 ms 13752 KB Output is correct
74 Correct 143 ms 13756 KB Output is correct
75 Correct 143 ms 14068 KB Output is correct
76 Correct 137 ms 13968 KB Output is correct
77 Correct 136 ms 13884 KB Output is correct
78 Correct 137 ms 14088 KB Output is correct
79 Correct 139 ms 13984 KB Output is correct
80 Correct 119 ms 14072 KB Output is correct
81 Correct 108 ms 14164 KB Output is correct
82 Correct 108 ms 14200 KB Output is correct
83 Correct 112 ms 14352 KB Output is correct
84 Correct 115 ms 14328 KB Output is correct
85 Correct 113 ms 14328 KB Output is correct
86 Correct 118 ms 14532 KB Output is correct
87 Correct 122 ms 14968 KB Output is correct
88 Correct 130 ms 15580 KB Output is correct
89 Correct 129 ms 15608 KB Output is correct
90 Correct 128 ms 15632 KB Output is correct
91 Correct 100 ms 13820 KB Output is correct
92 Correct 101 ms 13944 KB Output is correct
93 Correct 142 ms 15304 KB Output is correct
94 Correct 117 ms 13816 KB Output is correct
95 Correct 133 ms 14968 KB Output is correct
96 Correct 118 ms 13816 KB Output is correct
97 Correct 121 ms 14348 KB Output is correct
98 Correct 122 ms 13816 KB Output is correct
99 Correct 135 ms 14776 KB Output is correct
100 Correct 121 ms 13816 KB Output is correct
101 Correct 119 ms 14512 KB Output is correct
102 Correct 120 ms 13920 KB Output is correct
103 Correct 131 ms 14840 KB Output is correct
104 Correct 116 ms 13752 KB Output is correct
105 Correct 122 ms 14712 KB Output is correct
106 Correct 113 ms 13944 KB Output is correct
107 Correct 119 ms 14728 KB Output is correct
108 Correct 124 ms 13816 KB Output is correct
109 Correct 111 ms 14584 KB Output is correct
110 Correct 103 ms 13792 KB Output is correct
111 Correct 127 ms 15288 KB Output is correct
112 Correct 112 ms 13816 KB Output is correct
113 Correct 132 ms 15736 KB Output is correct
114 Correct 110 ms 13816 KB Output is correct
115 Correct 111 ms 14200 KB Output is correct
116 Correct 115 ms 13960 KB Output is correct
117 Correct 132 ms 15484 KB Output is correct
118 Correct 145 ms 13944 KB Output is correct
119 Correct 37 ms 10776 KB Output is correct
120 Correct 32 ms 8952 KB Output is correct