LOJ6283 block entry columns 7

LOJ6283 number of columns of the block entry 7

label

  • Block entry

Foreword

Concise meaning of the questions

  • Maintenance sequence, need the support of three operations:
    1. Plus range
    2. Interval ride
    3. Single check point

Thinking

  • Students learned segment tree should be done on this topic in Los Valley, the difficulty lies in how to deal with a variety of markers. How an article in the online segment classification tree I talked to handle multiple markers.
  • Here and block segment tree is the same, a set tag_plus [] and tag_mult [] two markers. How to update the mark? In fact, we should define the rules mark the first step of the operation, that is, if there are two markers at the same time, you should first calculate which one do? Defined the rules, then it is easy to be updated marked.

Precautions

  • Or pay attention to the last piece is incomplete. Especially if the reconstructed block, special sentence about the last piece.

to sum up

  • Reconstructed block write operation may be separately ~

AC Code

#pragma GCC optimize(2)
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 1e5 + 10;
const int mod = 10007;

int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

int n, a[maxn];
int pos[maxn], len, tag_plus[maxn], tag_mult[maxn];

void reset(int id)
{
    for (int i = id * len - len + 1; i <= min(id * len, n); i++)
        a[i] = (a[i] * tag_mult[id] + tag_plus[id]) % mod;
    tag_mult[id] = 1, tag_plus[id] = 0;
}

void change_plus(int l, int r, int c) 
{
    reset(pos[l]);
    if (pos[l] != pos[r]) reset(pos[r]);

    for (int i = l; i <= min(pos[l] * len, r); i++)
        a[i] = (a[i] + c) % mod;
    if (pos[l] != pos[r])
        for (int i = pos[r] * len - len + 1; i <= r; i++)
            a[i] = (a[i] + c) % mod;
    for (int i = pos[l] + 1; i <= pos[r] - 1; i++) tag_plus[i] = (tag_plus[i] + c) % mod;
}

void change_mult(int l, int r, int c) 
{
    reset(pos[l]);
    if (pos[l] != pos[r]) reset(pos[r]);

    for (int i = l; i <= min(pos[l] * len, r); i++) 
        a[i] = a[i] * c % mod;
        
    if (pos[l] != pos[r])
        for (int i = pos[r] * len - len + 1; i <= r; i++) 
            a[i] = a[i] * c % mod;

    for (int i = pos[l] + 1; i <= pos[r] - 1; i++) {
        tag_plus[i] *= c;
        tag_mult[i] *= c;
        tag_plus[i] %= mod, tag_mult[i] %= mod;
    }
}

int ask(int l, int r, int c) {
    return (a[r] * tag_mult[pos[r]] + tag_plus[pos[r]]) % mod;
}

void solve() {
    fill(tag_mult + 1, tag_mult + 1 + maxn - 10, 1);
    scanf("%d", &n);
    len = sqrt(n);
    for (int i = 1; i <= n; i++)
    a[i] = read(), pos[i] = (i - 1) / len + 1;

    for (int i = 1; i <= n; i++) {
        int opt, l, r, c;
        opt = read(), l = read(), r = read(), c = read();
        if (opt == 0)
            change_plus(l, r, c);
        else if (opt == 1)
            change_mult(l, r, c);
        else
            printf("%d\n", (a[r] * tag_mult[pos[r]] + tag_plus[pos[r]]) % mod);
    }
}

int main() {
    freopen("Testin.txt", "r", stdin);
    freopen("Testout.txt", "w", stdout);
    solve();
    return 0;
}

Guess you like

Origin www.cnblogs.com/danzh/p/11364087.html