Bzoj 3038 God-created seven-minute 2 tree-shaped array + and check set

Source: Internet
Author: User
Tags square root

The main idea: a sequence, there are two operations, 1. Open the square root of each number in a number. 2. Query for a number of the and.


Ideas: And 3211 is a question, interested can look at my blog post.


CODE:

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < Algorithm> #define MAX 100010using namespace Std;int cnt,asks;long long Src[max];long long Fenwick[max];int Father[max ];void pretreatment (), inline void Fix (int x,long long c), inline long long getsum (int x), int Find (int x), int main () {CIN ;> CNT; Pretreatment (); for (int i = 1;i <= cnt; ++i) {scanf ("%lld", &src[i]); Fix (I,src[i]); if (src[i] = = 1) father[i] = i + 1;} CIN >> asks;for (int flag,x,y,i = 1;i <= asks; ++i) {scanf ("%d%d%d", &flag,&x,&y), if (x > Y) Swap (y if (!flag) for (x = Find (x), x <= y;x = find (x + 1)) {Fix (x,-src[x]); Fix (X,src[x] = sqrt (src[x)), if (src[x] = = 1) father[x] = Find (x + 1);} elseprintf ("%lld\n", Getsum (Y)-getsum (X-1));} return 0;} void Pretreatment () {for (int i = 1;i <= cnt + 1; ++i) father[i] = i;} inline void Fix (int x,long long C) {for (int i = x;i <= cnt;i + = i&-i) Fenwick[i] + = C;} Inline long long getsum (int x) {Long lonG re = 0;for (int i = X;i;i = i&-i) re + + Fenwick[i];return re;} int Find (int x) {if (father[x] = = x) return X;return father[x] = find (Father[x]);}


Bzoj 3038 God-created seven-minute 2 tree-shaped array + and check set

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.