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<=L&&R<=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