标签:
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1553 Accepted Submission(s): 697
#include <cstdio> #include <algorithm> using namespace std; const int MAXN=100005; typedef long long ll; struct Node{ ll val; int l,r; }a[MAXN*3]; int n,mod; void build(int rt,int l,int r) { a[rt].l=l; a[rt].r=r; a[rt].val=1; if(l==r) { return ; } int mid=(l+r)>>1; build(rt<<1,l,mid); build((rt<<1)|1,mid+1,r); } void update(int rt,int pos,int val) { if(a[rt].l==pos&&a[rt].r==pos) { a[rt].val=val%mod; return ; } int mid=(a[rt].l+a[rt].r)>>1; if(pos<=mid) { update(rt<<1,pos,val); } else { update((rt<<1)|1,pos,val); } a[rt].val=(a[rt<<1].val*a[(rt<<1)|1].val)%mod; } int main() { int T; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { scanf("%d%d",&n,&mod); build(1,1,n); printf("Case #%d:\n",cas); for(int i=1;i<=n;i++) { int type,val; scanf("%d%d",&type,&val); if(type==1) { update(1,i,val); } else { update(1,val,1); } printf("%lld\n",a[1].val); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5721673.html