Submission #127425

# Submission time Handle Problem Language Result Execution time Memory
127425 2019-07-09T11:14:24 Z ainta None (JOI16_ho_t5) C++17
100 / 100
229 ms 29568 KB
#include<cstdio>
#include<algorithm>
#define SZ 262144
using namespace std;
long long R[SZ][2];
struct Tree {
	long long Mx[SZ + SZ], K[SZ + SZ];
	void UDT(int nd) {
		Mx[nd] = max(Mx[nd * 2], Mx[nd * 2 + 1]);
	}
	void init(int nd, int b, int e) {
		if (b == e) {
			Mx[nd] = b;
			return;
		}
		int m = (b + e) >> 1;
		init(nd * 2, b, m);
		init(nd * 2 + 1, m + 1, e);
		UDT(nd);
	}
	void Add2(int nd, long long x) {
		Mx[nd] += x;
		K[nd] += x;
	}
	void Spread(int nd) {
		Add2(nd*2, K[nd]);
		Add2(nd*2+1, K[nd]);
		K[nd] = 0;
	}
	void Add(int nd, int b, int e, int s, int l, int x) {
		if (s > l)return;
		if (s <= b && e <= l) {
			Add2(nd, x);
			return;
		}
		Spread(nd);
		int m = (b + e) >> 1;
		if (s <= m)Add(nd*2, b, m, s, l, x);
		if (l > m)Add(nd * 2 + 1, m + 1, e, s, l, x);
		UDT(nd);
	}
	int First(int nd, int b, int e, long long K) {
		if (Mx[nd] < K)return e + 1;
		if (b == e)return b;
		Spread(nd);
		int m = (b + e) >> 1;
		if (Mx[nd * 2] >= K)return First(nd * 2, b, m, K);
		return First(nd * 2 + 1, m + 1, e, K);
	}
	void Print(int nd, int b, int e, int ck) {
		if (b == e) {
			R[b][ck] = Mx[nd];
			return;
		}
		Spread(nd);
		int m = (b + e) >> 1;
		Print(nd * 2, b, m, ck);
		Print(nd * 2 + 1, m + 1, e, ck);
	}
}XMY, XPY;
int n, Q;
struct AA {
	int x, ck, l;
}U[SZ];
int main() {
	int i;
	scanf("%d%d", &n, &Q);
	XMY.init(1, 0, n - 1);
	XPY.init(1, 0, n - 1);
	for (i = 1; i <= Q; i++)scanf("%d%d%d", &U[i].x, &U[i].ck, &U[i].l);
	for (i = Q; i >= 1; i--) {
		int x, ck, l;
		x = U[i].x, ck = U[i].ck, l = U[i].l;
		if (ck == 1) {
			//x--;
			int t = XMY.First(1, 0, n - 1, x);
			XPY.Add(1, 0, n - 1, 0, t - 1, -2*l);
		}
		else {
			int t = XPY.First(1, 0, n - 1, x);
			XMY.Add(1, 0, n - 1, t, n - 1, 2*l);
		}
	}
	XMY.Print(1, 0, n - 1, 0);
	XPY.Print(1, 0, n - 1, 1);
	for (i = 0; i < n; i++)printf("%lld\n", -(R[i][1] - R[i][0]) / 2);
}

Compilation message

2016_ho_t5.cpp: In function 'int main()':
2016_ho_t5.cpp:67: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:70:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= Q; i++)scanf("%d%d%d", &U[i].x, &U[i].ck, &U[i].l);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 388 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 352 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 388 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 352 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 4 ms 760 KB Output is correct
31 Correct 4 ms 764 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 4 ms 760 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 4 ms 760 KB Output is correct
38 Correct 4 ms 760 KB Output is correct
39 Correct 4 ms 760 KB Output is correct
40 Correct 4 ms 732 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 4 ms 888 KB Output is correct
44 Correct 4 ms 764 KB Output is correct
45 Correct 4 ms 760 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 4 ms 760 KB Output is correct
48 Correct 4 ms 760 KB Output is correct
49 Correct 4 ms 760 KB Output is correct
50 Correct 4 ms 760 KB Output is correct
51 Correct 4 ms 760 KB Output is correct
52 Correct 4 ms 760 KB Output is correct
53 Correct 4 ms 760 KB Output is correct
54 Correct 4 ms 760 KB Output is correct
55 Correct 4 ms 760 KB Output is correct
56 Correct 4 ms 760 KB Output is correct
57 Correct 4 ms 760 KB Output is correct
58 Correct 4 ms 760 KB Output is correct
59 Correct 4 ms 760 KB Output is correct
60 Correct 4 ms 760 KB Output is correct
61 Correct 4 ms 788 KB Output is correct
62 Correct 4 ms 760 KB Output is correct
63 Correct 4 ms 760 KB Output is correct
64 Correct 4 ms 760 KB Output is correct
65 Correct 3 ms 760 KB Output is correct
66 Correct 4 ms 760 KB Output is correct
67 Correct 4 ms 760 KB Output is correct
68 Correct 4 ms 760 KB Output is correct
69 Correct 4 ms 760 KB Output is correct
70 Correct 2 ms 632 KB Output is correct
71 Correct 2 ms 760 KB Output is correct
72 Correct 2 ms 632 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 388 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 352 KB Output is correct
28 Correct 4 ms 760 KB Output is correct
29 Correct 4 ms 760 KB Output is correct
30 Correct 4 ms 760 KB Output is correct
31 Correct 4 ms 764 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 4 ms 760 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 4 ms 760 KB Output is correct
37 Correct 4 ms 760 KB Output is correct
38 Correct 4 ms 760 KB Output is correct
39 Correct 4 ms 760 KB Output is correct
40 Correct 4 ms 732 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 4 ms 888 KB Output is correct
44 Correct 4 ms 764 KB Output is correct
45 Correct 4 ms 760 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 4 ms 760 KB Output is correct
48 Correct 4 ms 760 KB Output is correct
49 Correct 4 ms 760 KB Output is correct
50 Correct 4 ms 760 KB Output is correct
51 Correct 4 ms 760 KB Output is correct
52 Correct 4 ms 760 KB Output is correct
53 Correct 4 ms 760 KB Output is correct
54 Correct 4 ms 760 KB Output is correct
55 Correct 4 ms 760 KB Output is correct
56 Correct 4 ms 760 KB Output is correct
57 Correct 4 ms 760 KB Output is correct
58 Correct 4 ms 760 KB Output is correct
59 Correct 4 ms 760 KB Output is correct
60 Correct 4 ms 760 KB Output is correct
61 Correct 4 ms 788 KB Output is correct
62 Correct 4 ms 760 KB Output is correct
63 Correct 4 ms 760 KB Output is correct
64 Correct 4 ms 760 KB Output is correct
65 Correct 3 ms 760 KB Output is correct
66 Correct 4 ms 760 KB Output is correct
67 Correct 4 ms 760 KB Output is correct
68 Correct 4 ms 760 KB Output is correct
69 Correct 4 ms 760 KB Output is correct
70 Correct 2 ms 632 KB Output is correct
71 Correct 2 ms 760 KB Output is correct
72 Correct 2 ms 632 KB Output is correct
73 Correct 210 ms 25480 KB Output is correct
74 Correct 215 ms 25464 KB Output is correct
75 Correct 229 ms 25732 KB Output is correct
76 Correct 210 ms 25848 KB Output is correct
77 Correct 208 ms 25720 KB Output is correct
78 Correct 206 ms 25732 KB Output is correct
79 Correct 209 ms 25848 KB Output is correct
80 Correct 164 ms 26104 KB Output is correct
81 Correct 135 ms 26460 KB Output is correct
82 Correct 134 ms 26536 KB Output is correct
83 Correct 136 ms 27148 KB Output is correct
84 Correct 136 ms 27128 KB Output is correct
85 Correct 136 ms 27216 KB Output is correct
86 Correct 138 ms 27808 KB Output is correct
87 Correct 140 ms 28408 KB Output is correct
88 Correct 143 ms 29532 KB Output is correct
89 Correct 143 ms 29568 KB Output is correct
90 Correct 218 ms 28024 KB Output is correct
91 Correct 194 ms 24712 KB Output is correct
92 Correct 197 ms 24836 KB Output is correct
93 Correct 191 ms 28152 KB Output is correct
94 Correct 176 ms 25492 KB Output is correct
95 Correct 185 ms 27552 KB Output is correct
96 Correct 176 ms 25560 KB Output is correct
97 Correct 179 ms 26616 KB Output is correct
98 Correct 184 ms 25520 KB Output is correct
99 Correct 190 ms 27376 KB Output is correct
100 Correct 175 ms 25520 KB Output is correct
101 Correct 178 ms 26744 KB Output is correct
102 Correct 178 ms 25672 KB Output is correct
103 Correct 185 ms 27512 KB Output is correct
104 Correct 179 ms 25524 KB Output is correct
105 Correct 197 ms 27180 KB Output is correct
106 Correct 169 ms 25592 KB Output is correct
107 Correct 150 ms 27340 KB Output is correct
108 Correct 192 ms 25548 KB Output is correct
109 Correct 148 ms 26872 KB Output is correct
110 Correct 138 ms 25588 KB Output is correct
111 Correct 226 ms 28536 KB Output is correct
112 Correct 206 ms 25584 KB Output is correct
113 Correct 217 ms 28920 KB Output is correct
114 Correct 191 ms 25720 KB Output is correct
115 Correct 195 ms 26104 KB Output is correct
116 Correct 194 ms 25808 KB Output is correct
117 Correct 216 ms 28920 KB Output is correct
118 Correct 192 ms 25720 KB Output is correct
119 Correct 46 ms 22108 KB Output is correct
120 Correct 39 ms 20344 KB Output is correct