bzoj2022 Fly Sheep

Source: Internet
Author: User
Tags min

I'm not LCT.
Qaqqqqqqq
DQS: "LCT a log runs slower than two log"
XCZHW: "I told you he ran slower than sqrt ..."

There are a lot of details about the problem ...
But the central idea is a sentence: "Record a point jump to the number of steps outside the block and the foothold"
NN, that's it.
Search is good to find ...
Just modify the same block in the same time.

void change (int x,int v)
{
    num[x] = V;//ki
    step[x] = 1;//jumps to block external steps
    int mx = x/m,nxt = min (n,x + v);//Next C4/>NEXT[X] = Nxt;//cnbb just let me wa for half a day
    if ((NXT)/M = = mx)
    {
        step[x] + = step[nxt];
        NEXT[X] = next[nxt];
    }
    int r = x-1;
    while ((r + 1)% M)
    {
        nxt = min (n,r + num[r]);
        if (nxt/m = = mx)
        {
            Step[r] = step[nxt] + 1;
            NEXT[R] = next[nxt];
        }
        r--;
    }
    return;
}
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <
Cmath> using namespace std;
const int MAXN = 200000 + 5;
int n,m,m;
int NUM[MAXN],NEXT[MAXN],STEP[MAXN];
    void Init () {M = sqrt (n) + 1;
        for (int i = n-1;i >= 0;i--) {int nxt = min (n,i + num[i]);
            if (nxt/m = = i/m) {Step[i] = step[nxt] + 1;
        Next[i] = next[nxt];
}} return;
    } int ask (int x) {int ans = 0;
        while (x < n) {ans + = step[x];
    x = Next[x];
} return ans;
    } void Change (int x,int v) {num[x] = V;
    STEP[X] = 1;
    int r = X-1,MX = x/m;
    int nxt = min (n,x + v);
    NEXT[X] = NXT;
        if (NXT)/M = = mx) {step[x] + = STEP[NXT];
    NEXT[X] = next[nxt];
        } while ((R + 1)% M) {nxt = min (n,r + num[r]);
            if (nxt/m = = mx) {Step[r] = step[nxt] + 1; Next[r] = Next[NXT];
    } r--;
} return;
} int q,x,v;
    int main () {scanf ("%d", &n);
        for (int i = 0;i < N;i + +) {scanf ("%d", &num[i]);
        Next[i] = min (n,i + num[i]);
    Step[i] = 1;
    } Step[n] = 0;
    Next[n] = n + 1;
    Init ();
    scanf ("%d", &m);
        for (int i = 1;i <= m;i + +) {scanf ("%d", &q);
            Switch (q) {case 1:scanf ("%d", &x);p rintf ("%d\n", ask (x));
        Case 2:scanf ("%d%d", &x,&v); change (X,V);
}} 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.