码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-12-10 22:46:35      阅读:193      评论:0      收藏:0      [点我收藏+]

标签: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,r
using 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

标签:stdio.h   use   txt   stdin   space   pac   std   using   long   

原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/6158350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!