POJ 1769 minimizing Maximizer

Source: Internet
Author: User
Tags define local

Dp[i = Sorter][j in front i = move min to j position] = Shortest sorter sequence.

For Sorteri, it only updates the position of its right endpoint R, so you can change the array to one-dimensional, dp[r] = min (dp[r],dp[j]+1), L≤j<r.

Not a sliding window, the monotone queue is not used, but can be used to maintain the minimum value line tree.

/**********************************************************            ------------------                          ** Author Abyssalfish ***********************************************************/#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<queue>#include<vector>#include<stack>#include<vector>#include<map>#include<Set>#include<algorithm>#include<cmath>using namespacestd;#definepara int o = 1, int l = 1,int r = N#defineTEMPvar int mid = (l+r) >>1, LC = (o<<1), rc = (o<<1|1);#defineLSN LC, L, mid#defineRSN RC, mid+1, R#defineINSD QL&LT;=L&AMP;&AMP;R&LT;=QRConst intMAXN =5e4;Const intSt_size =1<< -;Const intINF =0x3f3f3f3f;intMin[st_size];intN, M;intdp[maxn+1];voidbuild (para) {if(L = =R) {Min[o]=Dp[l]; }Else{TEMPvar build (LSN);        Build (RSN); Min[o]=min (MIN[LC],MIN[RC]); }}intQpos,qval;voidupdate (para) {if(L = =R) {Min[o]=Qval; }Else{TEMPvarif(qpos<=mid) Update (LSN); ElseUpdate (RSN); Min[o]=min (MIN[LC],MIN[RC]); }}intQL,QR;intQmin (para) {if(INSD) {returnMin[o];} Else {        intres =INF; TEMPvarif(ql<=mid) res =min (res,qmin (LSN)); if(qr>mid) res =min (res,qmin (RSN)); returnRes; }}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endifscanf ("%d%d",&n,&m); memset (DP+2,0x3f,sizeof(int) * (n1));    Build ();  for(inti =0; I < m; i++) {scanf ("%d%d",&ql,&QR); if((Qval = qmin () +1) <DP[QR]) {Dp[qpos= QR] =Qval;        Update (); }} printf ("%d\n", Dp[n]); return 0;}

POJ 1769 minimizing Maximizer

Related Keywords:

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.