LOJ6281 block entry columns 5

LOJ6281 number of columns of the block entry 5

label

  • Block entry

Foreword

  • no

Concise meaning of the questions

  • Maintenance sequence, need to support both operations
    1. Interval square root
    2. Plus range

Thinking

  • The students learned tree line certainly have done to achieve the interval square root of the problem with the tree line. Looks like the topic is what's Flora
  • In fact, almost block to do with the tree line. 2e31 noted that the number of open five times the square root becomes 1, so we directly open an array tag [] the record about how much each piece of root number is not open. Then modify the operation, the block is not directly open to the root, at the recording in a piece of tag ++. Then query operation, not monolithic directly add, block and see if tag> = 5, if it is, then the piece is 1, ans plus direct len. Otherwise, this one one handle just fine.

Precautions

  • First, we must pay attention to detail. When dealing with non-block, with remember tag [pos [i]], and the processing block, I took table block, with the tag [i].
  • Another is, the square root is 0 0, where special judge to look at. In short it comes to square root thought about 0 to special sentence.

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, tag[maxn], is_zero[maxn], num[maxn];

void change(int l, int r, int c)
{
    for (int i = l; i <= min(len * pos[l], r); i++)
        a[i] = sqrt(a[i]);

    if (pos[l] != pos[r])
        for (int i = r; i >= len * pos[r] - len + 1; i--)
            a[i] = sqrt(a[i]);

    for (int i = pos[l] + 1; i <= pos[r] - 1; i++)
        tag[i]++;
}

int cal(int l, int r, int c)
{
    int ans = 0;
    for (int i = l; i <= min(len * pos[l], r); i++)
    {
        if (a[i] == 0)
            continue;
        if (tag[pos[i]] >= 5)
            ans += 1;
        else
        {
            int t = a[i];
            for (int j = 1; j <= tag[pos[i]]; j++)
                t = sqrt(t);
            ans += t;
        }
    }
    
    if (pos[l] != pos[r])
        for (int i = r; i >= len * pos[r] - len + 1; i--)
        {
            if (a[i] == 0)
                continue;
            if (tag[pos[i]] >= 5)
                ans += 1;
            else
            {
                int t = a[i];
                for (int j = 1; j <= tag[pos[i]]; j++)
                    t = sqrt(t);
                ans += t;
            }
        }

    for (int i = pos[l] + 1; i <= pos[r] - 1; i++)
    {
        if (tag[i] >= 5)
            ans += len - num[i];
        else
        {
            for (int j = i * len - len + 1; j <= i * len; j++)
            {
                int t = a[j];
                for (int k = 1; k <= tag[i]; k++)//开方k次
                    t = sqrt(t);
                ans += t;
            }
        }
    }

    return ans;
}

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;
        if (a[i] == 0)
            is_zero[i] = 1, num[pos[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/11361119.html