LOJ block entry columns 6
topic:
answer:
- I do not understand this question ... Why block ...
- Direct vector like ...
- But if there is, then it would not modify the interval. So this question is the revelation we can dynamically block . Concrete is to find every time you insert the block location, and then insert the violence, the other elements in the block directly to a backward movement. If too many elements for a block is inserted, it needs to reconstruct (re-block), so that the block has a higher performance.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#define N 2000005
using namespace std;
vector<int> a;
struct Blo {int l, r;} blo[N];
int n, num, size;
int bel[N];
int read() {
int x = 0, f = 1; char c = getchar();
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;
}
void build(int len) {
size = (int)sqrt(len), num = len / size;
if (len % size) num++;
for (int i = 1; i <= len; i++) bel[i] = (i - 1) / size + 1;
for (int i = 1; i <= num; i++) {
blo[i].l = (i - 1) * size;
blo[i].r = i * size;
}
blo[num].r = len;
}
void update(int pos, int val) {
blo[bel[pos]].r++;
for (int i = bel[pos] + 1; i <= num; i++) {
blo[i].l++;
blo[i].r++;
}
a.insert(a.begin() + pos, val);
}
int ask(int pos) {
return a[pos];
}
int main() {
cin >> n;
a.push_back(-1);
for (int i = 1; i <= n; i++) a.push_back(read());
build(n);
for (int i = 1; i <= n; i++) {
int op = read(), l = read(), r = read(), c = read();
if(!op) update(l, r);
else printf("%d\n", ask(r));
}
return 0;
}