[Examination Reflection] 0917csp-s Simulation Test 45: destiny

He poured a a.

About mentality, many say.

First, I sat next to a kx. He T1 did not take long to start up the cut and then began to pat hundreds of thousands of group AC.

However, I think that T1 is immortal title. Advanced T2.

Very simple, 5 minutes a positive solution, then suddenly had an idea playing out of time, the feeling is equivalent, according to later have beaten that idea.

However, simply do not want to, in fact, the latter is wrong, wrong is extremely funny, casually can hack.

But I do not have to prove there is no hack, put positive solution buried.

A large sample had to pay, decisive burst zero.

This is the skyh start bitchy, I looked at the others began to laugh, and I despise him again after mikufun continue to answer.

Then into T3. It is clearly a data structure that.

I miss the idea is still relatively, want to spend 15 minutes was thought out.

But instantly found knowledge with this problem a bit more: chain modification, seeking the right side between two points maximum, minimum spanning tree.

I.e. lct / + tree split Kruskal chain. . . Smoked my mind a bit lca also doubled and seek distance

More time left, I had a fatal idea:

I usually did on the test A basic data structure that out too, so do not go conducive to development.

So I decided to sleep naturally on the road to positive solutions.

Two virtual battalion commander of the air conditioning off, then I'm already far away from the air conditioning, especially hot. . .

Then strike dizziness, feeling body temperature up, and look at the screen have gradually been ghosting (in fact, the problem of the screen)

Chose a slightly harder keyboard knock does not move, playing a variety of board process is extremely painful. . .

Anyway, two hours, playing out, had lost large sample, excellent mood.

I feel this is one of the few I can get rid of large data structures on the exam questions.

The data is then pan, and only 10 points.

Thank data returned no particular dog feces left me 10 minutes, or I will burst at zero in this test.

I do not know the examination room, I thought I lost two of A. I feel like I'm in good shape, although dizziness, sweating profusely.

Another hour to T1, I thought I kx next few minutes to cut T1, I feel I should be.

However, I feel the state has not withstand, and go out through the wind, scattered heat, slow brain a bit.

But still I will not, as always, want to use the network flow fucks bipartite graph matching.

According to the data range is said to be 60 minutes? Then 260 should not be too low.

So no longer want to run the risk of positive solutions, and began to tune the network flow.

The cycle of death, adjusting for a while, and after a large sample. Pay, 70 points.

Feeling array open big fear MLE, he opened a little small, large sample and try it again, and then pay.

This time, forgot to delete the freopen, with 0 to 70 points off the cover.

Over, out of 10 points.

Mentality or not: expect too much . The examination room must not blind confidence.

And then there's the final minutes of anxious easily cause wrong . This is the second time freopen pan.

Further subject difficulty level determination is also a problem . After the first T3 T1 is a huge mistake. . .

Do not believe a large sample! ! ! Be sure to take on! ! !

Do not think too much. High score is king.

So be it.

 

T1:

It is said nlog can do without.

Two kinds of the n- 2 are very miss. But we need to find a property.

Nature is a strange fight is a continuous interval enumerator to the first fight can be.

Another property is sorted after by location, everyone playing every strange position is incremented.

Two properties are very good card, but it is not easy to find on the test.

Then you can dp fucks up.

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 using namespace std;
 5 int abs(int p){return p>0?p:-p;}
 6 int dp[5005][5005],n,m,s,p[5005],q[5005];
 7 int main(){
 8     scanf("%d%d%d",&n,&m,&s);
 9     for(int i=1;i<=n;++i)scanf("%d",&p[i]);
10     for(int i=1;i<=m;++i)scanf("%d",&q[i]);
11     sort(p+1,p+1+n);sort(q+1,q+1+m);memset(dp,0x3f,sizeof dp);
12     for(int i=0;i<=m;++i)dp[i][0]=0;
13     for(int i=1;i<=m;++i)for(int j=1;j<=n;++j)
14         dp[i][j]=min(dp[i-1][j],max(dp[i-1][j-1],abs(p[j]-q[i])+abs(s-q[i])));
15     printf("%d\n",dp[m][n]);
16 }
View Code
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int fir[10005],l[25000005],to[25000005],cnt,n,m,p[5005],q[5005],s,dep[10005];
 5 bool v[25000005];int qu[10005];
 6 int abs(int p){return p>0?p:-p;}
 7 void link(int a,int b,int vv){
 8     l[++cnt]=fir[a];fir[a]=cnt;to[cnt]=b;v[cnt]=vv;
 9 }
10 bool bfs(){
11     int top=1;for(int i=1;i<=n+m+1;++i)dep[i]=-1;
12     for(int qh=1;qh<=top;++qh)for(int i=fir[qu[qh]];i;i=l[i])if(v[i]&&dep[to[i]]==-1)
13         dep[to[i]]=dep[qu[qh]]+1,qu[++top]=to[i];
14     return dep[n+m+1]!=-1;
15 }
16 int dfs(int p,int flow){//printf("%d %d\n",p,flow);
17     if(p==n+m+1)return flow;
18     int res=flow;
19     for(int i=fir[p];i;i=l[i])if(dep[to[i]]==dep[p]+1&&v[i]&&res){
20         int acs=dfs(to[i],1);
21         if(!acs){dep[to[i]]=0;continue;}
22         v[i]=0;v[i^1]=1;res--;
23     }
24     return flow-res;
25 }
26 bool chk(int tim){
27     int maxflow=0;
28     for(int i=0;i<=n+m+1;++i)fir[i]=0;cnt=1;
29     for(int i=1;i<=n;++i)link(0,i,1),link(i,0,0);
30     for(int i=1;i<=m;++i)link(n+i,n+m+1,1),link(n+m+1,n+1,0);
31     for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(abs(p[i]-q[j])+abs(q[j]-s)<=tim)
32         link(i,n+j,1),link(n+j,i,0);
33     while(bfs())maxflow+=dfs(0,n);//,printf("%d\n",maxflow);
34     return maxflow==n;
35 }
36 int main(){freopen("kill.in","r",stdin);
37     scanf("%d%d%d",&n,&m,&s);
38     for(int i=1;i<=n;++i)scanf("%d",&p[i]);
39     for(int j=1;j<=m;++j)scanf("%d",&q[j]);
40     int l=0,r=2000000000;
41     while(l<r-1)if(chk(l+r>>1))r=l+r>>1;else l=(l+r>>1)+1;
42     if(chk(l))printf("%d\n",l);else printf("%d\n",r);
43 }
After removing the freopen violence is 70 minutes (half the answer, the network flow determination)

The accumulation of ideas:

  • I guess nature, discover the nature of proved properties.
  • Fig promiscuity network flow bipartite matching.
  • We can not directly ask the network flow for maximum weights, using half the answer.

 

T2:

greedy.

When back from the bottom up, you certainly do not want the sub-tree in the point pairs, so that they extend up together clearly would answer better.

But if the number of points outside the sub-tree can be paired sub-tree which has no more, then it must be paired here a few.

It can not be understood as follows: If the sub-tree superfluous k must be paired wrong.

Twice dfs.

 1 #include<cstdio>
 2 int n,k,a,fir[100005],l[200005],to[200005],cnt,siz[100005],r[100005];long long ans;
 3 void link(int a,int b){l[++cnt]=fir[a];fir[a]=cnt;to[cnt]=b;}
 4 void dfs(int p,int fa){
 5     r[p]=siz[p];
 6     for(int i=fir[p];i;i=l[i])if(to[i]!=fa)dfs(to[i],p),siz[p]+=siz[to[i]];
 7 }
 8 void DFS(int p,int fa){
 9     for(int i=fir[p];i;i=l[i])if(to[i]!=fa)DFS(to[i],p),r[p]+=r[to[i]],ans+=r[to[i]];
10     if(p==1)return;
11     while(r[p]>k*2-siz[p])r[p]-=2;
12 }
13 int main(){//freopen("beauty.in","r",stdin);
14     scanf("%d%d%d",&n,&k,&a);
15     for(int i=1,x;i<=k<<1;++i)scanf("%d",&x),siz[x]++;
16     for(int i=1,x,y;i<n;++i)scanf("%d%d",&x,&y),link(x,y),link(y,x);
17     dfs(1,0);DFS(1,0);printf("%lld\n",ans);
18 }
View Code

The accumulation of ideas:

  • Greedy tree: Consider chain elongation.
  • Do not opportunistic, carefully written expression, carefully proof.

 

T3:

Data pan, does not guarantee Unicom, not all the numbers 1:00 Unicom's side the answer is zero.

Because std from 1 node to start dfs, so no point did not update Unicom, the answer is zero.

Observation of the subject, since the subject has been said that the minimum spanning tree, then came up with the minimum spanning tree come.

Found: has the edge in the trees, the answer must be smaller than the current weight of more than 1, for non-tree edge answers to some small weights than the current value.

For non-tree edge, as long as its weight is smaller than the maximum value of edge weights between two points corresponding to the minimum spanning tree, then it can be substituted into the minimum spanning tree that edge.

For the side of the tree, it can not be replaced, so it is smaller than the minimum value of all of this edge through a non-tree edges.

Chain modified trees distance between two points, a single point of inquiry.

lct board. The split tree or chain. Doubling or off-line processing (recommended zkt, and a good fight). cbx said segment tree can merge.

The idea is not difficult, the key lies in implementation.

Because the data has pot, so you can not judge whether p is top heavy chains use the "father of the son of whether p re p" is. You will be blown to 10 points.

1  // For the rim, the answer is no longer a minimum spanning tree is a maximum between two sides -1
 2  // updates the answer, it will cover all sides of the strand, on all sides of this chain -1 answer their weights taken min
 . 3  // EU operation - chain split tree? lct? 
. 4 #include <cstdio>
 . 5 #include <algorithm>
 . 6  the using  namespace STD;
 . 7  int n-, m, A, FIR [ 70005 ], L [ 200005 ], to [ 200005 ], SIZ [ 70005 ], CNT, HSON [ 70005 ], TFE [ 70005 ];
 . 8  int ANS [ 200005 ], Top [ 70005 ], DEP [ 70005 ], F [ 70005 ] [20],mx[70005][20],v[200005];
 9 int len[70005],tcnt,lc[1000005],rc[1000005],w[1000005],rt[70005],lz[1000005];
10 int cl[1000005],cr[1000005],tmp[70005],g[200005];
11 void build(int &p,int l,int r){
12     p=++tcnt;w[p]=1234567890;
13     cl[p]=l;cr[p]=r;
14     if(l==r)return;
15     build(lc[p],l,l+r>>1);
16     build(rc[p],(l+r>>1)+1,r);
17 }
18 void down(int p){//printf("%d %d %d %d %d\n",p,lc[p],rc[p],w[lc[p]],w[rc[p]]);
19     w[lc[p]]=min(w[lc[p]],lz[p]);
20     w[rc[p]]=min(w[rc[p]],lz[p]);
21     if(lz[lc[p]])lz[lc[p]]=min(lz[lc[p]],lz[p]);else lz[lc[p]]=lz[p];
22     if(lz[rc[p]])lz[rc[p]]=min(lz[rc[p]],lz[p]);else lz[rc[p]]=lz[p];
23     lz[p]=0;//printf("%d %d %d %d %d\n",p,lc[p],rc[p],w[lc[p]],w[rc[p]]);
24 }
25 void set(int p,int l,int r,int W){//printf("%d %d %d %d %d %d\n",p,l,r,w,cl[p],cr[p]);
26     if(l<=cl[p]&&cr[p]<=r){if(lz[p])lz[p]=min(lz[p],W);else lz[p]=W;w[p]=min(w[p],W);return;}
27     if(l<=cr[lc[p]])set(lc[p],l,r,W);
28     if(r>=cl[rc[p]])set(rc[p],l,r,W);
29 }
30 void ask(int p){//printf("%d\n",p);
31     if(cl[p]==cr[p]){tmp[cl[p]]=w[p];return;}
32     if(lz[p])down(p);
33     ask(lc[p]);ask(rc[p]);
34 }
35 struct edge{
36     int a,b,v,num;
37     friend bool operator<(edge a,edge b){return a.v<b.v;}
38 }e[100005];
39 void link(int a,int b,int vv,int gg){l[++cnt]=fir[a];fir[a]=cnt;to[cnt]=b;v[cnt]=vv;g[cnt]=gg;}
40 int fa[70005],in[100005];
41 int find(int k){return fa[k]==k?k:fa[k]=find(fa[k]);}
42 void Kruscal(){
43     sort(e+1,e+1+m);
44     for(int i=1;i<=n;++i)fa[i]=i;
45     for(int i=1;i<=m;++i)if(find(e[i].a)!=find(e[i].b))
46         fa[fa[e[i].a]]=fa[e[i].b],in[e[i].num]=1,
47         link(e[i].a,e[i].b,e[i].v,e[i].num),link(e[i].b,e[i].a,e[i].v,e[i].num);
48 }
49 void dfs(int p,int fa){
50     siz[p]=1;dep[p]=dep[fa]+1;f[p][0]=fa;
51     for(int i=1;i<=18;++i)f[p][i]=f[f[p][i-1]][i-1],mx[p][i]=max(mx[p][i-1],mx[f[p][i-1]][i-1]);
52     for(int i=fir[p];i;i=l[i])if(to[i]!=fa){
53         mx[to[i]][0]=v[i];
54         dfs(to[i],p),siz[p]+=siz[to[i]],tfe[to[i]]=g[i];
55         if(siz[to[i]]>siz[hson[p]])hson[p]=to[i];
56     }
57 }
58 void DFS(int p,int tp){
59     top[p]=tp;len[tp]=dep[p]-dep[tp]+1;
60     for(int i=fir[p];i;i=l[i])if(to[i]!=f[p][0]&&to[i]!=hson[p])DFS(to[i],to[i]);
61     if(hson[p])DFS(hson[p],tp);
62 }
63 int lca(int a,int b){
64     if(dep[a]<dep[b])swap(a,b);
65     int subdep=dep[a]-dep[b];
66     for(int i=18;~i;--i)if(subdep&1<<i)a=f[a][i];
67     if(a==b)return a;
68     for(int i=18;~i;--i)if(f[a][i]!=f[b][i])a=f[a][i],b=f[b][i];
69     return f[a][0];
70 }
71 int cal(int p,int fa){
72     int re=0,subdep=dep[p]-dep[fa];
73     for(int i=18;~i;--i)if(subdep&1<<i)re=max(re,mx[p][i]),p=f[p][i];
74     return re;
75 }
76 void update(int p,int fa,int w){
77     while(top[p]!=top[fa]){
78         set(rt[top[p]],1,dep[p]-dep[top[p]]+1,w);
79         p=f[top[p]][0];
80     }
81     if(p!=fa)set(rt[top[p]],dep[fa]-dep[top[p]]+2,dep[p]-dep[top[p]]+1,w);
82 }
83 void dfs_hson(int p,int ord){
84     ans[tfe[p]]=tmp[ord]-1;
85     if(hson[p])dfs_hson(hson[p],ord+1);
86 }
87 int main(){//freopen("weight.in","r",stdin);
88     scanf("%d%d%d",&n,&m,&a);
89     for(int i=1;i<=m;++i)scanf("%d%d%d",&e[i].a,&e[i].b,&e[i].v),e[i].num=i;
90     Kruscal();DFS ( 1,0);DFS(1,1);
91     for(int i=1;i<=n;++i)if(len[i])build(rt[i],1,len[i]);
92     for(int i=1;i<=m;++i)if(!in[e[i].num]){
93         int LCA=lca(e[i].a,e[i].b),DT=max(cal(e[i].a,LCA),cal(e[i].b,LCA));
94         ans[e[i].num]=DT-1;
95         update(e[i].a,LCA,e[i].v);update(e[i].b,LCA,e[i].v);
96     }
97     for(int i=1;i<=n;++i)if(hson[f[i][0]]!=i)ask(rt[i]),dfs_hson(i,1);//for(int i=1;i<=4;++i)printf("%d\n",tmp[i]);
98     for(int i=1;i<=m;++i)if(ans[i]==1234567889)printf("-1 ");else printf("%d ",ans[i]);
99 }
View Code

The accumulation of ideas:

  • Chain modified in various ways: lct, skilled split.
  • Offline.
  • The nature of the minimum spanning tree.
  • Son skilled split weight determination method.

 

Guess you like

Origin www.cnblogs.com/hzoi-DeepinC/p/11543317.html