比赛 |
防止浮躁的小练习v0.4 |
评测结果 |
AAAAAAAAAA |
题目名称 |
小L的斐波那契数列游戏 |
最终得分 |
100 |
用户昵称 |
Fmuckss |
运行时间 |
0.263 s |
代码语言 |
C++ |
内存使用 |
1.46 MiB |
提交时间 |
2016-10-13 18:53:41 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1e5 + 10;
const int smaxn = 400;
const int lcy = 998244353;
int n, m, sqrn;
int f[maxn];
int blk_l[smaxn], blk_r[smaxn], blk_id[maxn];
int lz_fr[smaxn], lz_se[smaxn];
int ans[maxn];
#define is_num(x) (x <= '9' and x >= '0')
inline int get_num() {
char tmp = getchar();
int res = 0;
while (not is_num(tmp)) tmp = getchar();
while ( is_num(tmp)) {
res = (res << 3) + (res << 1) + tmp - '0';
tmp = getchar();
}
return res;
}
inline void modify(int l, int r) {
int bl = blk_id[l], br = blk_id[r];
if (bl == br) {
for (int i = l; i <= r; i++) {
// ans[i] = (ans[i] + f[i - l + 1]) % lcy;
// ans[i] += f[i - l + 1]; if (ans[i] >= lcy) ans[i] -= lcy;
ans[i] = (ans[i] + f[i - l + 1] >= lcy ? ans[i] + f[i - l + 1] - lcy : ans[i] + f[i - l + 1]);
}
} else {
for (int i = l; i <= blk_r[bl]; i++) {
// ans[i] = (ans[i] + f[i - l + 1]) % lcy;
// ans[i] += f[i - l + 1]; if (ans[i] >= lcy) ans[i] -= lcy;
ans[i] = (ans[i] + f[i - l + 1] >= lcy ? ans[i] + f[i - l + 1] - lcy : ans[i] + f[i - l + 1]);
}
for (int i = blk_l[br]; i <= r; i++) {
// ans[i] = (ans[i] + f[i - l + 1]) % lcy;
// ans[i] += f[i - l + 1]; if (ans[i] >= lcy) ans[i] -= lcy;
ans[i] = (ans[i] + f[i - l + 1] >= lcy ? ans[i] + f[i - l + 1] - lcy : ans[i] + f[i - l + 1]);
}
for (int i = bl + 1; i < br; i++) {
int delta = blk_l[i];
// lz_fr[i] = (lz_fr[i] + f[delta + 1 - l]) % lcy;
// lz_fr[i] += f[delta + 1 - l]; if (lz_fr[i] >= lcy) lz_fr[i] -= lcy;
lz_fr[i] = (lz_fr[i] + f[delta + 1 - l] >= lcy ? lz_fr[i] + f[delta + 1 - l] - lcy : lz_fr[i] + f[delta + 1 - l]);
// lz_se[i] = (lz_se[i] + f[delta + 2 - l]) % lcy;
// lz_se[i] += f[delta + 2 - l]; if (lz_se[i] >= lcy) lz_fr[i] -= lcy;
lz_se[i] = (lz_se[i] + f[delta + 2 - l] >= lcy ? lz_se[i] + f[delta + 2 - l] - lcy : lz_se[i] + f[delta + 2 - l]);
}
}
}
inline int query(int tar) {
int id = blk_id[tar];
int bl = blk_l[id];
int now_add = lz_se[id], la_add = lz_fr[id];
// if (now_add == la_add and now_add == 0) return ans[tar];
if (tar == bl) return (ans[tar] + la_add) % lcy; //(ans[tar] + la_add >= lcy ? ans[tar] + la_add - lcy : ans[tar] + la_add);
if (tar == bl + 1) return (ans[tar] + now_add) % lcy; //(ans[tar] + now_add >= lcy ? ans[tar] + now_add - lcy : ans[tar] + now_add);
for (int i = bl + 2; i <= tar; i++) {
now_add += la_add;
// now_add = (now_add + la_add) % lcy;
la_add = now_add - la_add;
if (now_add >= lcy) now_add -= lcy;
// now_add %= lcy;
}
return (ans[tar] + now_add) % lcy; //(ans[tar] + now_add >= lcy ? ans[tar] + now_add - lcy : ans[tar] + now_add);
}
inline void init() {
f[1] = blk_id[1] = 1;
sqrn = sqrt(n);
int l = 0, r = 0, id = 1;
for (int i = 2; i <= n; i++) {
f[i] = (f[i - 1] + f[i - 2] >= lcy ? f[i - 1] + f[i - 2] - lcy : f[i - 1] + f[i - 2]);
// f[i] = f[i - 1] + f[i - 2]; if (f[i] >= lcy) f[i] -= lcy;
// f[i] = (f[i - 1] + f[i - 2]) % lcy;
blk_id[i] = id;
if (not (i % sqrn)) id++;
}
for (int i = 1; (i - 1) * sqrn <= n; i++) {
l = r + 1, r = l + sqrn - 1;
blk_l[i] = l, blk_r[i] = r;
}
int a = 2;
}
inline void solve() {
init();
int han, l, r;
for (int i = 1; i <= m; i++) {
han = get_num();
if (han) {
l = get_num(), r = get_num();
modify(l, r);
} else {
l = get_num();
printf("%d\n", query(l));
}
}
}
int main() {
freopen("chenyao_fib_game.in", "r", stdin);
freopen("chenyao_fib_game.out", "w", stdout);
n = get_num(), m = get_num();
solve();
return 0;
}