文章目录
- [F - Greedy Sequence](https://nanti.jisuanke.com/t/41303)
- [H - Holy Grail](https://nanti.jisuanke.com/t/41305)
F - Greedy Sequence
You’re given a permutation aa of length
For each , construct a sequence
- ;
- The length ofis, and for each,;
- First, we must choose all the possible elements offrom permutation aa. If the index ofin permutationis, for each,). And for each, every element of
- After we choose all possible elements for, if the length ofis smaller than, the value of every undetermined element ofis;
- For each
Consider two sequences and , we say the weight of is higher than that of if and only if there exists an integer such that for all and .
If for each , , the weight of is equal to the weight of .
For each , print the number of non-zero elements of
It’s guaranteed that there is only one possible answer.
Input
There are multiple test cases.
The first line contains one integer , denoting the number of test cases.
Each test case contains two lines, the first line contains two integers nn and , the second line contains nn distinct integers separated by a space, which is the permutation .
Output
For each test case, print one line consists of nn integers
is the number of non-zero elements of sequence .
There is no space at the end of the line.
样例输入
2
3 1
3 2 1
7 2
3 1 4 6 2 5 7
样例输出
1 2 3
1 1 2 3 2 3 3
有的人用的是主席树,我看好多暴力都过了,我也暴力
H - Holy Grail
As the current heir of a wizarding family with a long history,unfortunately, you find yourself forced to participate in the cruel Holy Grail War which has a reincarnation of sixty years.However,fortunately,you summoned a Caster Servant with a powerful Noble Phantasm.When your servant launch her Noble Phantasm,it will construct a magic field,which is actually a directed graph consisting of n vertices and m edges.More specifically,the graph satisfies the following restrictions :
- Does not have multiple edges(for each pair of vertices x and y, there is at most one edge between this pair of vertices in the graph) and does not have self-loops(edges connecting the vertex with itself).
- May havenegative-weighted edges.
- Does not have anegative-weighted loop.
- n<=300 , m<=500.
Currently,as your servant’s Master,as long as you add extra 6 edges to the graph,you will beat the other 6 masters to win the Holy Grail.
However,you are subject to the following restrictions when you add the edges to the graph:
- Each time you add an edge whose cost is c,it will cost you c units of Magic Value.Therefore,you need to add an edge which has the lowest weight(it’s probably that you need to add an edge which has a negative weight).
- Each time you add an edge to the graph,the graph must not have negative loops,otherwise you will be engulfed by the Holy Grail you summon.
Input
Input data contains multiple test cases. The first line of input contains integer t — the number of testcases .
For each test case,the first line contains two integers n,m,the number of vertices in the graph, the initial number of edges in the graph.
Then m lines follow, each line contains three integers x, y and w denoting an edge from vertices x to y (0-indexed) of weight w.
Then 6 lines follow, each line contains two integers s,t denoting the starting vertex and the ending vertex of the edge you need to add to the graph.
It is guaranteed that there is not an edge starting from s to t before you add any edges and there must exists such an edge which has the lowest weight and satisfies the above restrictions, meaning the solution absolutely exists for each query.
Output
For each test case,output 6 lines.
Each line contains the weight of the edge you add to the graph.
样例输入
1
10 15
4 7 10
7 6 3
5 3 3
1 4 11
0 6 20
9 8 25
3 0 9
1 2 15
9 0 27
5 2 0
7 3 -5
1 7 21
5 0 1
9 3 16
1 8 4
4 1
0 3
6 9
2 1
8 7
0 4
样例输出
-11
-9
-45
-15
17
7
因为有负权,要用SPFA
6次SPFA
每次找到t到s的最短路之后,在图中加一条s到t的负边