BZOJ2253: [Beijing WC] carton stacking

Source: Internet
Author: User

Exercises

In fact, is to seek three-dimensional partial order the longest chain. Similar to the three-dimensional inverse pairs, we can use a tree-like array to set up a balanced tree to achieve.

DP equation: F[i]=max (f[j]+1) a[j]<a[i]

We sort by one-dimensional, another creates a tree-like array, and inserts the third dimension into each node of the tree-like array.

In addition to the weights, each node also maintains an MX that represents the largest f[i in the subtree].

So we can nlg^n.

UPD: Tried the treap without rotation will be card Orz

Code:

1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten  One#include <iostream> A  -#include <vector> -  the#include <map> -  -#include <Set> -  +#include <queue> -  +#include <string> A  at #defineINF 1000000000 -  - #defineMAXN 150000+5 -  - #defineMAXM 4000000+5 -  in #defineEPS 1e-10 -  to #definell Long Long +  - #definePA pair<int,int> the  * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) -  the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) +  A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the  + #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) -  $ #defineFor5 (N,M) for (int. i=1;i<=n;i++) for (int j=1;j<=m;j++) $  - #defineMoD 1000000007 -  the using namespacestd; - Wuyi inline ll read () the  - { Wu  -ll x=0, f=1;CharCh=GetChar (); About  $      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -  -      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -  A     returnx*F; +  the } - intN,TOT,CNT,B[MAXN],F[MAXN],RT[MAXN],C[MAXN],D[MAXN]; $ intH[MAXM],MX[MAXM],L[MAXM],R[MAXM],V[MAXM],VV[MAXM]; the structrec{intx, Y, Z;} A[MAXN]; the BOOL operator< (rec A,rec b) {returna.x<b.x;} theInlinevoidPushup (intk) the { -mx[k]=Max (Vv[k],max (Mx[l[k]],mx[r[k])); in } theInlinevoidLturn (int&k) the { About     intT=r[k];r[k]=l[t];l[t]=k;pushup (k);p ushup (t); k=T; the } theInlinevoidRturn (int&k) the { +     intT=l[k];l[k]=r[t];r[t]=k;pushup (k);p ushup (t); k=T; - } theInlinevoidInsertint&k,intXinty)Bayi { the     if(!k) the     { -K=++tot;v[k]=x;h[k]=rand (); vv[k]=mx[k]=y; -         return; the     } the     if(X==v[k]) vv[k]=Max (vv[k],y); the     Else if(X<v[k]) {Insert (l[k],x,y);if(h[k]<H[l[k]]) Rturn (k);} the     Else{Insert (r[k],x,y);if(h[k]<H[r[k]]) Lturn (k);} - Pushup (k); the } theInlineintGETMX (intKintx) the {94     if(!k)return 0; the     if(v[k]==x)returnMax (mx[l[k]],vv[k]); the     Else if(X<v[k])returngetmx (l[k],x); the     Else returnMax (max (mx[l[k]],vv[k)), GETMX (r[k],x));98 } AboutInlineintQueryintXinty) - {101     intret=0;102      for(;x;x-=x& (-X)) {ret=Max (RET,GETMX (Rt[x],y));}103     returnret;104 } theInlinevoidAddintXintYintz)106 {107      for(;x<=cnt;x+=x& (-x)) Insert (rt[x],y,z);108 }109InlineBOOLcmpintXintY) {returnb[x]<b[y];} the 111 intMain () the 113 { the  theFreopen ("Input.txt","R", stdin); the 117Freopen ("output.txt","W", stdout);118 119ll T=read (), P=read (); N=read (); b[0]=1; -For1 (I,3*n) b[i]= (LL) b[i-1]*t%p,c[i]=i;121Sort (c+1, c+3*n+1, CMP);122Cnt=0;123For1 (I,3*N)124     { the         if(i==1|| b[c[i]]!=b[c[i-1]]) cnt++;126d[c[i]]=CNT;127     } -For1 (i,n) a[i].x=d[3*i-2],a[i].y=d[3*i-1],a[i].z=d[3*i];129 For1 (i,n) the     {131         if(a[i].y>a[i].x) Swap (A[I].X,A[I].Y); the         if(a[i].z>a[i].x) Swap (A[I].X,A[I].Z);133         if(a[i].z>a[i].y) Swap (A[I].Z,A[I].Y);134     }135Sort (A +1, a+n+1);136      for(intL=1, r=1; l<=n;r++,l=R)137     {138          while(a[r+1].x==a[l].x) r++;139For2 (i,l,r) f[i]=query (a[i].y-1, a[i].z-1)+1;//cout<<i<< ' <<f[i]<<endl; $ For2 (i,l,r) Add (A[i].y,a[i].z,f[i]);141     }142     intans=0;143For1 (i,n) ans=Max (ans,f[i]);144cout<<ans<<Endl;145 146     return 0;147 148}
View Code 2253: [Beijing WC] carton stacking time limit:30 Sec Memory limit:256 MB
submit:246 solved:96
[Submit] [Status] Description

P Factory is a factory that produces cartons. Carton production line in the manual input three parameters n p a, after,
Can be automated production of three-side edge length for

(A mod p,a^2 mod p,a^3 mod P)
(a^4 mod p,a^5 mod p,a^6 mod p)
....
(a^ (3n-2) mod p,a^ (3n-1) mod p,a^ (3n) mod p)

of n cartons. In order to save space, they must be stacked in place when transporting these cartons.
A carton can be nested stacked into another carton when and only if its shortest side, second short edge and longest edge
Lengths are strictly smaller than the shortest, second, and longest side lengths of another carton. It's not considered here.
Any nested stacks rotated in the diagonal direction.
Your task is to find the largest subset of the n cartons, so that they can be between 22
nested stack up.

Input

The first line of the input file is three integers, representing a,p,n

Output


The output file contains only one integer, representing the maximum number of cartons that can be nested stacked.

Sample Input10 17 4
Sample Output
2
"Sample description"
The three-side length of the carton produced is (10, 15, 14), (4, 6, 9), (5, 16, 7), (2, 3, 13). of which only
(4, 6, 9) can be stacked in (5, 16, 7), so the answer is 2.
2<=p<=2000000000,1<=a<=p-1,a^k MoD p<>0,ap<=2000000000,1<=n<=50000

BZOJ2253: [Beijing WC] carton stacking

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.