Cattle-off practice match 48 C w small candy (mathematics, polynomial, differential)

Cattle-off practice match 48 C w small candy (mathematics, polynomials)

Links: https://ac.nowcoder.com/acm/contest/923/C Source: Cattle-off network

Title Description

Small w and his two teammates teito, tokitsukaze prepare some material benefits for everyone, in the end made something of it? After thinking for a long time the three of them to prepare a lot of sweets. They let the n kids lined up in a long row from left to right and numbered 1,2,3,4,5,6,7,8,9 ..... n.

Every three candy hair, are beginning from a certain position, only the owner of the candy sent this man and this man on the right. But they made candy rules are different.

1, if a wheel made of candy is tokitsukaze, she will start from a position pos, turn right for everyone a candy.

2, if a wheel made of candy is teito, he will start from a position pos, turn to the right, he will give the first person he encountered send a candy, a second person he met hair 2 candy, to a third person he encountered made up of three candy ... personal k k candy hair, walked up to the right number of people for the n met.

3. If a wheel is made of candy winterzz1, well known small w is generous, so he made the most of sugar, he will start from a position pos, turn to the right, it will give his first encounter candy a human hair, to the second person he encountered candy hair 4, to a third person he encountered hair 9 ... k-th individual candy encountered hair k2k ^ {2} k2 until candy He walked right up to n number of people.

Made of sugar Welfare conducted a total of m round, and now tell you that the starting position pos m wheel made of sugar people and they made the round of sugar, please tell me the end of this round of m to n 1 made of sugar candy in the hands of everyone number number, this number in order to avoid too large, you only use the output of each of the hands of the individual sugars mod 109 + 7mod; results after 10 ^ {9} + 7mod109 + 7 can.

Enter a description:

The first line is a positive integer T (1⩽T⩽10) (1 \ leqslant T \ leqslant10) (1⩽T⩽10), expressed T set of test cases. For each case: the first line two positive integers n, m (1⩽n, m⩽105) (1 \ leqslant n, m \ leqslant10 ^ {5}) (1⩽n, m⩽105) now represents a row of n m individual rounds were made and candy. Next m lines of two positive integers type (1⩽type⩽3) (1 \ leqslant type \ leqslant 3) (1⩽type⩽3), pos (1⩽pos⩽n) (1 \ leqslant pos \ leqslant n) (1⩽pos⩽n) denote the wheel confetti person, and the position of the person begin candy. type = candy when artificial hair tokitsukaze 1, type = 2 when human teito confetti, type = 3 when human winterzz1 confetti. pos indicates the position, and most people left pos 1, pos rightmost man is n.

Output Description:

对于每组测试案例,输出一行n个非负整数,表示每个人手中的糖果数量mod  109+7mod\; 10^{9}+7mod109+7后的结果。数字与数字之间用空格隔开并且行末不允许有多余空格。

Example 1

Entry

copy

4
10 1
1 1
10 1
2 2
10 1
3 3
10 3
1 1
2 2
3 3

Export

copy

1 1 1 1 1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9
0 0 1 4 9 16 25 36 49 64
1 2 4 8 14 22 32 44 58 74

Remarks:

由于输入量和输出量比较大,请勿使用cin,cout进行输入输出。本题不会卡常数,不用特地使用输入输出挂。

Ideas:

 1.type = tokitsukaze artificial hair candy 1, if the onward pos made of sugar, the sugar has +1 behind all, regardless of the location of each person.
 
 2.type = 2 teito human hair when candy, if made of sugar from the start pos, the first X ( \ (X> = pos \) ) who obtained positions \ (x-pos + 1 \ ) sugar.
 
 3.type = 3 candy made artificially winterzz1, if from the start pos made of sugar, then the first x (x> = pos) individuals to obtain \ ((x-pos + 1 ) ^ 2 \) saccharide, and \ (( x-pos + 1) ^ 2
 
= x ^ 2 + 2 * (1-pos) x + pos * 2-2 * pos + 1 \) can be found, the x-th individual candy may be represented by a polynomial:
\ (f (x) = A_ { i} x ^ {2} + B_ {i} x + C_ {i} \)

It also can be found, each made of sugar, only the modified polynomial coefficients \ (Ai, Bi, Ci \ )

That is:
 when type = 1: from position pos all \ (C {x} \) plus all 1
 
 when type = 2: from position pos all \ (C {x} \) plus all \ (( 1-pos) \) , all \ (B {x} \) plus all 1
 
 when type = 3 when: from all the position pos \ (C {i} \) plus all \ ((pos ^ {2} -2 * pos + 1) \) all \ (B {i} \) plus all \ ((2-2 * POS) \) , all \ (a {i} \) plus 1

So long as we maintain a coefficient of difference scores can be listed.

Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}

inline void getInt(int* p);
const int maxn = 100010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
const ll mod = 1e9 + 7;
struct node
{
    ll a, b, c;
    void update()
    {
        if (a < 0)
            a += mod;
        if (b < 0)
            b += mod;
        if (c < 0)
            c += mod;
        if (a >= mod)
        {
            a %= mod;
        }
        if (b >= mod)
        {
            b %= mod;
        }
        if (c >= mod)
        {
            c %= mod;
        }
    }
} info[maxn];
int t;
int n, m;
int op;
int pos;
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    du1(t);
    while (t--)
    {
        du2(n, m);
        repd(i, 1, m)
        {
            du2(op, pos);
            if (op == 1)
            {
                info[pos].c++;
            } else if (op == 2)
            {
                info[pos].b++;
            } else
            {
                info[pos].a++;
            }
        }
        ll ans;
        repd(i, 1, n)
        {
            info[i - 1].a += info[i].a;
            info[i - 1].b -= 2ll * (i - 1) % mod * info[i].a % mod;
            info[i - 1].c += info[i].a * (i - 1) % mod * (i - 1) % mod;
            info[i - 1].b += info[i].b;
            info[i - 1].c -= info[i].b * (i - 1) % mod;
            info[i - 1].c += info[i].c ;
            info[i - 1].update();
            info[i] = info[i - 1];

            ans = ( (1ll * info[i].a * i % mod * i % mod + 1ll * info[i].b * i % mod) % mod + 1ll * info[i].c) % mod;
            if (ans >= mod)
            {
                ans %= mod;
            }
            printf("%lld%c",  ans, i == n ? '\n' : ' ');
        }
        repd(i, 0, n)
        {
            info[i].a = info[i].b = info[i].c = 0;
        }
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Guess you like

Origin www.cnblogs.com/qieqiemin/p/11828249.html