zoukankan      html  css  js  c++  java
  • HDU 4027Can you answer these queries?

    题意:先说下写这题的感受吧,在已知这个题开根号的次数不会超过7次的情况下,还是写了2个多小时,完全整个人都是懵的,出了很多小错误,讲道理,这题就只有要注意开根号的次数,加上类似于剪枝的东西,是能过的,但就是很菜,最后交的手都软了,还得多练练线段树;
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<stack>
    #include<map>
    #include<vector>
    #include<set>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #define N 100005
    #define INF 0x3f3f3f3f
    using namespace std;
    typedef struct node {
    	int x;
    	int y;
    	long long date;
    	long long p;
    } node;
    node a[N*4];
    long long b[N];
    long long w[N];
    void built(int root,int first,int end) {
    	if(first==end) {
    		a[root].date=b[first];
    		a[root].x=first;
    		a[root].y=end;
    		a[root].p=0;
    		return ;
    	}
    	int mid=(first+end)/2;
    	built(root*2,first,mid);
    	built(root*2+1,mid+1,end);
    	a[root].x=a[root*2].x;
    	a[root].y=a[root*2+1].y;
    	a[root].date=a[root*2].date+a[root*2+1].date;
    	a[root].p=0;
    }
    void U(int root,int first,int end,int l,int r) {
    	if(l<=first&&end<=r) {
    		a[root].p+=1;
    		return ;
    	}
    	int mid=(first+end)/2;
    	if(a[root].p!=0) {
    		if(a[root].p>7) {
    			a[root].date=(end-first+1);
    		}
    		a[root*2].p+=a[root].p;
    		a[root*2+1].p+=a[root].p;
    		a[root].p=0;
    	}
    	if(l<=mid)  U(root*2,first,mid,l,r);
    	if(r>mid)  U(root*2+1,mid+1,end,l,r);
    	a[root].date=a[root*2].date+a[root*2+1].date;
    }
    long long sum;
    void Q(int root,int first,int end,int l,int r) {
    	if(l<=first&&end<=r) {
    		if(a[root].date==(end-first+1)) {
    			sum+=a[root].date;
    			return ;
    		}
    		if(first==end) {
    			if(a[root].p>7) {
    				a[root].date=1;
    				a[root].p=0;
    				sum+=a[root].date;
    				return ;
    			}
    			if(a[root].p<=7&&a[root].p>0) {
    				long long t=a[root].date;
    				for(int i=1; i<=a[root].p; i++) {
    					t=(int)sqrt(t);
    					if(t==1) {
    						break;
    					}
    				}
    				a[root].date=t;
    				a[root].p=0;
    				sum+=a[root].date;
    				return ;
    			} else {
    				sum+=a[root].date;
    				return ;
    			}
    		}
    	}
    	int mid=(first+end)/2;
    	if(a[root].p!=0) {
    		if(a[root].p>7) {
    			a[root].date=(end-first+1);
    		}
    		a[root*2].p+=a[root].p;
    		a[root*2+1].p+=a[root].p;
    		a[root].p=0;
    	}
    	if(l<=mid)  Q(root*2,first,mid,l,r);
    	if(r>mid)  Q(root*2+1,mid+1,end,l,r);
    	a[root].date=a[root*2].date+a[root*2+1].date;
    }
    int main() {
    	int m;
    	int j=0;
    	while(scanf("%d",&m)!=EOF) {
    		j++;
    		memset(w,0,sizeof(w));
    		printf("Case #%d:
    ",j);
    		for(int i=1; i<=m; i++) {
    			scanf("%I64d",&b[i]);
    		}
    		built(1,1,m);
    		int n;
    		scanf("%d",&n);
    		long long d,c,e;
    		for(int i=1; i<=n; i++) {
    			scanf("%I64d %I64d %I64d",&d,&c,&e);
    			if(c>e)  swap(c,e);
    			if(d==0) {
    				U(1,1,m,c,e);
    			} else if(d==1) {
    				sum=0;
    				Q(1,1,m,c,e);
    				printf("%I64d
    ",sum);
    			}
    		}
    		printf("
    ");
    	}
    	return 0;
    }

  • 相关阅读:
    CentOS重启与关机
    VIM打开文件与保存文件
    sql Split
    JS获取URL参数
    C#后台调用公网接口(GET, POST)
    鼠标右击.exe的程序出现闪退(桌面重启)怎么办
    JS判断有无网络(移动端)
    TFS API : 四、工作项查询
    TFS API:三、TFS WorkItem添加和修改、保存
    TFS API:二、TFS 代码查询工作项
  • 原文地址:https://www.cnblogs.com/wang9897/p/7624396.html
Copyright © 2011-2022 走看看