这种数学题谁顶得住啊。
因为 (3 ^ 48) % (mod - 1)为 1 , 所以48个一个循环节, 用线段树直接维护。
#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ull unsigned long long using namespace std; const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 95542721; const double eps = 1e-6; const double PI = acos(-1); int n, q; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 int a[N << 2][48], lazy[N << 2]; inline void pull(int rt) { for(int i = 0; i < 48; i++) { a[rt][i] = a[rt << 1][i] + a[rt << 1 | 1][i]; if(a[rt][i] >= mod) a[rt][i] -= mod; } } inline void push(int rt) { lazy[rt] %= 48; if(lazy[rt]) { lazy[rt << 1] += lazy[rt]; lazy[rt << 1 | 1] += lazy[rt]; rotate(a[rt << 1], a[rt << 1] + lazy[rt], a[rt << 1] + 48); rotate(a[rt << 1 | 1], a[rt << 1 | 1] + lazy[rt], a[rt << 1 | 1] + 48); lazy[rt] = 0; } } void build(int l, int r, int rt) { if(l == r) { scanf("%d", &a[rt][0]); a[rt][0] %= mod; for(int i = 1; i < 48; i++) a[rt][i] = 1LL * a[rt][i - 1] * a[rt][i - 1] % mod * a[rt][i - 1] % mod; return; } int mid = l + r >> 1; build(lson); build(rson); pull(rt); } void update(int L, int R, int l, int r, int rt) { if(l >= L && r <= R) { lazy[rt]++; rotate(a[rt], a[rt] + 1, a[rt] + 48); return; } push(rt); int mid = l + r >> 1; if(L <= mid) update(L, R, lson); if(R > mid) update(L, R, rson); pull(rt); } int query(int L, int R, int l, int r, int rt) { if(l >= L && r <= R) return a[rt][0]; push(rt); int mid = l + r >> 1; if(R <= mid) return query(L, R, lson); else if(L > mid) return query(L, R, rson); else return (query(L, R, lson) + query(L, R, rson)) % mod; } int main() { scanf("%d", &n); build(1, n, 1); scanf("%d", &q); while(q--) { int t, L, R; scanf("%d%d%d", &t, &L, &R); if(t == 1) { printf("%d ", query(L, R, 1, n, 1)); } else { update(L, R, 1, n, 1); } } return 0; } /* */