LOJ6282 block entry columns 6

LOJ6282 number of columns of block entry 6

label

  • Block entry

Foreword

  • This is a one-off problem ~

Concise meaning of the questions

  • Maintenance sequence, supports two modes of operation:
    1. Insert: prior to the l-th element into an element
    2. Search: Find the r-th element value

Thinking

  • Directly open a vector [] to save all per piece. For the insertion operation, directly to the corresponding block, then this is a call to insert vector. For query operations, directly to the positional deviation in the past, then the query just fine.
  • This data problem is random. If it is constructed, it may be many times more than the same block operation, the size of this one will become large. Complexity'll explode. Introduces the idea here called reconstructed Once the block size \ (> 2 \ n-sqrt {} \) , then this block is divided into two, the complexity is \ (O (\ frac {n } { \ sqrt {n}}) \ )

    Precautions

  • no

to sum up

  • no

AC Code

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

const int maxn = 1e5 + 10;

int n, a[maxn];
int pos[maxn], len;
vector<int> b[maxn];

void change(int l, int r, int c)
{
    int pt = 1, sum = b[1].size();
    while (sum < l) pt++, sum += b[pt].size();

    b[pt].insert(b[pt].begin() + l - (sum - b[pt].size()) - 1, r);
}

int cal(int l, int r, int c)
{
    int pt = 1, sum = b[1].size();
    while (sum < r) pt++, sum += b[pt].size();

    return b[pt][r - (sum - b[pt].size()) - 1];
}

void solve()
{
    scanf("%d", &n);
    len = sqrt(n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]), pos[i] = (i - 1) / len + 1;
        b[pos[i]].push_back(a[i]);
    }

    for (int i = 1; i <= n; i++)
    {
        int opt, l, r, c;
        scanf("%d%d%d%d", &opt, &l, &r, &c);
        if (opt == 0)
            change(l, r, c);
        else
            printf("%d\n", cal(l, r, c));
    }
}

int main()
{
    freopen("Testin.txt", "r", stdin);
    //freopen("Testout.txt", "w", stdout);
    solve();
    return 0;
}

Guess you like

Origin www.cnblogs.com/danzh/p/11363110.html