LOJ #6282. Getting started with series partitioning 6,

Source: Internet
Author: User

LOJ #6282. Getting started with series partitioning 6,
Memory limit: 256 MiB time limit: 500 ms standard input/output question type: traditional evaluation method: text comparison uploaded by: hzwer submit Record Statistics Discussion test data question description

A series of nnn operations and nnn operations are provided. The operations involve Single Point Insertion, single point inquiry, and random data generation.

Input Format

Enter a number nnn in the first line.

Enter nnn numbers in the second row. the I-th digit is aia_iai, separated by spaces.

Next, enter the nnn line and enter four numbers in each line: opt \ mathrm {opt} opt, lll, rrr, and ccc, separated by spaces.

If opt = 0 \ mathrm {opt} = 0opt = 0, the number rrr is inserted before the lll number (ccc ignored ).

If opt = 1 \ mathrm {opt} = 1opt = 1, The ara_rar value is queried (lll and ccc are ignored ).

Output Format

For each query, a row of numbers is output to indicate the answer.

Sample Input
41 2 2 30 1 3 11 1 4 40 1 2 21 1 2 4
Sample output
23
Data range and prompt

For data of 100% 100 \ % 100%, 1 ≤ n ≤ 100000, − 231 ≤ others 1 \ leq n \ leq 100000, -2 ^ {31} \ leq \ mathrm {others} 1 ≤ n ≤ 100000, − 231 ≤ others, ans ≤ 231 − 1 \ mathrm {ans} \ leq 2 ^ {31}-1ans ≤ 231 − 1.

 

Use vector to maintain a bulk linked list

Data is random, So reconstruction is not required.

But the speed is the penultimate

 

 

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<cmath>using namespace std;const int MAXN=1e5+10;inline int read(){    char c=getchar();int x=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}    return x*f;}vector<int>v[MAXN];int a[MAXN],belong[MAXN],block;int main(){    int N=read();block=sqrt(N);    for(int i=1;i<=N;i++) a[i]=read(),belong[i]=(i-1)/block+1;        for(int i=1;i<=N;i++) v[belong[i]].push_back(a[i]);    for(int i=1;i<=N;i++)    {        int opt=read(),l=read(),r=read(),c=read();        if(opt==0)        {            for(int i=1;i<=belong[N];i++)            {                if(l<=v[i].size()) {v[i].insert(v[i].begin()+l-1,r);break;}                else l-=v[i].size();            }        }        else        {            for(int i=1;i<=belong[N];i++)            {                if(r<=v[i].size()) {printf("%d\n",v[i][r-1]);break;}                    else r-=v[i].size();            }        }    }    return 0;}

 

 

 

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.