hdu 4866 Shooting

Shooting

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 846    Accepted Submission(s): 165


Problem Description
In the shooting game, the player can choose to stand in the position of [1, X] to shoot, you can shoot all the nearest K targets. The value of K may be different on different shootings. There are N targets to shoot, each target occupy the position of [Li, Ri] , the distance from the starting line is Di(1<=i<=N). Shooting a target can get the bonus points equal to the distance to the starting line. After each shooting targets still exist. Additional, if the previous bonus points is more than P, then as a reward for the shooting present bonus points doubled(and then check the next one). Player wants to know the bonus points he got in each shot.

 

Input
The input consists several test cases. 
The first line has two integers, N, M, X, P(1<=N, M ,X<=100000, P<=1000000000), N represents the total number of target shooting, M represents the number of shooting. 
The next N lines of three integers L, R, D (1<=L<=R<=X, 1<=D<=10000000), occupy the position of [L, R] and the distance from the starting line is D. 
The next M lines, each line contains four integers x, a, b, c (1<=x<=X, 0<=a,b<=N, 1<=c<=10000000), and K = ( a * Pre + b ) % c. Pre is the bonus point of previous shooting , and for the first shooting Pre=1. It denotes standing in the position x and the player can shoot the nearest K targets.
 

Output
Output M lines each corresponds to one integer.
 

Sample Input
  
  
4 3 5 8 1 2 6 2 3 3 2 4 7 1 5 2 2 2 1 5 3 1 1 10 4 2 3 7
 

Sample Output
  
  
11 10 18
 


将目标按d排序,一个一个的插入线段树,区间更新,这样会牵涉到标记下传,但在可持久化线段树里面,标记下传是一个很耗内存的事,所以我们不用下传,只是在查询的时候,一路加到底,因为如果我们在某点打了标记,那么他的儿子也都要变化这么多。内存是硬伤。

#pragma comment(linker,"/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define red(i,s,t) for(int i=s-1;i>=t;i--)
#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)
#define clr(a,v) memset(a,v,sizeof a)
#define L t<<1
#define R t<<1|1
#define MID(l,r) int mid=(l+r)>>1
#define lowbit(x) (x&(-x))
#define SQR(a) ((a)*(a))

inline int input(){
	int ret=0;bool isN=0;char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') isN=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10+c-'0';
		c=getchar();
	}
	return isN?-ret:ret;
}

inline void output(ll x){    
    if(x<0){    
        putchar('-');x=-x;    
    }    
    int len=0,data[20];    
    while(x){    
        data[len++]=x%10;x/=10;    
    }    
    if(!len)    data[len++]=0;    
    while(len--)   
        putchar(data[len]+48);    
    putchar('\n');  
}  

const int MAXN=5900100;
int n,m,x,p;
int shotx,a,b,c,k;
ll pre,ans;
int ls[MAXN],rs[MAXN],num[MAXN],tot,root[100005];
ll sum[MAXN];

inline void copy(int k,int p){
	ls[k]=ls[p],rs[k]=rs[p],num[k]=num[p],sum[k]=sum[p];
}

inline int build(int l,int r){
	int k=(++tot);
	sum[k]=num[k]=0;
	if(l!=r){
		MID(l,r);
		ls[k]=build(l,mid);
		rs[k]=build(mid+1,r);
	}
	return k;
}

inline int add(int p,int l,int r,int x,int y,int w){
	int k=(++tot);copy(k,p);
	if(l>=x && r<=y){
		num[k]++,sum[k]+=w;
	}
	else{
		MID(l,r);
		if(y<=mid) ls[k]=add(ls[p],l,mid,x,y,w);
		else if(x>mid) rs[k]=add(rs[p],mid+1,r,x,y,w);
		else{
			ls[k]=add(ls[p],l,mid,x,mid,w);
			rs[k]=add(rs[p],mid+1,r,mid+1,y,w);
		}
	}
	return k;
}

inline int queryN(int p,int l,int r,int x){
	int ans=num[p];
	if(l!=r){
		MID(l,r);
		if(x<=mid) ans+=queryN(ls[p],l,mid,x);
		else ans+=queryN(rs[p],mid+1,r,x);
	}
	return ans;
}

inline ll queryS(int p,int l,int r,int x){
	ll ans=sum[p];
	if(l!=r){
		MID(l,r);
		if(x<=mid) ans+=queryS(ls[p],l,mid,x);
		else ans+=queryS(rs[p],mid+1,r,x);
	}
	return ans;
}

inline int Binary_Search(int s,int t,int shotx,int k){
	int cnt;
	while(s<=t){
		MID(s,t);
		cnt=queryN(root[mid],1,x,shotx);
		if(cnt==k) return mid;
		if(cnt<=k) s=mid+1;
		else t=mid-1;
	}
	return s;
}

struct TARGET{
	int l,r,d;
	void read(){
		l=input(),r=input(),d=input();
	}
	bool operator < (const TARGET &a) const{
		return d<a.d || (d==a.d&&l<a.l) || (d==a.d&&l==a.l&&r<a.r);
	}
}target[100005];


int main(){
	//cout<<sizeof(sum)+sizeof(num)+sizeof(ls)+sizeof(rs)+sizeof(root)<<endl;
	while(~scanf("%d%d%d%d",&n,&m,&x,&p)){
		rep(i,0,n) target[i].read();
		sort(target,target+n);
		tot=0;
		root[0]=build(1,x);
		rep(i,0,n){
			root[i+1]=add(root[i],1,x,target[i].l,target[i].r,target[i].d);
		}
		pre=1;
		rep(i,0,m){
			shotx=input(),a=input(),b=input(),c=input();
			k=(pre*a+b)%c;
			if(!k) pre=0;
			else{
				int pos=Binary_Search(0,n,shotx,k);//二分在shotx处哪棵线段树的目标数==k
				ans=queryS(root[pos],1,x,shotx);
				if(pre>p) ans<<=1;
				pre=ans;
			}
			output(pre);
		}
	}
	return 0;
}


官方解题报告里面,是按d建树的,把每个目标表示成左端点,和右端点,然后按x升序往线段树里面放这些点,左端点就+1,并且加上d,否则就-1,并且-d

查询就是根据x二分找到合适的线段树,在这棵树上找前k个数的和。


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define red(i,s,t) for(int i=s-1;i>=t;i--)
#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)
#define clr(a,v) memset(a,v,sizeof a)
#define L t<<1
#define R t<<1|1
#define MID(l,r) int mid=(l+r)>>1
#define lowbit(x) (x&(-x))
#define SQR(a) ((a)*(a))

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';
        c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){    
    if(x<0){    
        putchar('-');x=-x;    
    }    
    int len=0,data[11];    
    while(x){    
        data[len++]=x%10;x/=10;    
    }    
    if(!len)    data[len++]=0;    
    while(len--)   
        putchar(data[len]+48);    
    putchar('\n');  
} 

const int MAXN=100005;
struct TARGET{
    int l,r,d;
    void read(){
        scanf("%d%d%d",&l,&r,&d);
    }
    bool operator < (const TARGET &a) const{
        return l<a.l || (l==a.l && r<a.r);
    }
}ta[MAXN];
struct Add{
    int x,d,flag;
    void init(int _x,int _d,int _flag){
        x=_x,d=_d,flag=_flag;
    }
    bool operator < (const Add &a) const {
        return x<a.x || (x==a.x && flag>a.flag) || (x==a.x && flag==a.flag && d<a.d);
    }
}A[MAXN<<1];

int root[4000005],ls[4000005],rs[4000005],l[4000005],r[4000005],num[4000005];
ll sum[4000005];
int d[MAXN],cnt,tot;
int n,m,x,p,shotx,shota,shotb,shotc;
ll pre;
inline void copy(int k,int p){
    sum[k]=sum[p];num[k]=num[p];
    ls[k]=ls[p],rs[k]=rs[p];
    l[k]=l[p],r[k]=r[p];
}

inline int build(int x,int y){
    int k=tot++;
    l[k]=x,r[k]=y;
    num[k]=sum[k]=0;
    if(x!=y){
        MID(x,y);
        ls[k]=build(x,mid);
        rs[k]=build(mid+1,y);
    }
    return k;
}

inline int change(int p,int x,int val,int v){
    int k=tot++;
    copy(k,p);
    num[k]+=v,sum[k]+=val;
    if(l[p]==r[p]) return k;
    MID(l[p],r[p]);
    if(x<=mid) ls[k]=change(ls[p],x,val,v);
    else rs[k]=change(rs[p],x,val,v);
    return k;
}

inline ll query(int p,int l,int r,int k){
    if(l==r) return k*1LL*d[l];
    MID(l,r);
    if(k<=num[ls[p]]) return query(ls[p],l,mid,k);
    return sum[ls[p]]+query(rs[p],mid+1,r,k-num[ls[p]]);
}
int main(){
    while(~scanf("%d%d%d%d",&n,&m,&x,&p)){
        cnt=tot=0;
        rep(i,0,n){
            ta[i].read();
            d[++cnt]=ta[i].d;
        }
        sort(d+1,d+cnt+1);
        cnt=unique(d+1,d+cnt+1)-(d+1);
        int id=0;
        rep(i,0,n){
            int dd=lower_bound(d+1,d+cnt+1,ta[i].d)-(d+1)+1;
            A[id++].init(ta[i].l,dd,1);
            A[id++].init(ta[i].r,dd,-1);
        }
        
        sort(A,A+id);
        root[0]=build(1,cnt);
        rep(i,0,id){
            root[i+1]=change(root[i],A[i].d,A[i].flag*d[A[i].d],A[i].flag*1);
        }
        pre=1;
        rep(i,0,m){
            scanf("%d%d%d%d",&shotx,&shota,&shotb,&shotc);
            Add a;
            a.init(shotx,1,0);
            int xid=lower_bound(A,A+id,a)-(A);
            int pos=(pre*shota+shotb)%shotc;
            ll ans=query(root[xid],1,cnt,pos);
            if(pre>p) ans<<=1;
            pre=ans;
            cout<<ans<<endl;
        }
    }
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
应用背景为变电站电力巡检,基于YOLO v4算法模型对常见电力巡检目标进行检测,并充分利用Ascend310提供的DVPP等硬件支持能力来完成流媒体的传输、处理等任务,并对系统性能做出一定的优化。.zip深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值