6.11 Exam Revision + Summary

Source: Internet
Author: User

The third question so far did not dare to write, feel good terror qaq

It was a bad test today.

The first question only wrote 10 points of violence + (k=1) 20 points of the network stream

Later the problem told me K>1 can be divided into k=1, each layer of the solution is the same k=1

The examination did not notice the 2^k this more magical can be divided into the nature of the

And his examination room on the silk thin, did not find because it is a binary graph can be directly run the nature of the Euler loop, but the bare set of network flow model

The second question is actually close to figuring out the problem

The success of your own exams proves that the complexity of violence is linear.

But no idea how to find 0-1 pairs, and then only violence with splay maintenance 1 location

Silently praying data don't get too stuck in my practice, the result was only 10 points more than bare violence, just sad

Test heel ZCG Exchange A look at the maintenance of the hash value every time you can find 0-1 pairs of (the examination room on what to think about the series

But this will be T or WA (because of the seemingly natural overflow of cards?) You can just change some base.

Another approach is to split the interval directly on the segment tree, and then if the interval of equal value of the hash is not recursive, the recursion is changed

The complexity of time is somewhat metaphysical, but it runs faster than hash+.

I write the seemingly will t a point, but lazy play constant optimization

The third problem seems to be the weakening version of the dragon fruit

But LCT to maintain some strange things, when the exam did not think out how to maintain

Later see the solution found maintenance method similar to the crazy center of gravity, LCT maintenance subtrees

Each time the violence to delete the largest side to see if you can not lose the solution

But it feels like a piece of crap, a good beast.

was inexplicable card the constant, lost 20 points of violence divided Qaq

Finally seems to be handed over to the OJ Rank2?

%%%zcg

First question code:

Write the Euler circuit when the comparison of the ghost animal, but also can only write to ensure the nature of O (M) (yy for a long time, thank jkxing

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < Cstdlib> #include <set>using namespace std;const int maxn=400010;int n,m,k,t;int deg[maxn];struct Edge{int u,v, ID;} C[maxn],q1[maxn],q2[maxn];int ans[maxn];int h[maxn],cnt=0;bool vis[maxn];int check[maxn],tim;int st[maxn],top=0; struct Edge{int to,next,w;} g[maxn];void Add (int x,int y,int z=0) {++cnt; G[cnt].to=y; G[CNT].NEXT=H[X]; G[cnt].w=z;h[x]=cnt;vis[cnt]=false;} void read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ') Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();} void Get_euler (int u,int f) {check[u]=tim;for (int i=h[u];i;i=h[u]) {if (Vis[i]) {h[u]=g[i].next;continue;} int v=g[i].to;vis[i]=vis[i^1]=true; G[i].w=g[i^1].w=f;h[u]=g[i].next; Get_euler (v,f^1);} return;} void Solve (int l,int r,int k) {if (!k) return;cnt=1;tim++;top=0;for (int i=l;i<=r;++i) {int U=c[i].u,v=c[i].v;add (U,V) ; Add (v,u); if (Check[u]!=tim) check[u]=tim,st[++top]=u;if (check[v]!=tim) check[v]=tim,st[++top]=v;} tim++;for (int i=1;i<=top;++i) {if (Check[st[i]]!=tim) Get_euler (st[i],0);} int l1=0,l2=0;for (int i=l;i<=r;++i) {int now= (i-l+1) <<1;int u=c[i].id;h[c[i].u]=h[c[i].v]=0; ans[u]= (ans[u]<<1) | G[now].w;if (G[NOW].W) Q2[++l2]=c[i];else q1[++l1]=c[i];} for (int i=1;i<=l1;++i) c[l+i-1]=q1[i];for (int i=1;i<=l2;++i) c[l+l1+i-1]=q2[i]; Solve (l,l+l1-1,k-1); Solve (l+l1,r,k-1);} int main () {int __size__=128<<20;char *__p__= (char*) malloc (__size__) +__size__;__asm__ ("Movl%0,%%esp\n":: "R" ( __p__) while (scanf ("%d%d", &n,&m) ==2) {memset (deg,0,sizeof (deg)); for (int i=1;i<=m;++i) {read (C[I].U); Read (C[I].V); c[i].id=i;deg[c[i].u]++;d eg[c[i].v]++;} for (k=1;k;++k) {int mk= (1<<k), bool flag=false;for (int i=1;i<=n;++i) if (deg[i]%mk!=0| |! Deg[i]) {flag=true;break;} if (flag) break;} K--;if (!k) printf (" -1\n"); Else{memset (Ans,0,sizeof (Ans)); Solve (1,m,k);p rintf ("%d\n", K), for (int i=1;i<=m;++i) printf ("%d", ans[i]+1);p rintf ("\ n");}} return 0;}

Second question code:

#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include < Algorithm>using namespace Std;typedef long long ll;const int maxn=1000010;const int Base=13331;int n,m,type,l,r,len,p , X,y;char S[maxn];int sum[maxn<<2]; LL XP[MAXN]; LL h[maxn<<2];void Read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ') Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();} void build (int o,int l,int R) {if (l==r) {h[o]=s[l];sum[o]=h[o]-' 0 '; return;} int mid= (L+R) >>1;int l= (o<<1), r= (l|1); build (L,l,mid); build (r,mid+1,r); h[o]=h[l]*xp[r-mid]+h[r];sum[o ]=SUM[L]+SUM[R];} void UPD (int o,int l,int R) {if (l==r) {H[o]^=1;sum[o]^=1;return;} int mid= (L+R) >>1;int l= (o<<1), r= (l|1), if (P<=mid) upd (L,l,mid), Else upd (r,mid+1,r); h[o]=h[l]*xp[ R-MID]+H[R];SUM[O]=SUM[L]+SUM[R];} LL Ask (int o,int l,int R) {if (l>=x&&r<=y) return h[o];int mid= (l+r) >>1;if (Y<=mid) return Ask (O &LT;&LT;1,L,MID); else if (X>mid) rEturn Ask (o<<1|1,mid+1,r); Else{ll a=ask (O<<1,l,mid); LL B=ask (o<<1|1,mid+1,r); return A*xp[min (Y,r)-mid]+b;} int ask_s (int o,int l,int R) {if (l>=x&&r<=y) return sum[o];int mid= (l+r) >>1;if (y<=mid) return ask _s (o<<1,l,mid); else if (X>mid) return ask_s (o<<1|1,mid+1,r), Else return ask_s (o<<1,l,mid) +ask_s (o<<1|1,mid+1,r);} int main () {freopen ("and.in", "R", stdin), Freopen ("And.out", "w", stdout); Read (n); read (m); scanf ("%s", s+1); xp[0]=1; for (int i=1;i<=n;++i) Xp[i]=xp[i-1]*base;build (1,1,n), while (m--) {read (type), if (type==1) {read (L); Read (R); Read ( len); int L=1,r=len;while (TRUE) {while (l<r) {int mid= (L+R) >>1;x=L;y=L+mid-1; LL A=ask (1,1,n); x=r;y=r+mid-1; LL B=ask (1,1,n); if (a==b) L=mid+1;else R=mid;} X=l+r-1;y=r+r-1;int a=s[x]-' 0 ', b=s[y]-' 0 ', if (a==b) break;if (a==1) s[x]= ' 0 ', p=x,upd (1,1,n); else s[y]= ' 0 ', p=y,upd ( 1,1,n); l=r;r=len;}} else if (type==2) {read (L);p =l;if (s[l]== ' 1 ') s[l]= ' 0 '; else s[l]= ' 1 '; UPD (1,1,n);} Else{read (L); Read (R); read (len); x=l;y=r; int now=ask_s (1,1,N); if (len==1) printf ("%d\n", now), else printf ("%d\n", R-l+1-now);}} return 0;}

The third question, see if they can zcg.

I feel like I'm going to write one night pill.

6.11 Exam Revision + Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.