Codeforces Round #424 (Div. 2, rated, based on VK Cup finals)
D. Office Keys
Test instructions: In a straight line, there is an office coordinate p, there are n people in a[i], there are k keys in b[i], everyone must get a key, and then to the office. Ask how to arrange to spend the shortest time.
Tags: still do not understand the routine AH. In fact, you can feel it with more than two paintings, 2333.
The key is to see thatn People take the key should be continuous.
Then, is the blind violence.
#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineRep (i,a,b) for (int i=a;i<=b;i++)#definePer (i,b,a) for (int i=b;i>=a;i--)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineMP Make_pair#definePB push_back#defineFi first#defineSe SecondtypedefLong Longll;Const intN =2005;intN, K;ll p, A[n], b[n];intMain () {scanf ("%d%d%lld", &n, &k, &p); Rep (I,1, N) scanf ("%lld", &A[i]); Rep (I,1, k) scanf ("%lld", &B[i]); Sort (a+1, A +1+N); Sort (b+1, B +1+k); ll ans=1e18; for(intBb\1; cb+n-1<=k; ++CB) {ll ans1=0; Rep (I,1, N) {ans1= Max (ANS1, ABS (a[i]-b[cb+i-1]) +abs (b[cb+i-1]-p)); } ans=min (ans, ans1); } printf ("%lld\n", ans); return 0;}
E. Cards sorting
Test instructions: N number, Operation: Remove the first number of each time, if it is the smallest of these numbers to delete, if not just put to the bottom. How many times does it take to remove the N number.
Tags: use set and tree arrays to quickly simulate operations. start thinking wrong, thinking is for once, each number will be greater than its number in front of the contribution, and finally found no, white toss half an hour, heart tired
#include <bits/stdc++.h>using namespacestd;#pragmaComment (linker, "/stack:102400000,102400000")#defineRep (i,a,b) for (int i=a;i<=b;i++)#definePer (i,b,a) for (int i=b;i>=a;i--)#defineMes (A, b) memset (A,b,sizeof (a))#defineINF 0x3f3f3f3f#defineMP Make_pair#definePB push_back#defineFi first#defineSe SecondtypedefLong Longll;Const intN =100005;structbit{intBi[n]; voidAddintXintY) { for(; x<n; x+=x&-x) bi[x]+=y;} ll sum (intx) {ll ans=0; for(; x>0; x-=x&-x) ans+=bi[x];returnans;}} bit;intN, A[n];Set<int>Se[n];intMain () {scanf ("%d", &N); Rep (I,1, N) {scanf ("%d", &A[i]); Se[a[i]].insert (i); Bit.add (i,1); } ll ans=0; intnow=1, mi=1; Rep (CI,1, N) { while(Se[mi].empty ()) + +mi; if(Se[mi].lower_bound (now)! =Se[mi].end ()) { intpos=Now ; now= *Se[mi].lower_bound (now); Ans+ = Bit.sum (now)-bit.sum (pos-1); } Else { intpos=Now ; now= *se[mi].lower_bound (1); Ans+ = Bit.sum (n)-bit.sum (pos-1)+Bit.sum (now); } se[mi].erase (now); Bit.add (now,-1); } printf ("%lld\n", ans); return 0;}
Codeforces Round #424 (Div. 2) D-thinking E Set application, tree-like array