Bessie is going on a hiking excursion! The trail that she is currently traversing consists of N checkpoints labeled 1…N (1≤N≤10^5).
There are K (1≤K≤10^5) tickets available for purchase. The i-th ticket can be purchased at checkpoint ci (1≤ci≤N) for price pi (1≤pi≤10^9) and provides access to all of checkpoints [ai,bi] (1≤ai≤bi≤N). Before entering any checkpoint, Bessie must have purchased a ticket that allows access to that checkpoint. Once Bessie has access to a checkpoint, she may return to it at any point in the future. She may travel between two checkpoints to which she has access, regardless of whether their labels differ by 1 or not.
For each of i∈[1,N], output the minimum total price required to purchase access to both checkpoints 1 and N if Bessie initially has access to only checkpoint i. If it is impossible to do so, print ?1 instead.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains N and K.
Each of the next K lines contains four integers ci, pi, ai, and bi for each 1≤i≤K.
OUTPUT FORMAT (print output to the terminal / stdout):
N lines, one for each checkpoint.
SAMPLE INPUT:
7 6
4 1 2 3
4 10 5 6
2 100 7 7
6 1000 1 1
5 10000 1 4
6 100000 5 6
SAMPLE OUTPUT:
-1
-1
-1
1111
10100
110100
-1
If Bessie starts at checkpoint i=4, then one way for Bessie to purchase access to checkpoints 1 and N is as follows:
Purchase the first ticket at checkpoint 4, giving Bessie access to checkpoints 2 and 3.
Purchase the third ticket at checkpoint 2, giving Bessie access to checkpoint 7.
Return to checkpoint 4 and purchase the second ticket, giving Bessie access to checkpoints 5 and 6.
Purchase the fourth ticket at checkpoint 6, giving Bessie access to checkpoint 1.
SCORING:
Test cases 1-7 satisfy N,K≤10^00.
Test cases 8-19 satisfy no additional constraints.
分类: 赛事资讯
USACO美国信息学奥赛适合几年级学生参加?USACO美国信息学奥赛赛事每年考什么?USACO赛事晋级获奖率高吗?USACO赛事动态栏目及时更新学生关于赛事最关心的信息。
USACO2022年一月美国计算机奥赛竞赛铜奖组问题三——Drought
The grass has dried up in Farmer John's pasture due to a drought. After hours of despair and contemplation, Farmer John comes up with the brilliant idea of purchasing corn to feed his precious cows.
FJ’s N cows (1≤N≤10^5) are arranged in a line such that the ith cow in line has a hunger level of hi (0≤hi≤10^9). As cows are social animals and insist on eating together, the only way FJ can decrease the hunger levels of his cows is to select two adjacent cows i and i+1 and feed each of them a bag of corn, causing each of their hunger levels to decrease by one.
FJ wants to feed his cows until all of them have the same non-negative hunger level. Please help FJ determine the minimum number of bags of corn he needs to feed his cows to make this the case, or print ?1 if it is impossible.
INPUT FORMAT (input arrives from the terminal / stdin):
Each input consists of several independent test cases, all of which need to be solved correctly to solve the entire input case. The first line contains T (1≤T≤10^0), giving the number of test cases to be solved. The T test cases follow, each described by a pair of lines. The first line of each pair contains N, and the second contains h1,h2,…,hN. It is guaranteed that the sum of N over all test cases is at most 105. Values of N might differ in each test case.
OUTPUT FORMAT (print output to the terminal / stdout):
Please write T lines of output, one for each test case.
Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
SAMPLE INPUT:
5
3
8 10 5
6
4 6 4 4 6 4
3
0 1 0
2
1 2
3
10 9 9
SAMPLE OUTPUT:
14
16
-1
-1
-1
For the first test case, give two bags of corn to both cows 2 and 3, then give five bags of corn to both cows 1 and 2, resulting in each cow having a hunger level of 3.
For the second test case, give two bags to both cows 1 and 2, two bags to both cows 2 and 3, two bags to both cows 4 and 5, and two bags to both cows 5 and 6, resulting in each cow having a hunger level of 2.
For the remaining test cases, it is impossible to make the hunger levels of the cows equal.
SCORING:
All test cases in input 2 satisfy N≤3 and hi≤10^0.
All test cases in inputs 3-8 satisfy N≤10^0 and hi≤10^0.
All test cases in inputs 9-14 satisfy N≤10^0.
Input 15 satisfies no additional constraints.
Additionally, N is always even in inputs 3-5 and 9-11, and N is always odd in inputs 6-8 and 12-14.
Problem credits: Arpan Banerjee
USACO2022年一月美国计算机奥赛竞赛铜奖组问题二—— Non-Transitive Dice
To pass the time in the barn, the cows enjoy playing simple dice games. One of these games is played with two dice X and Y. Both are rolled, and the winner is the die with the higher number showing. If both land on the same number, they are re-rolled (they may be re-rolled several times, as long as there continues to be a tie). We say die X beats die Y if it is more likely that X will win this game than Y.
Consider the following 4-sided dice:
Die A has the numbers 4, 5, 6, and 7 on its sides.
Die B has the numbers 2, 4, 5, and 10 on its sides.
Die C has the numbers 1, 4, 8, and 9 on its sides.
These dice satisfy a rather intriguing property: A beats B, B beats C, and C also beats A. In particular, none of the three dice is the "best", beating the other two. In this case, where no two dice tie and no single die is the best, we call the set of three dice "non-transitive". In a non-transitive set of three dice, each die beats one other die, and loses to another die.
Given the numbers on the faces of two 4-sided dice A and B, please help the cows determine whether there is a way to assign numbers to the faces of a third die C so the set of dice is non-transitive. The numbers on the faces of all dices must be integers in the range from 1 through 10 inclusive.
INPUT FORMAT (input arrives from the terminal / stdin):
Each input consists of several independent test cases, all of which need to be solved correctly to solve the entire input case. The first line of input contains T (1≤T≤10^), the number of test cases you need to solve.
The following T lines each describe one test case in terms of 8 numbers: the numbers on the four sides of die A, and the numbers on the four sides of die B. All numbers are in the range 1 through 10, not necessarily in sorted order. The same number might appear multiple times, even on the same die.
OUTPUT FORMAT (print output to the terminal / stdout):
Please write T lines of output. The kth line should be 'yes' if it is possible to design a die C to make the kth test case into a set of non-transitive dice, and 'no' otherwise.
SAMPLE INPUT:
3
4 5 6 7 2 4 5 10
2 2 2 2 1 1 1 1
1 1 1 1 2 2 2 2
SAMPLE OUTPUT:
yes
no
no
The first test case corresponds to the example given above. In the second test case, there is no die C that can make the set of dice non-transitive. The answer is no for the same reason for the third test case.
Problem credits: Brian Dean
USACO2022年一月美国计算机奥赛竞赛铜奖组问题一——Herdle
The cows have created a new type of puzzle called Herdle that has become a viral sensation in the bovine world.
Each day, a new puzzle is released for the cows to solve. The puzzle takes the form of a 3 by 3 grid representing a field on the farm, with each square of the field occupied by a cow of a certain breed. There are only 26 possible breeds, each identified by a different capital letter in the range A through Z. One is not told the pattern of breeds in the field --- the goal is to figure them out through a series of guesses.
In each guess, the cows enter a 3 by 3 grid of uppercase letters indicating a possible way the field could be filled with cows. Some of the squares in the guess might be correct. These are highlighted in green to let the cows know that they are correct. Other squares in the guess might be filled with a cow of the right breed but in the wrong place. These are highlighted in yellow.
The number of yellow-highlighted squares can help provide an indication of the number of cows of a certain breed. For example, suppose the guess grid contains 4 cows of breed A, and the answer grid contains 2 cows of breed A, where none of the A's line up (i.e., none of them should be colored green). In this case, only two of the A's in the guess grid should be highlighted yellow. More precisely, if there are x cows of a certain breed in the guess grid and y<x cows of this breed in the answer grid (not counting cows in the right place that lead to green highlights), then only y of the x cows in the guess grid should be highlighted yellow.
Given the correct answer grid and a grid representing a guess at this answer, please calculate the number of green and yellow highlighted squares.
INPUT FORMAT (input arrives from the terminal / stdin):
The first 3 lines of input gives the grid representing the correct answer. The next 3 lines of input represent a guess of this answer.
OUTPUT FORMAT (print output to the terminal / stdout):
Print two lines of output. On the first line of output, print the number of squares that should be highlighted in green. On the second line, print the number of squares that should be highlighted in yellow.
SAMPLE INPUT:
COW
SAY
MOO
WIN
THE
IOI
SAMPLE OUTPUT:
1
1
In this example, the O in the middle of the last row is correct, so it is highlighted in green. The letter W is in the wrong place, so it is highlighted in yellow.
SAMPLE INPUT:
AAA
BBB
CCC
AYY
AAA
ZZZ
SAMPLE OUTPUT:
1
2
Here, one of the As is in the correct place, so it is highlighted green. Of the remaining As, none are in the right place, and since there are two of these remaining in the answer grid, two should be highlighted yellow.
Problem credits: Brian Dean, inspired by the 'Wordle' app
USACO2022年一月美国计算机奥赛竞赛银奖组问题三——Cereal 2
Farmer John's cows like nothing more than cereal for breakfast! In fact, the cows have such large appetites that they will each eat an entire box of cereal for a single meal.
The farm has recently received a shipment with M different types of cereal (2≤M≤10^5). Unfortunately, there is only one box of each cereal! Each of the N cows (1≤N≤10^5) has a favorite cereal and a second favorite cereal. When given a selection of cereals to choose from, a cow performs the following process:
If the box of her favorite cereal is still available, take it and leave.
Otherwise, if the box of her second-favorite cereal is still available, take it and leave.
Otherwise, she will moo with disappointment and leave without taking any cereal.
Find the minimum number of cows that go hungry if you permute them optimally. Also, find any permutation of the N cows that achieves this minimum.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains two space-separated integers N and M.
For each 1≤i≤N, the i-th line contains two space-separated integers fi and si (1≤fi,si≤M and fi≠si) denoting the favorite and second-favorite cereals of the i-th cow.
OUTPUT FORMAT (print output to the terminal / stdout):
Print the minimum number of cows that go hungry, followed by any permutation of 1…N that achieves this minimum. If there are multiple permutations, any one will be accepted.
SAMPLE INPUT:
8 10
2 1
3 4
2 3
6 5
7 8
6 7
7 5
5 8
SAMPLE OUTPUT:
1
1
3
2
8
4
6
5
7
In this example, there are 8 cows and 10 types of cereal.
Note that we can effectively solve for the first three cows independently of the last five, since they share no favorite cereals in common.
If the first three cows choose in the order [1,2,3], then cow 1 will choose cereal 2, cow 2 will choose cereal 3, and cow 3 will go hungry.
If the first three cows choose in the order [1,3,2], then cow 1 will choose cereal 2, cow 3 will choose cereal 3, and cow 2 will choose cereal 4; none of these cows will go hungry.
Of course, there are other permutations that result in none of the first three cows going hungry. For example, if the first three cows choose in the order [3,1,2] then cow 3 will choose cereal 2, cow 1 will choose cereal 1, and cow 2 will choose cereal 3; again, none of cows [1,2,3] will go hungry.
It can be shown that out of the last five cows, at least one must go hungry.
SCORING:
In 4 out of 14 test cases, N,M≤10^0.
In 10 out of 14 test cases, no additional constraints.
USACO2022年一月美国计算机奥赛竞赛银奖组问题二—— Cow Frisbee
Farmer John's N cows (N≤3×10^5) have heights 1,2,…,N. One day, the cows are standing in a line in some order playing frisbee; let h1…hN denote the heights of the cows in this order (so the h's are a permutation of 1…N).
Two cows at positions i and j in the line can successfully throw the frisbee back and forth if and only if every cow between them has height lower than min(hi,hj).
Please compute the sum of distances between all pairs of locations i<j at which there resides a pair of cows that can successfully throw the frisbee back and forth. The distance between locations i and j is j?i+1.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line of input contains a single integer N. The next line of input contains h1…hN, separated by spaces.
OUTPUT FORMAT (print output to the terminal / stdout):
Output the sum of distances of all pairs of locations at which there are cows that can throw the frisbee back and forth. Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).
SAMPLE INPUT:
7
4 3 1 2 5 6 7
SAMPLE OUTPUT:
24
The pairs of successful locations in this example are as follows:
(1, 2), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (4, 5), (5, 6), (6, 7)
SCORING
Test cases 1-3 satisfy N≤5000.
Test cases 4-11 satisfy no additional constraints.
USACO2022年一月美国计算机奥赛竞赛银奖组问题一——Searching for Soulmates
Farmer John's cows each want to find their soulmate -- another cow with similar characteristics with whom they are maximally compatible. Each cow's personality is described by an integer pi (1≤pi≤10^18). Two cows with the same personality are soulmates. A cow can change her personality via a "change operation" by multiplying by 2, dividing by 2 (if pi is even), or adding 1.
Farmer John initially pairs his cows up in an arbitrary way. He is curious how many change operations would be needed to make each pair of cows into soulmates. For each pairing, decide the minimum number of change operations the first cow in the pair must make to become soulmates with the second cow.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains N (1≤N≤10), the number of pairs of cows. Each of the remaining N lines describes a pair of cows in terms of two integers giving their personalities. The first number indicates the personality of the cow that must be changed to match the second.
OUTPUT FORMAT (print output to the terminal / stdout):
Please write N lines of output. For each pair, print the minimum number of operations required for the first cow to make her personality match that of the second.
SAMPLE INPUT:
6
31 13
12 8
25 6
10 24
1 1
997 120
SAMPLE OUTPUT:
8
3
8
3
0
20
For the first test case, an optimal sequence of changes is 31⟹32⟹16⟹8⟹9⟹10⟹11⟹12⟹13.
For the second test case, an optimal sequence of changes is 12⟹6⟹7⟹8.
SCORING:
Test cases 1-4 satisfy pi≤10^5.
Test cases 5-12 satisfy no additional constraints.
USACO2022 年一月美国计算机奥赛竞赛金奖组问题三——Tests for Haybales
Farmer John's cows have decided to offer a programming contest for the cows on Farmer Nhoj's farm. In order to make the problems as fun as possible, they have spent considerable time coming up with challenging input cases. For one problem in particular, "Haybales", the cows need your help devising challenging inputs. This involve solving the following somewhat intriguing problem:
There is an array of sorted integers x1≤x2≤?≤xN (1≤N≤10^5), and an integer K. You don't know the array or K, but you do know for each index i, the largest index ji such that xji≤xi+K. It is guaranteed that i≤ji and j1≤j2≤?≤jN≤N.
Given this information, Farmer John's cows need to construct any array along with some integer K that matches that information. The construction needs to satisfy 0≤xi≤10^18 for all i and 1≤K≤10^18.
It can be proven that this is always possible. Help Farmer John's cows solve this problem!
INPUT FORMAT (input arrives from the terminal / stdin):
The first line of input contains N. The next line contains j1,j2,…,jN.
OUTPUT FORMAT (print output to the terminal / stdout):
Print K, then x1,…,xN on separate lines. Any valid output will be accepted.
SAMPLE INPUT:
6
2 2 4 5 6 6
SAMPLE OUTPUT:
6
1
6
17
22
27
32
The sample output is the array a=[1,6,17,22,27,32] with K=6. j1=2 is satisfied because a2=6≤1+6=a1+K but a3=17>1+6=a1+K, so a2 is the largest element that is at most a1. Similarly,
j2=2 is satisfied because a2=6≤6+6 but a3=17>6+6
j3=4 is satisfied because a4=22≤17+6 but a5=27>17+6
j4=5 is satisfied because a5=27≤22+6 but a5=32>22+6
j5=6 is satisfied because a6=32≤27+6 and a6 is the last element of the array
j6=6 is satisfied because a6=32≤32+6 and a6 is the last element of the array
This is not the only possible correct output for the sample input. For example, you could instead output the array [1,2,4,5,6,7] with K=1.
SCORING:
For 50% of all inputs, N≤5000
For the remaining inputs, there are no additional constraints.
USACO 2022 年一月美国计算机奥赛竞赛金奖组问题二——Farm Updates
Farmer John operates a collection of N farms (1≤N≤2·10^5), conveniently numbered 1…N. Initially, there are no roads connecting these farms to each-other, and each farm is actively producing milk.
Due to the dynamic nature of the economy, Farmer John needs to make changes to his farms according to a series of Q update operations (0≤Q≤2⋅10^5). Update operations come in three possible forms:
(D x) Deactivate an active farm x, so it no longer produces milk.
(A x y) Add a road between two active farms x and y.
(R e) Remove the eth road that was previously added (e=1 is the first road that was added).
A farm x that is actively producing milk, or that can reach another active farm via a series of roads, is called a "relevant" farm. For each farm x, please calculate the maximum i (0≤i≤Q) such that x is relevant after the i-th update.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line of input contains N and Q. The next Q lines each contain an update of one of the following forms:
D x
A x y
R e
It is guaranteed that for updates of type R, e is at most the number of roads that have been added so far, and no two updates of type R have the same value of e.
OUTPUT FORMAT (print output to the terminal / stdout):
Please output N lines, each containing an integer in the range 0…Q.
SAMPLE INPUT:
5 9
A 1 2
A 2 3
D 1
D 3
A 2 4
D 2
R 2
R 1
R 3
SAMPLE OUTPUT:
7
8
6
9
9
In this example, roads are removed in the order (2,3),(1,2),(2,4).
Farm 1 is relevant just before (1,2) is removed.
Farm 2 is relevant just before (2,4) is removed.
Farm 3 is relevant just before (2,3) is removed.
Farms 4 and 5 are still active after all queries. Therefore they both stay relevant, and the output for both should be Q.
SCORING:
Tests 2 through 5 satisfy N≤103, Q≤2⋅103
Test cases 6 through 20 satisfy no additional constraints.
USACO 2022 年一月美国计算机奥赛竞赛金奖组问题一—— Drought
The grass has dried up in Farmer John's pasture due to a drought. After hours of despair and contemplation, FJ comes up with the brilliant idea of purchasing corn to feed his precious cows.
FJ’s N (1≤N≤100) cows are arranged in a line such that the ith cow in line has a non-negative integer hunger level of hi. As FJ’s cows are social animals and insist on eating together, the only way FJ can decrease the hunger levels of his cows is to select two adjacent cows i and i+1 and feed each of them a bag of corn, causing each of their hunger levels to decrease by one.
FJ wants to feed his cows until all of them have the same non-negative hunger level. Although he doesn't know his cows' exact hunger levels, he does know an upper bound on the hunger level of each cow; specifically, the hunger level hi of the i-th cow is at most Hi (0≤Hi≤1000).
Your job is to count the number of N-tuples of hunger levels [h1,h2,…,hN] that are consistent with these upper bounds such that it is possible for FJ to achieve his goal, modulo 10^9+7.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains N.
The second line contains H1,H2,…,HN.
OUTPUT FORMAT (print output to the terminal / stdout):
The number of N-tuples of hunger levels modulo 10^9+7.
SAMPLE INPUT:
3
9 11 7
SAMPLE OUTPUT:
241
There are (9+1)⋅ (11+1)⋅ (7+1) 3-tuples h that are consistent with H.
One of these tuples is h=[8,10,5]. In this case, it is possible to make all cows have equal hunger values: give two bags of corn to both cows 2 and 3, then give five bags of corn to both cows 1 and 2, resulting in each cow having a hunger level of 3.
Another one of these tuples is h=[0,1,0]. In this case, it is impossible to make the hunger levels of the cows equal.
SAMPLE INPUT:
4
6 8 5 9
SAMPLE OUTPUT:
137
SCORING:
N is even in even-numbered tests and odd in odd-numbered tests.
Tests 3 and 4 satisfy N≤6 and Hi≤10.
Tests 5 through 10 satisfy N≤50 and Hi≤100.
Tests 11 through 20 satisfy no further constraints.