首页 > 代码库 > 哈尔滨理工大学第六届程序设计团队 E-Mod

哈尔滨理工大学第六届程序设计团队 E-Mod

/*成功水过,哈哈哈,可能数据水吧*/#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