int@n,@b,@q,a[n+1]{}; rep(q){ int@(l,m,r); ll@c; int@d; c=(c+l)%b; rep(i,l,r+1){ a[i]=(a[i]+powmod(c++,d,b))%b; } wt(a[m]); }