Libreoj 6282. Getting Started with series Chunking 6

Source: Internet
Author: User

Title Link: https://loj.ac/problem/6282

Reference Blog: http://www.cnblogs.com/stxy-ferryman/p/8560551.html

If you use an array to move the element to the right will definitely time out, if you query with the linked list O (n), n times the inquiry is O (n^2), and then just glanced at a few other people's blog, with a block of words mainly like the query location, inserting elements, refactoring three operations, The query is to find the point in the first few layers of the location (using a vector), is probably the √n of time complexity, because it is divided into √n block, and then can be inserted after finding the position, but also √n, because the insertion of the element to the right, and because the extreme data may be inserted in a block of elements, So the element inside the block may be much more than the other blocks, resulting in the time complexity of the query becomes n, so we have to re-block all the elements, so the time complexity of the refactoring is √n, I think they are when a block of elements greater than 10*√n, the front 10 of the coefficient should be able to see their own conditions, In this case, the number of refactoring is less than √n times, the overall time complexity will not add, ^_^, anyway, is much lower than the n^2 is ....

Code:

#include <iostream>#include<cstring>#include<algorithm>#include<queue>#include<map>#include<stack>#include<cmath>#include<vector>#include<Set>#include<cstdio>#include<string>#include<deque>using namespaceStd;typedefLong LongLL;#defineEPS 1e-8#defineINF 0x3f3f3f3f#defineMAXN 100005/*struct point{int u,w;};    BOOL operator < (const point &s1,const point &s2) {if (S1.W!=S2.W) return s1.w>s2.w; else return s1.u>s2.u;}*/intlump[maxn],a[maxn*2];//lump array is not used, can not, a array is the same as the next refactoring to save all the elementsvector<int>ve[1010];//the elements that exist on each layerintN,m,k,t,block,max;//Max is used to save up to how many layerspair<int,int> Query (intL//This function is used to find the first L element in the first few layers, returning a pair<int,int> type{//its fist represents the number of layers, second represents the first, and the vector elements start from 0    intpos=1;  while(l>ve[pos].size ()) {L-=ve[pos].size (); POS++; }    returnMake_pair (pos,l-1);}voidRebuild ()//Refactoring Operations{    inttop=0;  for(intI=1; i<=max;i++)    {         for(intj=0; J<ve[i].size (); j + +) {a[++TOP]=VE[I][J];//Save all the elements.} ve[i].clear ();//Remember to empty    }    intBLOCK1=SQRT (top);//the size of the new block     for(intI=1; i<=top;i++) {ve[(i-1)/block1+1].push_back (A[i]); } Max= (top-1)/block+1;}voidInsertintLintR) {Pair<int,int>w=query (l);//Find a locationVe[w.first].insert (Ve[w.first].begin () +w.second,r);//inserting elements    if(Ve[w.first].size () >block*Ten)//if the block is too large to refactor, but I don't know why the block cannot become a new blockrebuild ();}intFindintLintR) {Pair<int,int>w=query (R); returnVe[w.first][w.second];}intMain () {scanf ("%d",&N); Block=sqrt (n);  for(intI=1; i<=n;i++)    {        intx; scanf ("%d",&x); Lump[i]= (I-1)/block+1;    Ve[lump[i]].push_back (x); } Max= (n1)/block+1;  for(intj=1; j<=n;j++)    {        intOp,l,r,c; scanf ("%d%d%d%d",&op,&l,&r,&c); if(!op) Insert (L,R); Else        {            intans=find (L,R); printf ("%d\n", ans); }    }    return 0;}

Libreoj 6282. Getting Started with series Chunking 6

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.