JZOJ6277 [] [] A group NOIP improve matrix game

Subject to the effect

Gives a \ (n * m \) matrix, where \ (A_ {I, J} = (. 1-I) + J * m \) , there are \ (K \) operations, each time a row or a ride with a number \ (the y-\) , final demand and the number of each matrix.
\ (n, m \ leq 10 ^ 6, k \ leq 10 ^ 5 \)

analysis

SoftBrands be a problem?

Can be found in the sequence of operations does not affect the result, it is possible to consider operations do first row, column operations do.

After the finish line operating on the good demand of each column and then the column then finish the operation.

Ask each column sum is: first find the sum of the first column, and then push a push next column more than the sum of the number, you can find a.

Time complexity \ (O (n-m + K +) \) .

Code

#include <cstdio>
#include <cstring>
#define F(i, l, r) for (int i = l; i <= r; ++i)

typedef long long ll;
const int N = 1000007;
const ll P = 1e9 + 7;

int n, m, k, x[N], y[N];
short opt[N];
ll ans, s, s1, fir, las, sum[N], mtp[N], p[N];
char c;

int main()
{
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);
    scanf("%d%d%d", &n, &m, &k);
    F(i, 1, k)
    {
        scanf(" %c%d%d", &c, &x[i], &y[i]);
        opt[i] = (c == 'R' ? 1 : 0);
    }
    F(i, 1, n) mtp[i] = 1;
    F(i, 1, k) if (opt[i]) mtp[x[i]] = mtp[x[i]] * y[i] % P;
    F(i, 1, n) s = (s + (mtp[i] - 1 + P) % P * (1ll * (i - 1) * m % P + 1) % P) % P, s1 = (s1 + (mtp[i] - 1 + P) % P) % P;
    F(i, 1, m)
    {
        fir = i, las = (i + 1ll * (n - 1) * m % P) % P;
        sum[i] = 1ll * (fir + las) * n % P * 500000004ll % P;
        sum[i] = (sum[i] + s) % P, s = (s + s1) % P;
        p[i] = 1;
    }
    F(i, 1, k) if (!opt[i]) p[x[i]] = p[x[i]] * y[i] % P;
    F(i, 1, m) ans = (ans + p[i] * sum[i] % P) % P;
    printf("%lld\n", ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/zjlcnblogs/p/11305778.html