标签:des style blog http color java os strong
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
#include <cstdio> #include <cstring> int n,q,a[100005],x[100005],p,l[100005],r[100005],t[100005]; int tree[1000005]; void build(int l, int r, int rt) { tree[rt]=-1; if(l==r){ tree[rt]=0; return; } int m=(l+r)/2; build(l,m,rt*2); build(m+1,r,rt*2+1); } void update(int x, int y, int z, int l, int r, int rt) { if(x<=l&&y>=r){ tree[rt]=z; return; } if(tree[rt]!=-1) { tree[rt*2]=tree[rt]; tree[rt*2+1]=tree[rt]; tree[rt]=-1; } int m=(l+r)/2; if(x<=m) update(x,y,z,l,m,rt*2); if(y>m) update(x,y,z,m+1,r,rt*2+1); } int query(int k, int l, int r, int rt) { if(tree[rt]!=-1) return tree[rt]; int m=(l+r)/2; if(k<=m) return(query(k,l,m,rt*2)); else return(query(k,m+1,r,rt*2+1)); } int main() { int cas; scanf("%d",&cas); while(cas--){ memset(tree,-1,sizeof(tree)); scanf("%d",&n); build(1,n,1); for(int i=1; i<=n; i++) scanf("%d",&a[i]); scanf("%d",&q); for(int i=1; i<=q; i++) { scanf("%d%d%d%d",&t[i],&l[i],&r[i],&x[i]); if(t[i]==1) update(l[i],r[i],i,1,n,1); } for(int i=1; i<=n; i++){ p=query(i,1,n,1); if(p) a[i]=x[p]; for(int j=p+1; j<=q; j++) if(t[j]==2&&l[j]<=i&&r[j]>=i){ if(a[i]>x[j]){ int aa=a[i],bb=x[j],t=aa%bb; while(t!=0){ aa=bb; bb=t; t=aa%bb; } a[i]=bb; } } } for(int i=1; i<=n; i++) printf("%d ",a[i]); printf("\n"); } }
总体上来说,这类题目实现时细节很重要,需要悉心考量,切忌急躁。
标签:des style blog http color java os strong
原文地址:http://www.cnblogs.com/Mathics/p/3883790.html