# bzoj3211花神游历各国&&bzoj3038上帝造题的七分钟2*

bzoj3211花神游历各国

n个数的序列，m个操作，操作两种：区间开根（向下取整）和区间求和。n≤100000，m≤200000，序列中的数非负且≤109

 1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <cmath>
5 #define inc(i,j,k) for(int i=j;i<=k;i++)
6 #define maxn 100500
7 #define ll long long
8 #define lb(x) x&-x
9 using namespace std;
10
12     char ch=getchar(); int f=1,x=0;
13     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
14     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
15     return f*x;
16 }
17 int n,m,fa[maxn]; ll c[maxn],v[maxn];
18 void update(int x,ll val){while(x<=n)c[x]+=val,x+=lb(x);}
19 ll query(int x){ll q=0; while(x>0)q+=c[x],x-=lb(x); return q;}
20 int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
21 int main(){
23     fa[n+1]=n+1; inc(i,1,n)if(v[i]<=1)fa[i]=find(i+1);
24     inc(i,1,m){
26         if(x==1)printf("%lld\n",query(r)-query(l-1));
27         if(x==2){
28             int j=l;
29             while(j<=r){
30                 j=find(j); if(j>r)break; ll y=v[j]; v[j]=(ll)sqrt(y);
31                 update(j,v[j]-y); if(v[j]<=1)fa[j]=find(j+1); j++;
32             }
33         }
34     }
35     return 0;
36 }

20160613

------------------------------------------------------------------------------------------------------------------------------------------

bzoj3038上帝造题的七分钟2

 1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <cmath>
5 #define inc(i,j,k) for(int i=j;i<=k;i++)
6 #define maxn 100500
7 #define ll long long
8 #define lb(x) x&-x
9 using namespace std;
10
12     char ch=getchar(); ll f=1,x=0;
13     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
14     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
15     return f*x;
16 }
17 int n,m,fa[maxn]; ll c[maxn],v[maxn];
18 void update(int x,ll val){while(x<=n)c[x]+=val,x+=lb(x);}
19 ll query(int x){ll q=0; while(x>0)q+=c[x],x-=lb(x); return q;}
20 int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
21 int main(){
23     fa[n+1]=n+1; inc(i,1,n)if(v[i]<=1)fa[i]=find(i+1);
24     inc(i,1,m){
26         if(x==1)printf("%lld\n",query(r)-query(l-1));
27         if(x==0){
28             int j=l;
29             while(j<=r){
30                 j=find(j); if(j>r)break; ll y=v[j]; v[j]=(ll)sqrt(y);
31                 update(j,v[j]-y); if(v[j]<=1)fa[j]=find(j+1); j++;
32             }
33         }
34     }
35     return 0;
36 }

20160922

posted @ 2016-08-17 14:16  YuanZiming  阅读(118)  评论(0编辑  收藏  举报