#include <stdio.h>
#define N 200000
#define M 200000
#define Q 200000
#define M_ (M * 3 + 2)
#define INF 0x3f3f3f3f3f3f3f3fLL
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int zz[M_], ll[M_], rr[M_], ii[M_], jj[M_], u_, l_, r_; long long xx[M_];
int node(int l, int r, long long x) {
static int _ = 1;
zz[_] = rand_();
ii[_] = l, jj[_] = r, xx[_] = x;
return _++;
}
void split_i(int u, int i) {
if (u == 0) {
u_ = l_ = r_ = 0;
return;
}
if (ii[u] <= i) {
split_i(rr[u], i);
rr[u] = l_, l_ = u;
} else {
split_i(ll[u], i);
ll[u] = r_, r_ = u;
}
}
void split_j(int u, int i) {
if (u == 0) {
u_ = l_ = r_ = 0;
return;
}
if (jj[u] <= i) {
split_j(rr[u], i);
rr[u] = l_, l_ = u;
} else {
split_j(ll[u], i);
ll[u] = r_, r_ = u;
}
}
int merge(int u, int v) {
if (u == 0)
return v;
if (v == 0)
return u;
if (zz[u] < zz[v]) {
rr[u] = merge(rr[u], v);
return u;
} else {
ll[v] = merge(u, ll[v]);
return v;
}
}
int first(int u) {
return ll[u] == 0 ? u : first(ll[u]);
}
int last(int u) {
return rr[u] == 0 ? u : last(rr[u]);
}
long long tt[M_]; int ww[M_], m_;
void add_segments(int u, int i, int j, long long x) {
if (u == 0)
return;
add_segments(ll[u], i, j, x);
tt[m_] = xx[u] == -INF ? 0 : x - xx[u], ww[m_] = max(min(j, jj[u]) - max(i, ii[u]) + 1, 0), m_++;
add_segments(rr[u], i, j, x);
}
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k)
if (tt[hh[j]] == tt[h])
j++;
else if (tt[hh[j]] < tt[h]) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
sort(hh, l, i);
l = k;
}
}
int main() {
static int hh[M_];
static long long kk[M_ + 1];
int n, m, q, h, i, j;
long long k;
scanf("%d%d%d", &n, &m, &q);
k = 0, u_ = node(0, n - 1, -INF);
while (m--) {
int l, m, m_, r, u;
scanf("%d%d", &i, &j), i--, j--;
split_j(u_, i - 1), l = l_;
split_i(r_, j), m = l_, r = r_;
add_segments(m, i, j, k - i);
m_ = node(i, j, k - i);
if (ii[u = first(m)] < i)
m_ = merge(node(ii[u], i - 1, xx[u]), m_);
if (jj[u = last(m)] > j)
m_ = merge(m_, node(j + 1, jj[u], xx[u]));
u_ = merge(merge(l, m_), r);
k += j - i + 1;
}
for (h = 0; h < m_; h++)
hh[h] = h;
sort(hh, 0, m_);
kk[0] = k;
for (h = 0; h < m_; h++)
kk[h + 1] = kk[h] - ww[hh[h]];
while (q--) {
long long t;
int lower, upper;
scanf("%lld", &t);
lower = -1, upper = m_;
while (upper - lower > 1) {
h = (lower + upper) / 2;
if (tt[hh[h]] <= t)
lower = h;
else
upper = h;
}
printf("%lld ", kk[upper]);
}
printf("\n");
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:113:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | scanf("%d%d%d", &n, &m, &q);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:118:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | scanf("%d%d", &i, &j), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:140:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
140 | scanf("%lld", &t);
| ^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
50 ms |
2528 KB |
Output is correct |
14 |
Correct |
47 ms |
2228 KB |
Output is correct |
15 |
Correct |
51 ms |
2432 KB |
Output is correct |
16 |
Correct |
49 ms |
2588 KB |
Output is correct |
17 |
Correct |
50 ms |
2508 KB |
Output is correct |
18 |
Correct |
51 ms |
2468 KB |
Output is correct |
19 |
Correct |
63 ms |
2660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
51 ms |
2428 KB |
Output is correct |
4 |
Correct |
51 ms |
3040 KB |
Output is correct |
5 |
Correct |
192 ms |
25592 KB |
Output is correct |
6 |
Correct |
168 ms |
25228 KB |
Output is correct |
7 |
Correct |
164 ms |
17680 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
50 ms |
2528 KB |
Output is correct |
14 |
Correct |
47 ms |
2228 KB |
Output is correct |
15 |
Correct |
51 ms |
2432 KB |
Output is correct |
16 |
Correct |
49 ms |
2588 KB |
Output is correct |
17 |
Correct |
50 ms |
2508 KB |
Output is correct |
18 |
Correct |
51 ms |
2468 KB |
Output is correct |
19 |
Correct |
63 ms |
2660 KB |
Output is correct |
20 |
Correct |
57 ms |
3716 KB |
Output is correct |
21 |
Correct |
48 ms |
2984 KB |
Output is correct |
22 |
Correct |
59 ms |
3660 KB |
Output is correct |
23 |
Correct |
55 ms |
2568 KB |
Output is correct |
24 |
Correct |
48 ms |
2428 KB |
Output is correct |
25 |
Correct |
50 ms |
3064 KB |
Output is correct |
26 |
Correct |
58 ms |
3608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
288 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
284 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
50 ms |
2528 KB |
Output is correct |
14 |
Correct |
47 ms |
2228 KB |
Output is correct |
15 |
Correct |
51 ms |
2432 KB |
Output is correct |
16 |
Correct |
49 ms |
2588 KB |
Output is correct |
17 |
Correct |
50 ms |
2508 KB |
Output is correct |
18 |
Correct |
51 ms |
2468 KB |
Output is correct |
19 |
Correct |
63 ms |
2660 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
51 ms |
2428 KB |
Output is correct |
23 |
Correct |
51 ms |
3040 KB |
Output is correct |
24 |
Correct |
192 ms |
25592 KB |
Output is correct |
25 |
Correct |
168 ms |
25228 KB |
Output is correct |
26 |
Correct |
164 ms |
17680 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
57 ms |
3716 KB |
Output is correct |
30 |
Correct |
48 ms |
2984 KB |
Output is correct |
31 |
Correct |
59 ms |
3660 KB |
Output is correct |
32 |
Correct |
55 ms |
2568 KB |
Output is correct |
33 |
Correct |
48 ms |
2428 KB |
Output is correct |
34 |
Correct |
50 ms |
3064 KB |
Output is correct |
35 |
Correct |
58 ms |
3608 KB |
Output is correct |
36 |
Correct |
305 ms |
36244 KB |
Output is correct |
37 |
Correct |
261 ms |
36572 KB |
Output is correct |
38 |
Correct |
226 ms |
36224 KB |
Output is correct |
39 |
Correct |
144 ms |
25420 KB |
Output is correct |
40 |
Correct |
206 ms |
35824 KB |
Output is correct |
41 |
Correct |
214 ms |
35012 KB |
Output is correct |
42 |
Correct |
203 ms |
34712 KB |
Output is correct |
43 |
Correct |
186 ms |
31564 KB |
Output is correct |
44 |
Correct |
188 ms |
31516 KB |
Output is correct |
45 |
Correct |
243 ms |
35696 KB |
Output is correct |
46 |
Correct |
357 ms |
32548 KB |
Output is correct |
47 |
Correct |
300 ms |
32716 KB |
Output is correct |
48 |
Correct |
219 ms |
36532 KB |
Output is correct |