zoukankan      html  css  js  c++  java
  • TJOI 2018 数学计算

    题链

     对时间建线段树,当然,你要写中国剩余定理我也是很资瓷。

    #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('
    '); }
    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;
    }
  • 相关阅读:
    Pycharm快捷键【mac版】
    程序解数独
    c++ map
    c++ vector 初始化二维数组
    二进制求和
    数组形式的加一
    坑题:最后一个单词的长度
    最大子序和:dp
    外观数列
    双指针消重复项
  • 原文地址:https://www.cnblogs.com/rrsb/p/9058094.html
Copyright © 2011-2022 走看看