Submission #106776

# Submission time Handle Problem Language Result Execution time Memory
106776 2019-04-20T12:41:53 Z eriksuenderhauf Two Antennas (JOI19_antennas) C++11
100 / 100
935 ms 55284 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 2e9;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
ll h[MAXN], ans[MAXN];
int a[MAXN], b[MAXN];
pair<pii,int> qr[MAXN];
pll seg1[MAXN*4], lazy[MAXN*4];
ll seg2[MAXN*4];
int n;
vi arr[2][MAXN];

void build(int l, int r, int k) {
	seg1[k] = {INF, -INF};
	lazy[k] = {INF, -INF};
	seg2[k] = -1;
	if (l == r)
		return;
	int m = (l + r) / 2;
	build(l, m, k*2);
	build(m+1, r, k*2+1);
}

void prop(int l, int r, int k) {
	if (l != r) {
		lazy[k*2].fi = min(lazy[k*2].fi, lazy[k].fi);
		lazy[k*2].se = max(lazy[k*2].se, lazy[k].se);
		lazy[k*2+1].fi = min(lazy[k*2+1].fi, lazy[k].fi);
		lazy[k*2+1].se = max(lazy[k*2+1].se, lazy[k].se);
	}
	lazy[k] = {INF, -INF};
}

void upd1(int l, int r, int k, int x, pll val) {
	if (lazy[k] != mp(INF, -INF)) {
		seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi));
		prop(l, r, k);
	}
	if (r < x || x < l) return;
	if (x <= l && r <= x) {
		seg1[k] = val;
		return;
	}
	int m = (l + r) / 2;
	upd1(l, m, k*2, x, val);
	upd1(m+1, r, k*2+1, x, val);
	seg1[k].fi = min(seg1[k*2].fi, seg1[k*2+1].fi);
	seg1[k].se = max(seg1[k*2].se, seg1[k*2+1].se);
}

void upd2(int l, int r, int k, int x, int y, ll val) {
	if (lazy[k] != mp(INF, -INF)) {
		seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi));
		prop(l, r, k);
	}
	if (r < x || y < l || y < x) return;
	if (x <= l && r <= y) {
		seg2[k] = max(seg2[k], max(val - seg1[k].fi, seg1[k].se - val));
		lazy[k] = mp(val, val);
		prop(l, r, k);
		return;
	}
	int m = (l + r) / 2;
	upd2(l, m, k*2, x, y, val);
	upd2(m+1, r, k*2+1, x, y, val);
	seg2[k] = max(seg2[k*2], seg2[k*2+1]);
}

ll qry(int l, int r, int k, int x, int y) {
	if (r < x || y < l || y < x) return -1;
	if (lazy[k] != mp(INF, -INF)) {
		seg2[k] = max(seg2[k], max(lazy[k].se - seg1[k].fi, seg1[k].se - lazy[k].fi));
		prop(l, r, k);
	}
	if (x <= l && r <= y)
		return seg2[k];
	int m = (l + r) / 2;
	return max(qry(l, m, k*2, x, y), qry(m+1, r, k*2+1, x, y));
}

void ins(int ind) {
	int lo = max(1, ind - b[ind]), hi = max(0, ind - a[ind]);
	for (int nx: arr[0][ind])
		upd1(1, n, 1, nx, mp(h[nx], h[nx]));
	for (int nx: arr[1][ind])
		upd1(1, n, 1, nx, mp(INF, -INF));
	upd2(1, n, 1, lo, hi, h[ind]);
	lo = min(n + 1, ind + a[ind]);
	hi = min(n, ind + b[ind]);
	arr[0][lo].pb(ind);
	arr[1][hi + 1].pb(ind);
}

int main() {
	int q;
	ni(n);
	for (int i = 1; i <= 4 * n; i++) {
		seg1[i] = {INF, -INF};
		lazy[i] = {INF, -INF};
		seg2[i] = -1;
	}
	for (int i = 1; i <= n; i++)
		scanf("%d %d %d", &h[i], &a[i], &b[i]);
	ni(q);
	for (int i = 1; i <= q; i++) {
		scanf("%d %d", &qr[i].fi.fi, &qr[i].fi.se);
		qr[i].se = i;
	}
	sort(qr+1, qr+1+ q, [](pair<pii,int> l, pair<pii,int> r) {
		return l.fi.se < r.fi.se;
	});
	int cur = 1;
	for (int i = 1; i <= q; i++) {
		while (cur <= qr[i].fi.se)
			ins(cur++);
		ans[qr[i].se] = qry(1, n, 1, qr[i].fi.fi, qr[i].fi.se);
	}
	for (int i = 1; i <= q; i++)
		pri(ans[i]);
    return 0;
}

Compilation message

antennas.cpp: In function 'int main()':
antennas.cpp:134:40: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll* {aka long long int*}' [-Wformat=]
   scanf("%d %d %d", &h[i], &a[i], &b[i]);
                     ~~~~~              ^
antennas.cpp:12:34: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
 #define pri(n) printf("%d\n", (n))
                               ~~~^
antennas.cpp:150:3: note: in expansion of macro 'pri'
   pri(ans[i]);
   ^~~
antennas.cpp:8:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
antennas.cpp:127:2: note: in expansion of macro 'ni'
  ni(n);
  ^~
antennas.cpp:134:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &h[i], &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:8:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
antennas.cpp:135:2: note: in expansion of macro 'ni'
  ni(q);
  ^~
antennas.cpp:137:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &qr[i].fi.fi, &qr[i].fi.se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9856 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 11 ms 9856 KB Output is correct
4 Correct 11 ms 9856 KB Output is correct
5 Correct 11 ms 9852 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 12 ms 9856 KB Output is correct
8 Correct 15 ms 9856 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 12 ms 9856 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 11 ms 9856 KB Output is correct
13 Correct 12 ms 9856 KB Output is correct
14 Correct 14 ms 9856 KB Output is correct
15 Correct 12 ms 9856 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 14 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 11 ms 9856 KB Output is correct
23 Correct 11 ms 9856 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9856 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 11 ms 9856 KB Output is correct
4 Correct 11 ms 9856 KB Output is correct
5 Correct 11 ms 9852 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 12 ms 9856 KB Output is correct
8 Correct 15 ms 9856 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 12 ms 9856 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 11 ms 9856 KB Output is correct
13 Correct 12 ms 9856 KB Output is correct
14 Correct 14 ms 9856 KB Output is correct
15 Correct 12 ms 9856 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 14 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 11 ms 9856 KB Output is correct
23 Correct 11 ms 9856 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
25 Correct 118 ms 14448 KB Output is correct
26 Correct 24 ms 10752 KB Output is correct
27 Correct 188 ms 16100 KB Output is correct
28 Correct 188 ms 16248 KB Output is correct
29 Correct 156 ms 14456 KB Output is correct
30 Correct 155 ms 14456 KB Output is correct
31 Correct 139 ms 15580 KB Output is correct
32 Correct 174 ms 16120 KB Output is correct
33 Correct 145 ms 15824 KB Output is correct
34 Correct 94 ms 13236 KB Output is correct
35 Correct 170 ms 16088 KB Output is correct
36 Correct 184 ms 16120 KB Output is correct
37 Correct 128 ms 13252 KB Output is correct
38 Correct 158 ms 15212 KB Output is correct
39 Correct 35 ms 11000 KB Output is correct
40 Correct 163 ms 15224 KB Output is correct
41 Correct 116 ms 13944 KB Output is correct
42 Correct 172 ms 15312 KB Output is correct
43 Correct 53 ms 12028 KB Output is correct
44 Correct 172 ms 15208 KB Output is correct
45 Correct 45 ms 11256 KB Output is correct
46 Correct 185 ms 15220 KB Output is correct
47 Correct 48 ms 11640 KB Output is correct
48 Correct 161 ms 15188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 45540 KB Output is correct
2 Correct 550 ms 49388 KB Output is correct
3 Correct 385 ms 37488 KB Output is correct
4 Correct 509 ms 49520 KB Output is correct
5 Correct 203 ms 28272 KB Output is correct
6 Correct 527 ms 49776 KB Output is correct
7 Correct 399 ms 44152 KB Output is correct
8 Correct 548 ms 49776 KB Output is correct
9 Correct 85 ms 16380 KB Output is correct
10 Correct 543 ms 49648 KB Output is correct
11 Correct 310 ms 34804 KB Output is correct
12 Correct 554 ms 49776 KB Output is correct
13 Correct 301 ms 46792 KB Output is correct
14 Correct 242 ms 47428 KB Output is correct
15 Correct 265 ms 46816 KB Output is correct
16 Correct 223 ms 47172 KB Output is correct
17 Correct 296 ms 46820 KB Output is correct
18 Correct 283 ms 47368 KB Output is correct
19 Correct 258 ms 46788 KB Output is correct
20 Correct 291 ms 46828 KB Output is correct
21 Correct 229 ms 46944 KB Output is correct
22 Correct 230 ms 47216 KB Output is correct
23 Correct 226 ms 46704 KB Output is correct
24 Correct 217 ms 46836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9856 KB Output is correct
2 Correct 11 ms 9856 KB Output is correct
3 Correct 11 ms 9856 KB Output is correct
4 Correct 11 ms 9856 KB Output is correct
5 Correct 11 ms 9852 KB Output is correct
6 Correct 13 ms 9856 KB Output is correct
7 Correct 12 ms 9856 KB Output is correct
8 Correct 15 ms 9856 KB Output is correct
9 Correct 12 ms 9728 KB Output is correct
10 Correct 12 ms 9856 KB Output is correct
11 Correct 12 ms 9856 KB Output is correct
12 Correct 11 ms 9856 KB Output is correct
13 Correct 12 ms 9856 KB Output is correct
14 Correct 14 ms 9856 KB Output is correct
15 Correct 12 ms 9856 KB Output is correct
16 Correct 13 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 12 ms 9856 KB Output is correct
19 Correct 14 ms 9856 KB Output is correct
20 Correct 10 ms 9856 KB Output is correct
21 Correct 11 ms 9856 KB Output is correct
22 Correct 11 ms 9856 KB Output is correct
23 Correct 11 ms 9856 KB Output is correct
24 Correct 12 ms 9856 KB Output is correct
25 Correct 118 ms 14448 KB Output is correct
26 Correct 24 ms 10752 KB Output is correct
27 Correct 188 ms 16100 KB Output is correct
28 Correct 188 ms 16248 KB Output is correct
29 Correct 156 ms 14456 KB Output is correct
30 Correct 155 ms 14456 KB Output is correct
31 Correct 139 ms 15580 KB Output is correct
32 Correct 174 ms 16120 KB Output is correct
33 Correct 145 ms 15824 KB Output is correct
34 Correct 94 ms 13236 KB Output is correct
35 Correct 170 ms 16088 KB Output is correct
36 Correct 184 ms 16120 KB Output is correct
37 Correct 128 ms 13252 KB Output is correct
38 Correct 158 ms 15212 KB Output is correct
39 Correct 35 ms 11000 KB Output is correct
40 Correct 163 ms 15224 KB Output is correct
41 Correct 116 ms 13944 KB Output is correct
42 Correct 172 ms 15312 KB Output is correct
43 Correct 53 ms 12028 KB Output is correct
44 Correct 172 ms 15208 KB Output is correct
45 Correct 45 ms 11256 KB Output is correct
46 Correct 185 ms 15220 KB Output is correct
47 Correct 48 ms 11640 KB Output is correct
48 Correct 161 ms 15188 KB Output is correct
49 Correct 519 ms 45540 KB Output is correct
50 Correct 550 ms 49388 KB Output is correct
51 Correct 385 ms 37488 KB Output is correct
52 Correct 509 ms 49520 KB Output is correct
53 Correct 203 ms 28272 KB Output is correct
54 Correct 527 ms 49776 KB Output is correct
55 Correct 399 ms 44152 KB Output is correct
56 Correct 548 ms 49776 KB Output is correct
57 Correct 85 ms 16380 KB Output is correct
58 Correct 543 ms 49648 KB Output is correct
59 Correct 310 ms 34804 KB Output is correct
60 Correct 554 ms 49776 KB Output is correct
61 Correct 301 ms 46792 KB Output is correct
62 Correct 242 ms 47428 KB Output is correct
63 Correct 265 ms 46816 KB Output is correct
64 Correct 223 ms 47172 KB Output is correct
65 Correct 296 ms 46820 KB Output is correct
66 Correct 283 ms 47368 KB Output is correct
67 Correct 258 ms 46788 KB Output is correct
68 Correct 291 ms 46828 KB Output is correct
69 Correct 229 ms 46944 KB Output is correct
70 Correct 230 ms 47216 KB Output is correct
71 Correct 226 ms 46704 KB Output is correct
72 Correct 217 ms 46836 KB Output is correct
73 Correct 779 ms 49996 KB Output is correct
74 Correct 551 ms 50032 KB Output is correct
75 Correct 623 ms 43416 KB Output is correct
76 Correct 935 ms 55144 KB Output is correct
77 Correct 465 ms 32772 KB Output is correct
78 Correct 779 ms 53280 KB Output is correct
79 Correct 750 ms 49988 KB Output is correct
80 Correct 933 ms 55176 KB Output is correct
81 Correct 276 ms 22008 KB Output is correct
82 Correct 795 ms 52232 KB Output is correct
83 Correct 579 ms 40532 KB Output is correct
84 Correct 878 ms 55284 KB Output is correct
85 Correct 419 ms 49348 KB Output is correct
86 Correct 570 ms 51624 KB Output is correct
87 Correct 310 ms 47528 KB Output is correct
88 Correct 538 ms 52008 KB Output is correct
89 Correct 453 ms 50264 KB Output is correct
90 Correct 541 ms 51864 KB Output is correct
91 Correct 361 ms 48508 KB Output is correct
92 Correct 594 ms 51380 KB Output is correct
93 Correct 292 ms 47748 KB Output is correct
94 Correct 484 ms 51444 KB Output is correct
95 Correct 373 ms 47984 KB Output is correct
96 Correct 476 ms 51448 KB Output is correct