T1, hopscotch
\ (Sol \) :
can be considered a single point contribution to the answers after two different operations, just push a push will be able to forget.
Or you can put the ranks of the operating counted separately, not difficult to find the line and is the arithmetic series (columns, too), only first performed (hang) (xing) line operation, maintenance, and each column of the first term and tolerance to ;
time complexity \ (O (m) \) .
code show as below:
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include <cstdio>
#include <cstring>
#include <algorithm>
int in() {
int x = 0; char c = getchar(); bool f = 0;
while (c < '0' || c > '9')
f |= c == '-', c = getchar();
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? -x : x;
}
template<typename T>inline void chk1(T &_, T __) { _ = _ < __ ? _ : __; }
template<typename T>inline void chk2(T &_, T __) { _ = _ > __ ? _ : __; }
const int N = 1e6 + 5, Q = 1e5 + 5, mod = 1e9 + 7;
int n, m, q;
struct info {
int typ;
int x, k;
} a[Q];
int x[N], y[N];
inline void add(int &_, int __) {
_ += __;
if (_ >= mod) _ -= mod;
if (_ < 0) _ += mod;
}
int main() {
//freopen("in", "r", stdin);
freopen("game.in", "r", stdin);
freopen("game.out", "w", stdout);
n = in(), m = in(), q = in();
for (int i = 1; i <= q; ++i) {
char c = getchar();
while (c != 'R' && c != 'S')
c = getchar();
a[i] = (info){c == 'R', in(), in()};
}
int d = n;
for (int i = 1; i <= n; ++i)
x[i] = 1;
if (n & 1)
y[1] = 1ll * (1ll * (n - 1) / 2 * m + 1) % mod * n % mod;
else
y[1] = 1ll * (1ll * (n - 1) * m + 2) % mod * (n / 2) % mod;
for (int i = 1; i <= q; ++i)
if (a[i].typ) {
add(y[1], 1ll * (1 + 1ll * (a[i].x - 1) * m % mod) * x[a[i].x] % mod * (a[i].k - 1) % mod);
add(d, 1ll * (a[i].k - 1) * x[a[i].x] % mod);
x[a[i].x] = 1ll * x[a[i].x] * a[i].k % mod;
}
for (int i = 2; i <= m; ++i)
y[i] = y[i - 1], add(y[i], d);
for (int i = 1; i <= q; ++i)
if (!a[i].typ)
y[a[i].x] = 1ll * y[a[i].x] * a[i].k % mod;
for (int i = 1; i <= m; ++i)
add(y[0], y[i]);
printf("%d\n", y[0]);
return 0;
}
T2, hopscotch
\ (Sol \) :
Consider optimization cycle of violence to find a section to record each point will reach the first \ (m \) which position column, find the first column will change during the interval can be modified;
time complexity \ (O ((n-m +) \ Q) \) .
Code(Cushions)
T3, a beautiful sequence
First muttered,