1. 程式人生 > >TJOI 2018 數學計算

TJOI 2018 數學計算

tchar style ati show stat href char 數學計算 targe

題鏈

對時間建線段樹,當然,你要寫中國剩余定理我也是很資瓷。

#include<bits/stdc++.h>
#define LL long long
#define N 300007
#define sight(x) (‘0‘<=x&&x<=‘9‘)
#define Mid (l+r>>1)
#define Ls No<<1,l,Mid
#define Rs No<<1|1,Mid+1,r
using namespace std;
LL p[N];
int mo,T,x,op,q;
inline void
read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } void write(LL x){if (x<10) {putchar(0+x); return;} write(x/10); putchar(0+x%10);} inline void writeln(LL x){ if (x<0) putchar(-),x*=-1; write(x); putchar(\n); } inline
void writel(LL x){ if (x<0) putchar(-),x*=-1; write(x); putchar( ); } void change(int No,int l,int r,int id,int xx){ if (l==r) { assert(id==l); p[No]=xx; return; } if (id<=Mid) change(Ls,id,xx); else change(Rs,id,xx); p[No]=p[No<<1]*p[No<<1
|1]%mo; } void build(int No,int l,int r) { if (l==r) { p[No]=1; return; } build(Ls); build(Rs); p[No]=p[No<<1]*p[No<<1|1]%mo; } signed main () { // freopen("b.in","r",stdin); read(T); while (T--) { read(q); read(mo); build(1,1,q); for (int i=1;i<=q;i++) { read(op); read(x); if (op==1) change(1,1,q,i,x); else change(1,1,q,x,1); writeln(p[1]); } } return 0; }

TJOI 2018 數學計算