2020.4.5 Xuejun faithful team fun network Tournament summary

Click the title
T1 because the problem is to find the law, and talk about the poor little significance, so I will not say.

T2

Give you a little right of the tree, you have to choose a pair of points \ ((x, y) \ ) and \ (a_x> a_y \) , making contributions \ (a_x * dist (x, y) \) maximum.
Seeking maximum contribution.

This is a feeling at first glance will be able to cut the subject.
Second eye I thought I could \ (LCT \) do, but on the second question is certainly not \ (LCT \) .
Third eye thought sectional tree, after a similar dynamic pushed come up \ (the DP \) method.
Playing half feel constant may be a bit big, then think dotted rule.
Dotted rule beginning to make a band set, then the constant feeling too, for another play:
the sub-tree added to the list in order to maintain the right to use tree line when the maximum value is less than equal to the number, added to the list of sub-tree when computing the contribution; the positive with do it again, would spend it again.
Pay up TLE, into a tree-like array of AC.
At this time, the race began about 80min.

Positive Solutions to understand after I realized I ...... sb the
subject becomes what is the \ (max (a_x, a_y) * dist (x, y) = max (a_x * dist (x, y), a_y * dist (x, y )) \)
so the problem is to find its farthest point for each point ......
find out the diameter, the farthest point of a point is certainly one of the two diameter end points.


T3

There is an array of \ (A_ {1..n} \) , in the beginning there is a ([1, A_N] \) \ (integer) probability of moderate value \ (the X-\) (you do not know specifically how much ).
Can always check \ (X \) state, \ (X \) state is \ (I \) is the \ (x \ in [a_ {
i-1} + 1, a_i] \) then there are several modes of operation , use and the order of each operation is arbitrary, denoted \ ((v_j, w_j) \
) indicates that the flower \ (v_j \) price can \ (x \) minus \ (w_j \)
to ask the \ (X \) reaches state \ (1 \) is desirable to minimize the number of steps, multiplying the result by \ (A_N \)

The meaning of the questions may not be well understood. This may be pointing to understand: As \ (x \) is random, it can only determine \ (x \) without knowing the specific value in a certain interval. The role of the so-called "status" is a further distinction between \ (the X-\) , in order to influence future decisions.
Obviously there will be a DP after understanding the meaning of the title,
\ (dp_ {I, J} \) representing the interval of \ ([i, j] \ ) answer, when the transfer equation clearly.
Next there is a dynamic mind a thought that can not be calculated only \ (i \) or \ (j \) answers the boundary of a state it?
So open play ......
when debugging found that ignoring the interval \ ([i, j] \ ) that occurred after the left is not divided, this time from the end of ten minutes ...... not
so anxious and want to change back to the previous violence, Unfortunately, time is not enough.

In fact, my previous ideas are no problem, the question now is how to deal with the case segmented.
Solutions show positive approach is to force dividing interval (or the entire range over the status after being left \ (1 \) ).
Obviously, the number you want within an interval into a state \ (1 \) , it is necessary to go through such a process.
But how to ensure that you can do it, and most of it?
To engage in various operations again completely backpack, then the equivalent of \ (a_n \) modes of operation, and is guaranteed to be optimal.

using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#define N 2010
#define ll long long
int n,m;
int a[N];
int pre[N],suc[N];
struct Op{
	int v,w;
} o[N];
ll v[N];
ll f[N],g[N],s[N];
ll calc(int,int);
ll getg(int x){return g[x]!=-1?g[x]:g[x]=calc(a[pre[x]]+1,x);}
ll getf(int x){return f[x]!=-1?f[x]:f[x]=calc(x,a[suc[x]]);}
ll calc(int L,int R){
	ll res=0x7f7f7f7f7f7f7f7f;
	for (int i=1;i<=a[n] && L-i>0;++i)
		if (v[i]!=0x7f7f7f7f7f7f7f7f && (suc[L-i]!=suc[R-i] || R-i<=a[1])){
			int l=L-i,r=R-i;
			ll tmp=v[i]*(r-l+1)+getf(l)+getg(r);
			l=a[suc[l]]+1,r=a[pre[r]];
			if (l<=r)
				tmp+=s[suc[r]]-s[suc[l]-1];
			res=min(res,tmp);
		}
	return res;
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int T;
	scanf("%d",&T);
	while (T--){
		scanf("%d%d",&n,&m);
		memset(pre,0,sizeof pre);
		memset(suc,0,sizeof suc);
		for (int i=1;i<=n;++i)
			scanf("%d",&a[i]),pre[a[i]+1]=suc[a[i]]=i;
		for (int i=1;i<=a[n];++i)
			pre[i]=(pre[i]?pre[i]:pre[i-1]);
		for (int i=a[n];i>=1;--i)
			suc[i]=(suc[i]?suc[i]:suc[i+1]);
		for (int i=1;i<=m;++i)
			scanf("%d%d",&o[i].v,&o[i].w);
		memset(v,127,sizeof(ll)*(a[n]+1));
		v[0]=0;
		for (int i=1;i<=m;++i)
			for (int j=o[i].w;j<=a[n];++j)
				v[j]=min(v[j],v[j-o[i].w]+o[i].v);
		memset(g,255,sizeof(ll)*(a[n]+1));
		memset(f,255,sizeof(ll)*(a[n]+1));
		for (int i=1;i<=a[1];++i)
			f[i]=g[i]=0;
		bool bz=1;
		for (int i=2;i<=n && bz;++i){
			s[i]=s[i-1]+getg(a[i]);
			if (g[a[i]]==0x7f7f7f7f7f7f7f7f)
				bz=0;
		}
		printf("%lld\n",bz==0?-1:s[n]);
	}
	return 0;
}











T4

First, a game Title: take two people playing stones, gravel total of \ (m \) , and the number of stones taken each person can not exceed a person stones taken. \ (f (m) \) is the minimum number is guaranteed to take the upper hand win.
Seeking \ (\ sum_ {i = 1 } ^ n \ sum_ {m | i} f (m) \)

This question is when the game is simply not thought about ......

First \ (f (m) \) is the general term, can be found by the following reasoning or play table:
If \ (m \) is an odd number, that is selected from the upper hand \ (1 \) .
If \ (m \) is even, then the next process, who chose the odd bad luck will come, so the election will be an even number. Two stones will then combined, equivalent \ (f (m / 2)
\) then \ (f (m) = lowbit
(m) \) above that is a change in expression \ (\ sum_ { i = 1} ^ nlowbit (i
) \ lfloor \ frac {n} {i} \ rfloor \) consider (lowbit (i) \) \ calculated separately equal. Order \ (G (n-) = \ sum_ {I =. 1} ^ n-\ lfloor \ FRAC {n-} {I} \ rfloor \)
\ (G (n-) \) is \ (lowbit (i) \ geq 1 \ ) number, \ (G (\ lfloor \ FRAC {n-2}} {\ rfloor) \) is \ (lowbit (i) \ geq 2 \) number, and so on.
The answer is \ (g (n) + ( 2-1) g (\ lfloor \ frac {n} {2} \ rfloor) + (4-2) g (\ lfloor \ frac {n} {4} \ rfloor) + ... \)
is calculated\ (g (n) \) time is \ (\ sqrt n \) , one above method using geometric series summation formula Analysis time out \ (\ sqrt n \)

Direct divisible large block constant, but the card. Thus gmh uncle invented a constant minimum methods:
the \ (xy = n \) of the image drawn, can be found in the whole number of points required is interposed between the coordinate axes of the image of FIG.
This thing is about \ (y = x \) symmetry.
So just before you need \ (\ sqrt n \) one by one count, expanded repeat section after subtracting twice (ie, \ (\ lfloor \ sqrt the n-\ rfloor ^ 2 \) )

using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
#define mo 998244353
ll n;
inline ll g(ll n){
	ll sq=sqrt(n);
	ll res=0;
	for (ll i=1;i<=sq;++i)
		res+=n/i;
	return (2*res%mo-sq*sq%mo+mo)%mo;
}
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%lld",&n);
	ll ans=g(n);
	for (ll k=1;1ll<<k<=n;++k)
		ans+=(1ll<<k-1)%mo*g(n>>k)%mo;
	ans%=mo;
	printf("%lld\n",ans);
	return 0;
}

T5

Gives a mountain linearly arranged, the position of each elevation is monotonically decreasing function over time.
A plurality of interrogation \ ([T, L, R & lt] \) , represents \ (T \) time, \ ([L, R & lt] \) interval mountain how much water can be reservoir (not within the mountains can be seen that shovel section level).

The answer is equal to the contour of the lower profile, lower profile and the interval is reduced.
After the profile is to find the highest point, the left prefix to the highest point of the maximum value and the right to the highest point and the maximum value of the prefix. They say only the left, right empathy:
the segment tree, dynamic range for each node represents the maximum maintenance prefix.
When the inquiry \ ([l, r] \ ) corresponding to \ (log \) intervals to find out, a good count.
The question is how to maintain.

First, a length of \ (L \) interval, the maximum number of modified prefix is \ (O (L) \) a.
Since they are a function of a number prefixed maximum at some point may become their own, and then change back to someone else sometime back, since then it can not become the maximum. Each primary function becomes a maximum value at the most, the number of modifications to \ (O (L) \)
Try to pretreatment at a point in time intervals greater than the number on the left.
When a node processing section represents the left half can be inherited by the son of the left over
the right half of it is fully larger than the interval may be calculated for all of the left son (the maximum value of the left son built piecewise function), and then son and take the right information.
Such time complexity is \ (O (n \ lg ^ 2n) \) a.

The next question is how to maintain the maximum prefix (support interval sum)
to consider a number becomes maximum when it will cover a broad range of its original maximum prefix covered.
When the number is no longer a maximum value, which was originally covered by the prefix interval is a maximum value of the covered position.
Modification of the form: the entire assignment for a certain interval number.
This modification seems to be collectively processed in the previous out pretreatment.
This thing can set a segment tree maintenance. Each number only once engage in, engage in a time complexity is \ (O (\ lg n) \) , a number will appear in the \ (O (\ lg n) \) of intervals, so the total time is \ (O (the n-\ the n-LG ^ 2) \)
PS: seems to be used Fenwick tree?

Final total time is \ (O (n-\ LG ^ n-2) \) .
I think there is actually std 5k, a little scary.
Means they are not playing, there is no chance to see the future.

Guess you like

Origin www.cnblogs.com/jz-597/p/12656489.html