• bzoj5334: [Tjoi2018]数学计算


    这是个悲伤的故事捂脸

    噶爷爷安利了到水题,自然而然的被D飞

    队长看了一眼说他不会

    然而我写T了的时候他过来又看了下说粗略看没啥问题

    OZY一眼就说我会nlogn的

    结果题意看了20分钟没看懂。。。高兴的吼了起来
    tkj:人家都秒了你才看懂题意

    哈哈。然而我看懂题意也一眼秒啦。就是线段树把全部记录下来乱搞啊。

    结果TLE了。噶爷爷没看出来,就怼怼我线段树模板都错学什么OI啊

    l打成1真是没话说。。ORZ zory

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LL;
    LL mod;
    
    struct seg_tree
    {
        int l,r,lc,rc;LL c;
    }tr[210000];int trlen;
    void bt(int l,int r)
    {
        int now=++trlen;
        tr[now].l=l;tr[now].r=r;tr[now].c=1;
        tr[now].lc=tr[now].rc=-1;
        if(l<r)
        {
            int mid=(l+r)/2;
            tr[now].lc=trlen+1;bt(l,mid);
            tr[now].rc=trlen+1;bt(mid+1,r);
        }
    }
    void change(int now,int p,LL c)
    {
        if(tr[now].l==tr[now].r){tr[now].c=c;return ;}
        int lc=tr[now].lc,rc=tr[now].rc;
        int mid=(tr[now].l+tr[now].r)/2;
        if(p<=mid)change(lc,p,c);
        else change(rc,p,c);
        tr[now].c=(tr[lc].c*tr[rc].c)%mod;
    }
    LL getmul(int now,int l,int r) 
    {
        if(tr[now].l==l&&tr[now].r==r){return tr[now].c;}
        int lc=tr[now].lc,rc=tr[now].rc;
        int mid=(tr[now].l+tr[now].r)/2;
             if(r<=mid)  return getmul(lc,l,r);
        else if(mid+1<=l)return getmul(rc,l,r);
        else return (getmul(lc,l,mid)*getmul(rc,mid+1,r))%mod;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int Q;
            scanf("%d%lld",&Q,&mod);
            trlen=0;bt(1,Q);
            int op;LL x;
            for(int i=1;i<=Q;i++)
            {
                scanf("%d%lld",&op,&x);
                if(op==1)change(1,i,x),printf("%lld
    ",getmul(1,1,Q));
                else change(1,x,1),printf("%lld
    ",getmul(1,1,Q));
            }
        }
        return 0;
    }
  • 相关阅读:
    cout 格式化输出
    CreateEvent的用法
    深入理解CRITICAL_SECTION
    const型类成员
    用 const 限定类的成员函数
    C++文件读写详解(ofstream,ifstream,fstream)
    C++中回调函数(CallBack)的使用
    SetTimer函数的用法
    CString转换成int CString类相应函数
    自己设计并制作了一个自己主动温度控制系统
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/9082316.html
Copyright © 2020-2023  润新知