Codeforces 13E. Holes Sub-block processing

Source: Internet
Author: User

The positive solution is a dynamic tree, which is too difficult to deal with water just by blocking it. Look at the status is probably a lot slower than the.
The block algorithm is basically looking for a tradeoff point, so that the time complexity of query and change is not too high, all O (sqrt (n)), so the total time complexity is O (m*sqrt (n)).
The general idea of chunking is to divide the entire interval into sqrt (n), and each change affects the sqrt (n) points within the segment. Each time the query traverses the sqrt (n) segment, it then does something.
For this problem, first explain the meaning of several arrays:
Cnt[i] means the number of steps required to jump out of the segment from point I.
The meaning of Goal[i] is the last point that has been experienced since I started.
The meaning of jmp[i] is to jump out of the first point of arrival from the point I started.
Clear the meaning of the code after reading the good, the text is too weak.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #include <ctime > #include <iomanip> #pragma comment (linker, "/stack:1024000000"); #define EPS (1e-6) #define LL Long Long#define ULL unsigned long long#define _ll __int64#define INF 0x3f3f3f3f#define Mod 1000000007using namespace Std;const int maxn =    100010,block = sqrt (100010); int jmp[maxn],cnt[maxn],goal[maxn],val[maxn];void updata (int x,int y,int N) {if (Y > N)        {Jmp[x] = MAXN;        CNT[X] = 1;    GOAL[X] = x;        } else if (X/block*block = = Y/block*block) {Jmp[x] = Jmp[y];        CNT[X] = cnt[y]+1;    GOAL[X] = Goal[y];        } else {jmp[x] = y;        CNT[X] = 1;    Goal[x] = y;    }}void Cal (int x) {int ans = 0,f;        while (x! = MAXN) {f = goal[x];        Ans + = cnt[x];    x = Jmp[x]; } printf ("%d%d\n", F,ans);}    int main () {int i,j,u,v,n,m,ord,l;    scanf ("%d%d", &n,&m);    for (i = 1;i <= n; ++i) scanf ("%d", &val[i]);    for (i = N;i >= 1; i.) Updata (I,I+VAL[I],N);        while (m--) {scanf ("%d", &ord);            if (ORD) {scanf ("%d", &u);        Cal (U);            } else {scanf ("%d%d", &u,&v);            Val[u] = v;            L = U/block*block;        for (i = U;i >= L; i.) Updata (I,I+VAL[I],N); }} return 0;}


Codeforces 13E. Holes Sub-block processing

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.