Intra AUST Programming Contest - Spring 2019, Exams of Computer science

Editorial of the problems of the contest Intra AUST Programming Contest - Spring 2019

Typology: Exams

2019/2020

Uploaded on 08/08/2021

gray-tourist
gray-tourist 🇧🇩

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Copy and Replace
Tag: Segment tree, Sparse table, Lazy propagation
-Keep minimum and maximum in the segment tree node. And output the difference.
-Now, how will the minimum and maximum change during an update?
It’s nothing but the maximum and minimum of the “x” array.
So, while you are lazily updating a segment of the tree, just check which range of the array “x”
affects the node.
Example:
Query = 1 a b k = 1 3 7 6
X =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
….
Y =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
….
Here, the Green part will be updated with the red part.
Let's consider you are at two lazy node for this given update, 1) [3 : 6] and 2) [7 : 8]
Then
Node [3 : 6] will the updated with value(min and max) of range [7 : 10] and
Node [7 : 8] will be updated with the value(min and max) of range [11 : 12] from array “y”
For calculating the minimum and maximum value quickly you can maintain
another data-structure like a sparse table.
Lazy update sudo code can be:
void lazy_update(int root, int l, int r, int d) {
node ans = sparse_table_query(l + d, r + d); // d = index difference of two given index a and b
tree[root] = node(ans.mx, ans.mn); // for above query 1 a b k = 1 3 7 6
lazy[root] = -inf; // d = 7 - 3 = 4
if (r - l == 1) {
return ;
}
int lefty = (root << 1) + 1;
int righty = lefty + 1;
lazy[lefty] = lazy[righty] = d;
}
pf2

Partial preview of the text

Download Intra AUST Programming Contest - Spring 2019 and more Exams Computer science in PDF only on Docsity!

Copy and Replace

Tag: Segment tree, Sparse table, Lazy propagation -Keep minimum and maximum in the segment tree node. And output the difference. -Now, how will the minimum and maximum change during an update? It’s nothing but the maximum and minimum of the “x” array. So, while you are lazily updating a segment of the tree, just check which range of the array “x” affects the node. Example: Query = 1 a b k = 1 3 7 6 X = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 …. Y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 …. Here, the Green part will be updated with the red part. Let's consider you are at two lazy node for this given update, 1) [3 : 6] and 2) [7 : 8] Then Node [3 : 6] will the updated with value(min and max) of range [7 : 10] and Node [7 : 8] will be updated with the value(min and max) of range [11 : 12] from array “y” For calculating the minimum and maximum value quickly you can maintain another data-structure like a sparse table. Lazy update sudo code can be: void lazy_update(int root, int l, int r, int d) { node ans = sparse_table_query(l + d, r + d); // d = index difference of two given index a and b tree[root] = node(ans.mx, ans.mn); // for above query 1 a b k = 1 3 7 6 lazy[root] = -inf; // d = 7 - 3 = 4 if (r - l == 1) { return ; } int lefty = (root << 1) + 1; int righty = lefty + 1; lazy[lefty] = lazy[righty] = d; }

Tomb Raider

Tab: Multisource BFS First calculate how many safe places you can visit less than N number of steps(Before the earthquake) from the source S. If you can go to the destination by the time this takes the minimum time as the answer. Otherwise, after N steps, put all the nodes to a queue which are safe from the earthquake and start a new BFS from the safe nodes in the second grid. And try the minimum time to go to the destination E.