3192: [JLOI2013] Delete Item
Time Limit:10 Sec Memory limit:128 MB
submit:668 solved:400
[Submit] [Status] [Discuss]
Description
The case redistribution problem needs to address the following issues:
(1) A total of n items, piled into m heap.
(2) All items are the same, but they have different priorities.
(3) You can only move items at the top of a pile.
(4) You can move any item in the top of any pile to the top of another heap. If the item is the highest priority in all current items, it can be deleted without moving it directly.
(5) Find out the minimum number of steps required to remove all items. The delete operation does not count toward the number of steps.
(6) Just a more difficult problem to solve, here you just need to solve a relatively simple version:
No two items have the same priority, and m=2
Input
The first line consists of two integer n1,n2 that represent the number of items in the two stacks.
Next, N1 line integers give priority to the first pile of items according to the order from top to bottom, and the higher the number, the greater the priority.
The next N2 line gives priority to the second pile of items in the same format.
Output
For each data, output an integer, which is the minimum number of steps to move.
Sample Input
3 3
1
4
5
2
7
3
Sample Output
6
HINT
1<=n1+n2<=100000
Source
Ideas
Interval summation + single point modification.
A very clever reorganization of the data, for example, the samplereorganization to 73, given two pointer t1/t2, pointing to two piles of top, so that the so-called move operation has become the pile top pointer sliding. Existence set 1, single point modification, bit sum can be.
Note that ANS is a long long.
Code
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 #definefor (A,B,C) for (int a= (b); a<= (c); a++)6 using namespacestd;7 8typedefLong LongLL;9 Const intMAXN =100000+Ten;Ten One intRead () { A CharC=GetChar (); - while(!isdigit (c)) c=GetChar (); - intx=0; the while(IsDigit (c)) { -x=x*Ten+c-'0'; -C=GetChar (); - } + returnx; - } + A intA[MAXN],RANK[MAXN],TMP[MAXN]; at intn,m,t1,t2; - - intcmpConst int& I,Const int& j) {returnA[i]>A[j]; - } - - intC[MAXN]; in intLowbit (intx) {returnx& (-x); - } to voidADD (intXintd) { + while(x<=N) { -c[x]+=D; thex+=lowbit (x); * } $ }Panax Notoginseng intSum (intx) { - intres=0; the while(x>0) { +res+=C[x]; Ax-=lowbit (x); the } + returnRes; - } $ intMain () { $N=read (), m=read (); -t1=n,t2=t1+1; -for (I,1, N) a[i]=read (); thefor (i,n+1, n+m) a[i]=read (); -for (I,1, N) tmp[i]=a[n-i+1];Wuyifor (I,1, N) a[i]=Tmp[i]; then + =m; -for (I,1, n) rank[i]=i,add (i,1); Wu -Sort (rank+1, rank+n+1, CMP); About $LL ans=0;//Long Long type -for (I,1, N) { - intt=Rank[i]; - if(t>=T2) { AAns+=sum (t)-sum (t2-1)-1; +ADD (t,-1); thet2=t;t1=t2-1; - } $ Else { theAns+=sum (t1)-sum (t1)-1; theADD (t,-1); thet1=t; t2=t1+1; the } - } inprintf"%lld\n", ans); the return 0; the}
bzoj3192 [JLOI2013] Deleting items