hdu 5475 线段树

来源:互联网 发布:苹果电脑设计软件免费 编辑:程序博客网 时间:2024/06/04 23:26
#include<iostream>#include<cstdio>#include<cstdlib>#include<vector>#include<cmath>#include<string>#include<algorithm>#include<set>#include<map>#include<cstring>#include<queue>#include<stack>//#include<>using namespace std;typedef long long ll;const int MAXN=100000;struct node{    ll ji;    int l,r;}tree[MAXN*4];int Q,M;void Build(int pos,int l,int r){ /*   for(int i=0;i<MAXN*4;i++)    {        tree[i].ji=1;    }    */    tree[pos].l=l;    tree[pos].r=r;    tree[pos].ji=1;    int mid=(l+r)/2;    if(l==r)    {        return ;    }    Build(pos*2,l,mid);    Build(pos*2+1,mid+1,r);}void update(int pos,int k,ll p){    int L=tree[pos].l;    int R=tree[pos].r;    int mid=(L+R)/2;    if(L==R)    {        tree[pos].ji=p;        return;    }    else if(k<=mid)    {        update(pos*2,k,p);    }    else if(k>=mid+1)    {        update(pos*2+1,k,p);    }    tree[pos].ji=((tree[pos*2].ji%M)*(tree[pos*2+1].ji%M))%M;}int main(){    int T,t=1;    scanf("%d",&T);    while(T--)    {        printf("Case #%d:\n",t++);        scanf("%d%d",&Q,&M);        Build(1,1,Q);        int n=1;        for(int i=0;i<Q;i++)        {            int x;            scanf("%d",&x);            if(x==1)            {                ll y;                scanf("%I64d",&y);                update(1,n,y);                printf("%I64d\n",tree[1].ji);            }            else            {                int p;                scanf("%d",&p);                update(1,p,1);                printf("%I64d\n",tree[1].ji);            }            n++;        }    }return 0;}

0 0