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;}