哈爾濱理工大學第六屆程式設計團隊 E-Mod

來源:互聯網
上載者:User

標籤:stdio.h   use   txt   stdin   space   pac   std   using   long   

/*成功水過,哈哈哈,可能資料水吧*/#include <stdio.h>#include <algorithm>#include <string.h>#include <queue>#include <set>#define t_mid (l+r >> 1)#define ls (o<<1)#define rs (o<<1 | 1)#define lson ls,l,t_mid#define rson rs,t_mid+1,rusing namespace std;typedef long long ll;const int N = 100000 + 5;int a[N],c[N<<2],n;void build(int o,int l,int r){    if(l==r) {c[o] = a[l];return;}    build(lson);    build(rson);    c[o] = min(c[ls],c[rs]);}int query(int ql,int qr,int o,int l,int r,int x){    if(l==r)    {        if(c[o] <= x) return l;//找到比他小的了        else return -1;    }    int ans = -1;    if(t_mid >= ql && c[ls] <= x)    {        ans = query(ql,qr,lson,x);        if(ans == -1)        {            if(t_mid < qr && c[rs] <= x) ans = query(ql,qr,rson,x);        }        return ans;    }    else if(t_mid < qr && c[rs] <= x) return query(ql,qr,rson,x);    return -1;}int main(){    //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);    int T;scanf("%d",&T);    while(T--)    {        scanf("%d",&n);        for(int i=1;i<=n;i++)            scanf("%d",a+i);        build(1,1,n);        int q;        scanf("%d",&q);        while(q--)        {            int op;            scanf("%d",&op);            int now =op;            int l=1;            while(l <=n)            {                l=query(l,n,1,1,n,now);                if(l == -1) break;                now %= a[l];            }            printf("%d\n",now);        }    }}

 

哈爾濱理工大學第六屆程式設計團隊 E-Mod

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.