Submission #126317

# Submission time Handle Problem Language Result Execution time Memory
126317 2019-07-07T11:44:56 Z imyujin None (JOI16_ho_t5) C++14
100 / 100
143 ms 19832 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 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

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
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 380 KB Output is correct
11 Correct 2 ms 380 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 376 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 380 KB Output is correct
11 Correct 2 ms 380 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 376 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 632 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 484 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 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 4 ms 632 KB Output is correct
47 Correct 4 ms 632 KB Output is correct
48 Correct 4 ms 632 KB Output is correct
49 Correct 4 ms 632 KB Output is correct
50 Correct 4 ms 632 KB Output is correct
51 Correct 3 ms 504 KB Output is correct
52 Correct 4 ms 632 KB Output is correct
53 Correct 4 ms 504 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 504 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 4 ms 632 KB Output is correct
59 Correct 3 ms 524 KB Output is correct
60 Correct 4 ms 632 KB Output is correct
61 Correct 3 ms 632 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 508 KB Output is correct
64 Correct 3 ms 504 KB Output is correct
65 Correct 3 ms 504 KB Output is correct
66 Correct 4 ms 632 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 632 KB Output is correct
70 Correct 2 ms 504 KB Output is correct
71 Correct 3 ms 504 KB Output is correct
72 Correct 3 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 380 KB Output is correct
11 Correct 2 ms 380 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 376 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 632 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 484 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 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 4 ms 632 KB Output is correct
47 Correct 4 ms 632 KB Output is correct
48 Correct 4 ms 632 KB Output is correct
49 Correct 4 ms 632 KB Output is correct
50 Correct 4 ms 632 KB Output is correct
51 Correct 3 ms 504 KB Output is correct
52 Correct 4 ms 632 KB Output is correct
53 Correct 4 ms 504 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 504 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 4 ms 632 KB Output is correct
59 Correct 3 ms 524 KB Output is correct
60 Correct 4 ms 632 KB Output is correct
61 Correct 3 ms 632 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 508 KB Output is correct
64 Correct 3 ms 504 KB Output is correct
65 Correct 3 ms 504 KB Output is correct
66 Correct 4 ms 632 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 632 KB Output is correct
70 Correct 2 ms 504 KB Output is correct
71 Correct 3 ms 504 KB Output is correct
72 Correct 3 ms 504 KB Output is correct
73 Correct 138 ms 15800 KB Output is correct
74 Correct 143 ms 15736 KB Output is correct
75 Correct 141 ms 15992 KB Output is correct
76 Correct 138 ms 15932 KB Output is correct
77 Correct 137 ms 15992 KB Output is correct
78 Correct 140 ms 16120 KB Output is correct
79 Correct 141 ms 16248 KB Output is correct
80 Correct 119 ms 16376 KB Output is correct
81 Correct 108 ms 16544 KB Output is correct
82 Correct 107 ms 16728 KB Output is correct
83 Correct 111 ms 17304 KB Output is correct
84 Correct 111 ms 17400 KB Output is correct
85 Correct 111 ms 17404 KB Output is correct
86 Correct 117 ms 17896 KB Output is correct
87 Correct 119 ms 18552 KB Output is correct
88 Correct 130 ms 19784 KB Output is correct
89 Correct 129 ms 19832 KB Output is correct
90 Correct 124 ms 18168 KB Output is correct
91 Correct 99 ms 14872 KB Output is correct
92 Correct 99 ms 15028 KB Output is correct
93 Correct 138 ms 18552 KB Output is correct
94 Correct 115 ms 15864 KB Output is correct
95 Correct 143 ms 17840 KB Output is correct
96 Correct 115 ms 15772 KB Output is correct
97 Correct 120 ms 16764 KB Output is correct
98 Correct 120 ms 15716 KB Output is correct
99 Correct 133 ms 17528 KB Output is correct
100 Correct 118 ms 15736 KB Output is correct
101 Correct 118 ms 16952 KB Output is correct
102 Correct 117 ms 15864 KB Output is correct
103 Correct 131 ms 17608 KB Output is correct
104 Correct 115 ms 15684 KB Output is correct
105 Correct 119 ms 17272 KB Output is correct
106 Correct 111 ms 15788 KB Output is correct
107 Correct 116 ms 17472 KB Output is correct
108 Correct 118 ms 15668 KB Output is correct
109 Correct 111 ms 17124 KB Output is correct
110 Correct 102 ms 15908 KB Output is correct
111 Correct 126 ms 18808 KB Output is correct
112 Correct 104 ms 15912 KB Output is correct
113 Correct 131 ms 19100 KB Output is correct
114 Correct 108 ms 15872 KB Output is correct
115 Correct 110 ms 16376 KB Output is correct
116 Correct 109 ms 16060 KB Output is correct
117 Correct 131 ms 19192 KB Output is correct
118 Correct 108 ms 15920 KB Output is correct
119 Correct 37 ms 10744 KB Output is correct
120 Correct 30 ms 8972 KB Output is correct