You are on page 1of 11

XIV Zhautykov Olympiad on Mathematics, Physics and Informatics, *Day 2*

Almaty, Kazakhstan, January, 13, 2018

Problem D. Segments
Input file: standard input
Output file: standard output
Time limit: 3 seconds
Memory limit: 40 megabytes
There is a multiset of segments S. Difference between multiset and set is that multiset allows multiple
instances of one segment, unlike a set.
Given two integer numbers n and t. You have n operations of following types that are made over the
multiset:

1. Insert segment [l, r] into the multiset S. The segment is assigned with id — minimum positive integer
number that was not assigned to any other segment before.

2. Erase the segment with assigned number id from the multiset S. It is guaranteed that at the moment
of erasing there is a segment in the multiset S with assigned number id.

3. Count the number of segments from the multiset S that has at least k integer points in common
with given segment [l, r].

Integer point x is common for both segments [li , ri ] and [lj , rj ], if li ≤ x ≤ ri and lj ≤ x ≤ rj .
Input
The first line of input contains two integer numbers n and t (1 ≤ n ≤ 2 · 105 , 0 ≤ t ≤ 1) — number of
operations and constant number. Each of next n lines describes one query.

1. Queries of first type are given in following format: 1 ai bi (0 ≤ ai , bi ≤ 2 · 109 ).

2. Queries of second type are given in following format: 2 idi (1 ≤ idi ≤ n).

3. Queries of third type are given in following format: 3 ai bi ki (0 ≤ ai , bi , ki ≤ 2 · 109 ).

Please note that end points of segments [li , ri ] for queries of type 1 and 3 are encoded, in order to
decode them you need to perform the following transformations:

li = (ai ⊕ (t ∗ lastans)) ri = (bi ⊕ (t ∗ lastans))

where lastans — last answer to the query of type 3 (initially lastans equals to 0). If it turned out
that li is greater than ri , you should swap the values of li and ri .
It is guaranteed that there will be at least one query of type 3 in input.
Here ⊕ denotes the bitwise XOR operation.
Consider that problem has unusual memory limit.
Output
For each query of type 3 print answer in separate line.
Scoring
This task contains six subtasks:
1. n ≤ 5 · 103 . Scored 7 points.

2. n ≤ 105 . First comes queries of type 1, then of type 3 and there is no query of type 2. Scored 15
points.

3. n ≤ 2 · 105 , ki = 1 for all third type queries. Scored 16 points.

4. n ≤ 105 , t = 0. Scored 17 points.

5. n ≤ 105 . Scored 20 points.

Page 1 of 5
XIV Zhautykov Olympiad on Mathematics, Physics and Informatics, *Day 2*
Almaty, Kazakhstan, January, 13, 2018

6. n ≤ 2 · 105 . Scored 25 points.


Examples
standard input standard output
6 1 0
1 1 2 2
3 2 4 2 0
1 3 5
3 2 3 1
2 1
3 0 3 1
6 0 0
1 3 10 2
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2

Page 2 of 5
XIV Zhautykov Olympiad on Mathematics, Physics and Informatics, *Day 2*
Almaty, Kazakhstan, January, 13, 2018

Problem E. Nice sequence


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes
At their leisure time Tima and Kanat play with sequences of integers. Tima considers a sequence nice
if the sum of any N consecutive numbers of the sequence is negative and Kanat considers a sequence nice
if the sum of any M consecutive numbers of the sequence is positive. If the sequence does not have N
and/or M consecutive numbers, it is considered to be nice for Tima and/or Kanat respectively.
Find the sequence of maximum possible length that will be nice for both of them.
Input
The first line contains one integer T (1 ≤ T ≤ 10) — the number of tests.
In the next T lines there are two integers N and M , separated by space.
Output
For each test output 2 lines: in the first line output one integer K — maximum length of the sequence,
which is nice for both Tima and Kanat. In the second line output K numbers separated by space —
the sequence itself. The numbers should not exceed 109 by absolute value and should be non-zero. It is
guaranteed that it is possible to find a sequence of maximum length that satisfies above condition. When
K = 0 second line should be empty.
Scoring
This task includes seven subtasks:

1. 1 ≤ N, M ≤ 100, and max(N, M ) is divisible by min(N, M ). Score 6 points.

2. 1 ≤ N, M ≤ 104 , min(N, M ) = 2. Score 9 points.

3. 1 ≤ N, M ≤ 10. Score 14 points.

4. 1 ≤ N, M ≤ 2 · 105 , |N − M | ≤ 2. Score 15 points.

5. 1 ≤ N, M ≤ 2000. Score 14 points.

6. 1 ≤ N, M ≤ 5 · 104 . Score 18 points.

7. 1 ≤ N, M ≤ 2 · 105 . Score 24 points.

Example
standard input standard output
3 2
3 1 1 2
2 3 3
1 1 3 -4 2
0

Page 3 of 5
XIV Zhautykov Olympiad on Mathematics, Physics and Informatics, *Day 2*
Almaty, Kazakhstan, January, 13, 2018

Problem F. Birthday gift


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes
Askhat received from NurlashKO rooted tree on his birthday as a gift with n vertexes, numbered from
1 to n. Tree — connected unoriented graph without any cycles. The tree root is a vertex with number
1. Vertex v is an ancestor of vertex u if v lies on the minimal path from u to the root. Lowest common
ancestor of sequence of vertexes (x1 , x2 , ..., xk ) — farthest vertex from root, which is an ancestor of xi for
all 1 ≤ i ≤ k (lca(x1 , x2 , ..., xk )).
In addition to the gift, NurlashKO prepared a task for Askhat. At first, he reported a sequence with
length m — (a1 , a2 , ..., am ), each number in the sequence is a vertex from the tree. There may be duplicates
of vertexes in the sequence. Then he started asking q queries, each query is one of the two types:
• 1 pos v — NurlashKO asks Askhat to change the value at position pos to the value v, i.e. apos = v.
• 2 l r v — NurlashKO asks Askhat to find a pair (x, y), such that l ≤ x ≤ y ≤ r and
lca(ax , ax+1 , ..., ay ) = v. Or say that there is no such pair.
Askhat has spent a lot of time on researching the gift and now he wants your help.
Input
First line of input contains three positive integer numbers n, m and q — size of the tree, length of
the sequence and number of queries. Next n − 1 lines contain edges of the tree (ui , vi ) (ui ̸= vi ). Next
line contains m integer numbers, a1 , a2 , ..., am . (1 ≤ ai ≤ n) — sequence, which was gifted to Askhat by
NurlashKO. Each of the next q lines describes a query. If first number of query equals to 1, then it is
followed by two numbers pos and v (1 ≤ pos ≤ m, 1 ≤ v ≤ n) — query of first type. If first number of
query equals to 2, then it is followed by three numbers l, r and v (1 ≤ l ≤ r ≤ m, 1 ≤ v ≤ n) — query of
second type. It is guaranteed that among q queries at least one is of second type.
Output
Print two numbers x and y — answer to each query of second type, if there is no solution print out
“-1 -1” (without quotes). If there are multiple solutions, output any of them.
Scoring
This problem consists of four subtasks, in each subtask tests satisfy constraints in statement:
1. 1 ≤ n, m, q ≤ 100. Score 12 points.
2. 1 ≤ n, m, q ≤ 500. Score 18 points.
3. 1 ≤ n, m, q ≤ 2000. Score 26 points.
4. 1 ≤ n, m, q ≤ 2 · 105 . Score 44 points.

Example
standard input standard output
5 4 4 1 3
1 2 3 3
3 1 -1 -1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1

Page 4 of 5
XIV Zhautykov Olympiad on Mathematics, Physics and Informatics, *Day 2*
Almaty, Kazakhstan, January, 13, 2018

Note

• Sequence: [4, 5, 2, 3]

• Subsegment = [4, 5, 2], v = 1. lca(4, 5, 2) = 1, answer: (1, 3).

• Query on changing, new sequence: [4, 5, 5, 3]

• Subsegment = [5, 3], v = 5. lca(5) = 5, answer: (3, 3).

• Subsegment = [4, 5, 5], v = 1. lca(4) = 4, lca(5) = 5, lca(4, 5) = 3, lca(5, 5) = 5, lca(4, 5, 5) = 3.


There is no solution.

Page 5 of 5
XIV International Zhautykov Olimpiad/Experimental Competition Page 1/6

SOLUTION TO THE EXPERIMENTAL COMPETITION


The Law of Archimedes (15.0 points)
Part 1. Installation parameters
1.1 A strip of millimeter paper is screwed onto the test-tube. We make marks on the strip, untwist it
and obtain the lengths of 1, 2, 3 and 4 revolutions as
l1  63 mm
l2  127 mm
l3  191mm
l4  255 mm
From these data we find that the length of one revolution is equal to l  64,0  0.3mm
l
The diameter is then calculated by the formula D   20,372 mm , the unstrumental error is found

l
as D  D  0,1mm and the final result is written as
l
D  20,4  0.1mm.
1.2 The length of the test-tube is obtained as L  175  1mm.
1.3.1 – 1.3.2 . Dependence of the immersion depth of the tesr-tube on the number of nuts, placed in
it, is shown in Table 1. First, the length x of the part of the test-tube, protruding above the water
level, is measured. And then the immersion depth is calculated by the formula h  L  x .

Table 1
Number
of nuts x , mm h , mm
1 80 95
2 65 110
3 50 125
4 37 138
5 22 153
6 10 165

Immersion depth against the number of nuts


180
Immersion depth, mm

160

140

120

100

80

60
0 1 2 3 4 5 6 7
Number of nuts
XIV International Zhautykov Olimpiad/Experimental Competition Page 2/6

The dependence obtained is linear and is described by the formula


h  an  b. (1)
The parameters, calculated by the least square method, are equal
a  14,1  0,5mm
. (2)
b  81,8  1,8mm
1.3.3 The theoretical formula for the resulting dependence follows from the equilibrium condition
M  mng  Shd  h  M  mn . (3)
S
D 2
where S  stands for the cross-sectional area of the test tube.
4
From the comparison of expressions (3) and (1) it follows that
m
a  m  Sa . (4)
S
Numerical calculations lead to the following result
D 2
m a  4,58 10 3 kg  4,58 g. (5)
4
The instrumental error in measuring the mass of the nut is calculated by the formula
 a   D 
2 2
4
m  m    2   1,6  10 kg. (6)
 a   D 
The final weight of the nut is written as
m  4,58  0,16 g. (7)
The weight of the test-tube is calculated by the formula
M D 2
b  M  Sb   b  2,67 102 kg  26,7 g.
S 4
The error in calculating the mass of the test-tube is found as
 b   D 
2 2

M  M     2   0,6 g. . (8)
 b   D 
To simplify further calculations, we note that the ratio of the parameters of the linear dependence (2)
is equal to the ratio of the mass of the test-tube and the nut:
M b
n*    5,82 . (9)
m a
Part 2. Oscillations of the test-tube
2.1 To simplify the calculations, the formula for the period of oscillations can be rewritten in the
form
h an  b
Tn  2 0  2 . (10)
g g
To linearize this dependence, it is necessary to plot and analyze the dependence of the squared period
on the number of nuts T 2 (n) . The results are summarized in Table 2.

Table 2.
Number T,s T 2 , s2
of nuts
1 0,680 0,463
2 0,717 0,514
3 0,752 0,565
XIV International Zhautykov Olimpiad/Experimental Competition Page 3/6

4 0,785 0,617
5 0,817 0,668
6 0,848 0,720

The graph of the dependence T 2 (n) is shown in the figure below.


Linearized dependence of the period on the number of
nuts
0.700
0.650
Squared period T^2, s^2

0.600
0.550
0.500
0.450
0.400
0.350
0.300
0 1 2 3 4 5 6 7
Number of nuts

2.2 The results of the measurements are given in tables


The random error in measuring the period is estimated from the following formula
 t  t 
2
k
t
t  2 k
. ; T  (11)
N ( N  1) k
Here t refers to the time needed to perform k periods of oscillations (in our case k  5 and k  3
respectively), N  10 stands for the number of measurements.

Table 3. Oscillations in the wide vessel


Number
Averaged Squared
of Error in the
Time period period
Number periods Period period
of nuts k t ,s T,s T ,s T T 2 , s2
4 5 3,74 0,748 0,744 0,009 0,554
5 3,64 0,728
5 3,77 0,754
5 3,71 0,742
5 3,74 0,748
5 5 3,93 0,786 0,770 0,010 0,594
5 3,81 0,762
5 3,89 0,778
5 3,83 0,766
5 3,80 0,760
XIV International Zhautykov Olimpiad/Experimental Competition Page 4/6

6 5 3,93 0,786 0,789 0,010 0,622


5 3,93 0,786
5 4,04 0,808
5 3,93 0,786
5 3,89 0,778

Table 3. Oscillations in the beaker

Number
Averaged Squared
of Error in the
Time period period
Number periods Period period
of nuts k t ,s T,s T , s T T 2 , s2
4 3 2,21 0,74 0,742 0,014 0,551
3 2,25 0,75
3 2,27 0,76
3 2,20 0,73
3 2,20 0,73
5 3 2,38 0,79 0,789 0,015 0,623
3 2,37 0,79
3 2,34 0,78
3 2,42 0,81
3 2,33 0,78
6 2 1,61 0,81 0,818 0,036 0,669
2 1,59 0,80
2 1,66 0,83
2 1,63 0,82
2 1,69 0,85

2.4 What possible reasons can explain the deviation between experimental data and theoretical
calculations?

Table 4
No. Possible reasons «Yes» «No»
1 Measurement errors Х
2 Oscillation damping Х
3 An increase in the effective mass of a moving Х
test-tube due to water entraining
4 Change in pressure under the tube when it moves Х
as compared to hydrostatic pressure
5 Surface tension forces Х

Comments:
1. Of course, errors ifluence any result.
2.3 These reasons should lead to an increase in the period, and not to a decrease.
4. Apparently, the main reason, leading to a reduction in the period.
5. Too small forces.
XIV International Zhautykov Olimpiad/Experimental Competition Page 5/6

Marking scheme
Part1. Installation parameters
№ Criteria Total Points
1.1 Diamater measurement 0,9
- sketch of the measurements:
- rolling on the test-tube (2-3 revolutions; 1 revolution); 0,2 (0,1)
- rolling the test-tube on the millimeter paper; (0,1)
- direct measurement of the diameter; (0,1)
Measurement results:
- circumference in the range of 63-66 mm (61-68 mm, out of 0,2 (0,1; 0)
range)
Evaluation of the diameter:
- formula: 0,1
- numerical value (in accordance with the previous part) 0,2 (0,1; 0)
Instrumental errpr 0,25-0,35 mm (larger) 0,1 (0)
Correctly rouded results* 0,1
1.2 Measurement of the test-tube length 0,3
- length in the range of 170-180 mm (out of range) 0,1 (0)
- instrumental error 1 mm (иное) 0,1 (0)
Correctly rounded result* 0,1
1.3.1 Results of the immersion depth measurement 1,8
Results differ from tabulated  2 mm (  4 mm, larger) 1,2 (0,6; 0)
Number of points* 6 (3, less) 0,6 (0,3, 0)
1.3.2 Plotting the graph and calculating the parameters of the 1,0
dependence
(marked only if 1.3.1 has been marked)
- axes are signed and ticked; 0,1
- points are plotted in accordance with the table 0,2
Parameters of the dependence:
- form of dependence is a linear function 0,1
- evaluation of the parameters; 2х0.2
- errors of the parameters; 2х0,2
1.3.3 Calculation of masses of the nut and the test tube: 2,0
(marked only if 1.3.1 has been marked)
- formula of the theoretical dependence 0,4
- formulas for calculating masses through the parameters of the
linear dependence; 2х0,2
- calculation of the mass of the nut: within 10% from the 0,4 (0,2, 0)
tabulated value (20%, larger)
- Nut mass error: errors in the slope and the diameter are taken
into account (only one contribution) 0,2 (0,1)
- calculation of the test-tube mass: within 10% from the tabulated 0,4 (0,2, 0)
value (20%, larger)
- error in the mass of the test-tube: errors in the shift and the 0,2 (0,1)
diameter: erroes in the shift and in the diameter are taken into
account (only one contribution)

* - marked only if the measurements are marked.


XIV International Zhautykov Olimpiad/Experimental Competition Page 6/6

Part 2. Oscillations of the test-tube

№ Criteria Total Points


2.1 Theoretical dependence 1,2
- formula for the period T (n ) via measured parameters 0,2
- periods are calculated 6х0,1
- linearization T 2 (n) (other) 0,1(0)
Plotting the graph:
- axes are signed and ticked; 0,1
- points are plotted in accordance with the table; 0,2
2.2 Formula for evaluating the error in the period:
- decrease of the random error with increasing the number of
measurements; 0,2
- modulus of the average deviation from the mean value; (0,1)
Oscillations in the wide vessel 3,0
Results within the range  20% (  30% , larger) 3х0,3 (0,2;
0)
More than 7 measuments are taken (more than 4, less)* 3х0,3 (0.2;
0)
Periods are calculated* 3х0,1
Errors are calculated* 3х0,1
Points are plotted in accordance with the table * 0.2
Errors are stated in the graph* 0,2
The periods of oscillations are found to be less than the 0,2
theoretical one (more than 0,1 s)*
Oscillations in the beaker 3,3
The results of the measurements within the range  20% (  30% 3х0,3 (0,2;
, larger) 0)
More than 7 measuments are taken (more than 4, less)* 3х0,3 (0.2;
0)
Periods are calculated* 3х0,1
Errors are calculated* 3х0,1
Points are plotted in accordance with the table * 0.2
Errors are stated in the graph* 0,2
The periods of oscillations are close to theoretical (the difference 0,3
is not more than 0,2 s)*
The periods of oscillations in different vessels are similar 0,2
(differences not more than 0.2 s) *
2.4 Possible reasons 1,5
- each correct answer 5х0,3
Total 15

* - marked only if the measurements are marked.

You might also like