0% found this document useful (0 votes)
39 views

Problemset

Uploaded by

samehsayed12245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Problemset

Uploaded by

samehsayed12245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ACPC For Girls 2024

AAST, Alexandria, Egypt, July, 2024

Problem A. Ascending Subarray


Input file: standard input
Output file: standard output
Balloon Color: Orange

You are given an array a of n elements. This array has two pointers, and you will be given the initial
position of these pointers.
Your task is to move these two pointers so that when you reverse the subarray between them inclusive,
the subarray will be sorted ascendingly.
Print the maximum length of this subarray and the minimum number of operations required to move
those two pointers towards it.

Input
The input consists of multiple test cases.
The first line contains a single integer t (1 ≤ t ≤ 104 ) — the number of test cases.
The first line of each test case contains three integers n, l, r (1 ≤ l ≤ r ≤ n ≤ 105 ) — length of the array,
left pointer, right pointer.
The second line contains n integers a1 , a2 , . . . , an (1 ≤ ai ≤ 109 ) — elements of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 2 · 105 .

Output
For each test case, print two integers — the maximum length of this subarray, the minimum number of
operations required to move those two pointers towards the subarray.

Example
standard input standard output
1 3 2
6 2 4
4 2 1 4 7 8

Page 1 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem B. Game
Input file: standard input
Output file: standard output
Balloon Color: White

Alaa and Habiba played a game where Alaa scored A and Habiba scored H.
Can you determine who won or if it was a draw?

Input
One line contains two integers number A, H (1 ≤ A, H ≤ 100).

Output
Print "A"if Alaa won, "H"if Habiba won, or "D"if it was a draw.

Example
standard input standard output
2 3 H

Page 2 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem C. Great Coaches


Input file: standard input
Output file: standard output
Balloon Color: Yellow

Amr and Hazem are excellent problem-solving coaches. Their trainees wanted more challenges, specifically
involving arrays. To meet this demand, the coaches presented an original problem that the trainees had
never encountered before. The problem is as follows:
Given an array a of length n, count the number of subsequences of this array such that the Least Common
Multiple (LCM ) of the elements in the subsequence is equal to x. Since the number of such subsequences
can be very large, print the count modulo 109 + 7.
A subsequence is a sequence that can be derived from another sequence by deleting zero or more elements
without changing the order of the remaining elements.
The Least Common Multiple (LCM ) of a set of integers is the smallest positive integer that is divisible
by each of the integers in the set.

Input
The first line contains one integer T (1 ≤ T ≤ 105 ) — the number of test cases.
For each test case:
The first line contains two integers n (1 ≤ n ≤ 105 ) and x (1 ≤ x ≤ 107 ) — the number of elements in a
and the LCM , respectively.
The second line contains n numbers a1 , a2 , ..., an (1 ≤ ai ≤ 107 ) — the elements of a.
It’s guaranteed that the sum of n over all test cases doesn’t exceed 105 .

Output
You should output one number - the number of subsequences that their LCM = x modulo 109 + 7.

Example
standard input standard output
4 11
5 10 15
2 5 3 10 2 2
4 7 2
7 7 7 7
7 3
1 2 3 4 5 6 7
10 10
2 4 6 3 4 8 7 14 15 10

Page 3 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem D. Waheed’s Array


Input file: standard input
Output file: standard output
Balloon Color: Silver

Waheed has an array of integers. He would love to know how many operations it will take to transform
his array into a palindrome array.
The operation is as follows: he can take any element from the array and divide it by one of its divisors.
Waheed can do the operation any number of times (possibly zero).
Can you tell the minimum number of operations required to transform the array?

Input
The first integer t (1 ≤ t ≤ 105 ) — the number of test cases.
The first line of each test case contains one integer n, the size of the array(1 ≤ n ≤ 105 ).
The second line of each test case contains n integers a1 , a2 , . . . , an (1 ≤ ai ≤ 109 ).
It is guaranteed that the sum of n overall test cases does not exceed 105 .

Output
For each test case, output a single number: the minimum number of operations on a separate line.

Example
standard input standard output
2 4
4 0
8 5 3 12
3
1 1 1

Page 4 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem E. Common Subsequences


Input file: standard input
Output file: standard output
Balloon Color: Red

Given an array of size n, an integer x, and q queries.


Each query consists of two integers l and r. For each query, determine the number of subsequences that
can be formed from the array elements between indices l and r, such that the subsequence has x as a
common divisor.
The result for each query should be computed modulo 109 + 7.

Input
The first line contains one integer T (1 ≤ T ≤ 105 ) — the number of test cases.
Then follows T test cases.
The first line of each test case contains n, x and q (1 ≤ n, q ≤ 105 ) (1 ≤ x ≤ 109 ) — the size of the array,
the common divisor, and the number of queries respectively.
The second line of each test case contains n elements (1 ≤ ai ≤ 109 ) — the elements of the array.
Then q queries, each query contains l, r (1 ≤ l ≤ r ≤ n) — indices of the range.
It is guaranteed that the sum of n and q overall test cases does not exceed 105 .

Output
Output the answer of the queries for each test case modulo 109 + 7 on a separate line.

Example
standard input standard output
3 7
4 2 3 1
2 3 4 8 1
1 4 3
2 3 7
3 3 1
6 3 3 31
2 3 4 8 9 12 7
2 5 15
1 6
6 6
10 1 3
2 10 7 1 5 4 8 9 12 1
3 7
2 4
5 8

Page 5 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem F. Split the subarray


Input file: standard input
Output file: standard output
Balloon Color: Blue

Given an array of n integers, you can choose any position p such that (p > 1), and calculate the maximum
subarray sum for the elements to the left of that position and the maximum subarray sum for the elements
from that position to the right.
In other words, if you choose position p (1-based index and p > 1), you need to find the maximum subarray
sum from (a1 , a2 , . . . , ap−1 ), and the maximum subarray sum from (ap , ap+1 , . . . , an ).
Your task is to minimize the absolute difference between these two sums by choosing the optimal position
p. Output the minimum possible difference.

Input
The first line contains a single integer t (1 ≤ t ≤ 105 ) — the number of test cases.
The first line of each test case contains a single integer n (2 ≤ n ≤ 105 ) — the length of the array.
The second line of each test case contains n integers a1 , a2 , . . . , an (−109 ≤ ai ≤ 109 ) — the elements of
the array.
It is guaranteed that the sum of n over all test cases does not exceed 2 · 105 .

Output
For each test case, output one integer — the minimum possible difference.

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

Page 6 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem G. Replace From Range


Input file: standard input
Output file: standard output
Balloon Color: Rose

Given an integer array a of size N .


If ai = −1, that means you can replace it with any other number from the range [L, R].
Count the number of ways you can replace all indices i where ai = −1 such that no two consecutive
numbers are equal.
It’s guaranteed that a1 6= −1 and an 6= −1.
As the number can be very big, print the answer modulo 109 + 7.

Input
The input consists of multiple lines.
The first line contains three integers N, L, R (1 ≤ N ≤ 105 , 1 ≤ L ≤ R ≤ 1018 )− the size of the string,
and the range of numbers that you can choose from.
The second line contains N integers a1 , a2 , a3 , ...., aN (L ≤ ai ≤ R, or ai = −1).

Output
Single integer C – the number of ways you can replace all indices i where ai = −1 such that no two
consecutive numbers are equal.
As the number can be very big, print C modulo 109 + 7.

Examples
standard input standard output
4 1 5 12
5 -1 -1 5
4 6 10 13
7 -1 -1 6

Page 7 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem H. Jana and the Tournament


Input file: standard input
Output file: standard output
Balloon Color: Black

Jana loves tournaments. She is given an integer n, the number of participants in a tournament, numbered
from 1 to n. The tournament is structured in multiple rounds. In each round, matches are held between
pairs of players as follows:

• Player 1 plays against Player 2

• Player 3 plays against Player 4

• And so on...

The winner from match 1 plays the winner from match 2, the winner of match 3 plays the winner of
match 4, etc., in the subsequent round. The winner of a match is the participant whose largest divisor
(excluding the number itself) is the biggest. In case of a tie, the bigger number wins. If a participant does
not have someone to play against in a particular round, they advance to the next round automatically.
Jana wants to find out who will win the tournament.
Player 1’s largest divisor is considered equal to 1.

Input
The first integer t (1 ≤ t ≤ 105 ) — the number of test cases.
The onlyline contains an integer n (1 ≤ n ≤ 106 ), the number of participants.

Output
For each test case, output a single integer: the number of the participant who won the tournament on a
separate line.

Example
standard input standard output
3 1
1 14
15 16
16

Page 8 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem I. Shahd and Descending Numbers


Input file: standard input
Output file: standard output
Balloon Color: Green

Shahd loves math and numbers. She has a special fondness for certain numbers based on their binary
representations. One day, she discovered something interesting: some numbers have binary representations
where the bits form a descending sequence. For example, the numbers 1, 4, and 6 have this property, while
5 and 9 do not. Shahd refers to these numbers as "descending numbers."
Fascinated by this discovery, Shahd wants to find out how many descending numbers exist within a given
range. She asks for your help to count the number of descending numbers between l and r (inclusive).

Input
The first line contains a single integer t (1 ≤ t ≤ 104 ) — the number of test cases.
The first and only line of each test case contains two integers l and r (1 ≤ l ≤ r ≤ 109 ).

Output
For each test case, print the number of descending numbers in the range [l, r] inclusive.

Example
standard input standard output
3 2
4 6 3
12 15 1
8 9

Note
In the first test case where l = 4 and r = 6

1. Numbers in range and their binary representations:

• 4 - 100 descending
• 5 - 101 not descending
• 6 - 110 descending

2. Count of descending numbers: 2

Page 9 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem J. Sherlock and Equal Arrays


Input file: standard input
Output file: standard output
Balloon Color: Purple

Mariam loves Sherlock Holmes and aspires to be his student to learn from his great experience. To see if
she is worthy of his time, Sherlock gave her an easy challenge.
Given two arrays A and B, the goal is to make array A equal to B using the following types of operations:

1. Choose an integer x (0 ≤ x < 30) and a subset of elements from A, and apply the bitwise OR
operation to each element in the subset with 2x .

2. Choose an integer x (0 ≤ x < 30) and a subset of elements from B, and apply the bitwise OR
operation to each element in the subset with 2x .

Mariam needs your help to determine the minimum number of operations (possibly zero) required to make
arrays A and B equal.

Input
The first line contains a single integer t (1 ≤ t ≤ 103 ) — the number of test cases.
Each test case has 3 lines:
The first line contains a single integer n (1 ≤ n ≤ 105 ) — the length of the two arrays.
The second line contains n integers A1 , A2 , . . . , An (0 ≤ Ai < 230 ) — elements of the array A.
The third line contains n integers B1 , B2 , . . . , Bn (0 ≤ Bi < 230 ) — elements of the array B.
It is guaranteed that the sum of n over all test cases does not exceed 2 · 105 .

Output
For each test case, print one integer — the minimum number of operations (possibly zero) to make arrays
A and B equal.

Example
standard input standard output
3 0
1 3
1 8
1
4
7 4 6 2
1 5 4 3
5
16 7 3 9 5
10 1 2 4 3

Note
Two arrays A and B of length n are considered equal if Ai = Bi for all i, (1 ≤ i ≤ n).

Page 10 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem K. Rady the farmer


Input file: standard input
Output file: standard output
Balloon Color: Light Blue

Rady, a lazy farmer, wants to maximize his profit with minimal effort. Here’s his detailed plan:
Each day, Rady performs the following operations:

• He triples the fruit count of each existing tree.

• He plants y new trees, with each new tree initially having 1 fruit.

Rady will be satisfied if he manages to collect at least z fruits in total.


Initially, Rady starts with x trees, each initially having 1 fruit. Calculate the minimum number of days
Rady needs to work to achieve satisfaction.

Input
The first line of the input contains a single integer T (1 ≤ T ≤ 105 ) — the number of test cases.
The first line of each test contains three integers x, y, z (1 ≤ x, y, z ≤ 1018 ) — the number of trees he
will start with, the number of trees he will plant each day, and the number of fruits that will make him
satisfied.

Output
For each test case, output one integer — the minimum number of days that Rady needs to work to be
satisfied.

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

Page 11 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem L. Young Siblings


Input file: standard input
Output file: standard output
Balloon Color: Bronze

Reem introduced a two-player game to her younger siblings, Toty and Boty. Here’s how the game works:
There are n cards, each labeled with a number ai where 1 ≤ i ≤ n. Toty always starts first. Players take
turns picking cards either from the beginning or the end of the sequence until no cards are left. Each
player aims to maximize their score, defined as the bitwise XOR of all the cards they picked. The player
with the higher score wins, and if both play optimally, determine whether Toty wins, Boty wins, or if it
results in a draw.

Input
The first line contains an integer n (1 ≤ n ≤ 102 ) - the number of cards.
The second line contains n integers - ai (1 ≤ ai ≤ 103 ) representing the values on the cards.

Output
If Toty wins, output “Toty”. If Boty wins, output “Boty”. If it’s a draw, output ‘Toty-Boty”

Examples
standard input standard output
4 Toty
1 2 3 4
4 Toty-Boty
2 2 2 2
3 Boty
1 3 1

Page 12 of 13
ACPC For Girls 2024
AAST, Alexandria, Egypt, July, 2024

Problem M. Fibonacci’s Store


Input file: standard input
Output file: standard output
Balloon Color: Light Green

Gamal buys groceries on Fibonacci days, which correspond to Fibonacci numbers. He buys the same items
on two different Fibonacci days n and m (n > m) if m divides n.
Given n, the n-th Fibonacci number is denoted as Fn . Gamal wants to count how many Fibonacci days
he bought the same items as Fn , including Fn itself.
To clarify:

• Fibonacci days are those corresponding to Fibonacci numbers.

• Fibonacci numbers are defined recursively: F1 = 1, F2 = 1, Fn = Fn−1 + Fn−2 for n > 2.

• Gamal buys the same items on two Fibonacci days n and m (n > m) if m divides n.

Note: F1 and F2 are considered as two different days.

Input
The first line contains one integer t (1 ≤ t ≤ 106 ) — the number of test cases.
Then follows t test cases. Each test case contains an integer n (1 ≤ n ≤ 107 ).

Output
For each test case, output a single integer representing the number of Fibonacci days Gamal bought the
same items as Fn , on a separate line.

Example
standard input standard output
6 2
1 2 4 8 9 12 2
3
4
4
6

Note
The first 4 Fibonacci numbers are 1, 1, 2, 3.

• For the first test case where n = 1, F1 = 1, there are 2 days m that divide F1 : F1 = 1 and F2 = 1.

• For the second test case where n = 2, F2 = 1, there are 2 days m that divide F2 : F1 = 1 and F2 = 1.

• For the third test case where n = 4, F4 = 3, there are 4 days m that divide F4 : F1 = 1, F2 = 1,
F3 = 2, and F4 = 3.

Page 13 of 13

You might also like