標籤: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