哇,不知道哪里错了(顺便也可以教一下我哈希两个数)
查看原帖
哇,不知道哪里错了(顺便也可以教一下我哈希两个数)
520544
Phrvth楼主2022/8/7 08:48

我写了个记忆化搜索,由于需要储存两个参数,所以用了哈希(我乱写的

CodeCode

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod=998244353;
const ll hmod=1111111;
const ll p=523;
struct line{ll l,r,h;}l[500005];
bool cmp(line a,line b){return a.h>b.h;	}
ll n,m,x[300005],ans,vis[1111120];
ll Hash(ll a,ll b){
	return (a*p%hmod*p%hmod*p%hmod+b*p%hmod*p%hmod+p*a%hmod*b%hmod)*p%hmod;
}
int dfs(ll now,ll hight)
{
	if(hight==1) return 1;
	ll hashkey=Hash(now,hight);//乱七八糟的哈希 
	if(vis[hashkey]) return vis[hashkey];
	ll cnt=0,flag=0;
	for(int i=1;i<=m;i++)
		if(hight>l[i].h&&now>=l[i].l&&now<=l[i].r){
			cnt+=dfs(l[i].l,l[i].h)+dfs(l[i].r,l[i].h);
			flag=1;break;
		}
	if(!flag) return vis[hashkey]=1;
	return vis[hashkey]=cnt;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>l[i].l>>l[i].r>>l[i].h;
	for(int i=1;i<=n;i++){
		cin>>x[i];
		ans=(ans+dfs(x[i],10000000))%mod;
	}
	cout<<ans;
	return 0;
} 

真的是乱写的,请不要喷太厉害

2022/8/7 08:48
加载中...