101252024-03-27 18:04:09111Maximum felosztáscpp17Wrong answer 25/1001.082s142484 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007

struct MI{
	int x;
	
	MI():x(0){
	}
	
	MI(int x):x(x){
	}
	
	MI operator*(MI o){
		return x*o.x%MOD;
	}
	
	void operator=(MI o){
		x=o.x;
	}
	
	void operator+=(MI o){
		x+=o.x;
		if(x>=MOD){
			x-=MOD;
		}
	}
	
	operator int(){
		return x;
	}
};

struct ST{
	int n,k;
	vector<MI>a,b,c;
	
	ST(int n):n(n),a(n*8),b(n*8),c(n*8){
	}
	
	void push(int i,int l,int r){
		if(c[i]==1){
			a[i*2+1]=0;
			a[i*2+2]=0;
			b[i*2+1]=0;
			b[i*2+2]=0;
			c[i*2+1]=1;
			c[i*2+2]=1;
			c[i]=0;
		}
		a[i*2+1]+=b[i]*MI((l+r)/2-l+1);
		a[i*2+2]+=b[i]*MI(r-(l+r)/2);
		b[i*2+1]+=b[i];
		b[i*2+2]+=b[i];
		b[i]=0;
	}
	
	void add(int i,int l,int r,int ll,int rr,int x){
		if(l>rr||r<ll){
			return;
		}
		if(l>=ll&&r<=rr){
			a[i]+=x*(r-l+1);
			b[i]+=x;
			return;
		}
		push(i,l,r);
		add(i*2+1,l,(l+r)/2,ll,rr,x);
		add(i*2+2,(l+r)/2+1,r,ll,rr,x);
		a[i]=a[i*2+1]+a[i*2+2];
	}
	
	void add(int l,int r,int x){
		add(0,0,n-1,l,r,x);
	}
	
	MI sum(int i,int l,int r,int ll,int rr){
		if(l>rr||r<ll){
			return 0;
		}
		if(l>=ll&&r<=rr){
			return a[i];
		}
		push(i,l,r);
		MI ans=0;
		ans+=sum(i*2+1,l,(l+r)/2,ll,rr);
		ans+=sum(i*2+2,(l+r)/2+1,r,ll,rr);
		return ans;
	}
	
	MI sum(int l,int r){
		return sum(0,0,n-1,l,r);
	}
	
	void clear(){
		c[0]=1;
	}
};

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	vector<int>v(N+1),w(M+1);
	map<int,vector<int>>m;
	for(int i=1;i<=N;i++){
		cin>>v[i];
		m[v[i]].push_back(i);
	}
	for(int i=1;i<=M;i++){
		cin>>w[i];
	}
	vector<ST>dp(2,ST(N+1));
	dp[0].add(0,0,1);
	for(int i=1;i<=M;i++){
		dp[i&1].clear();
		for(int j:m[w[i]]){
			MI x=0;
			int k;
			for(k=j;k>0&&v[k]<=w[i];k--){
			}
			x+=dp[i&1^1].sum(k,j-1);
			for(k=j;k<=N&&(k==j||v[k]<w[i]);k++){
			}
			dp[i&1].add(j,k-1,x);
		}
		// for(int j=1;j<=N;j++){
			// cout<<setw(4)<<dp[i&1].sum(j,j)<<' ';
		// }
		// cout<<'\n';
	}
	cout<<dp[M&1].sum(N,N)<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1956 KiB
2Accepted4ms4864 KiB
subtask210/10
3Accepted3ms2808 KiB
4Accepted3ms3084 KiB
5Accepted3ms3024 KiB
6Accepted3ms3292 KiB
7Accepted3ms3536 KiB
8Accepted3ms3492 KiB
subtask315/15
9Accepted3ms3780 KiB
10Accepted3ms4048 KiB
11Accepted4ms4220 KiB
12Accepted3ms4436 KiB
13Accepted3ms4516 KiB
14Accepted3ms4480 KiB
15Accepted4ms4756 KiB
16Accepted4ms4988 KiB
17Accepted3ms5244 KiB
18Accepted3ms5152 KiB
subtask40/15
19Accepted6ms7480 KiB
20Accepted6ms7540 KiB
21Accepted4ms7720 KiB
22Accepted6ms7704 KiB
23Accepted4ms8100 KiB
24Accepted4ms7908 KiB
25Accepted6ms7940 KiB
26Accepted6ms8224 KiB
27Accepted8ms8524 KiB
28Accepted6ms8552 KiB
29Wrong answer4ms8352 KiB
30Accepted4ms8276 KiB
31Accepted6ms8272 KiB
32Accepted6ms8292 KiB
33Accepted7ms8452 KiB
34Accepted6ms8396 KiB
35Accepted6ms8488 KiB
36Accepted4ms8576 KiB
37Accepted4ms8340 KiB
38Wrong answer4ms8564 KiB
subtask50/60
39Accepted256ms137476 KiB
40Accepted228ms133056 KiB
41Accepted237ms133184 KiB
42Accepted244ms125236 KiB
43Accepted224ms123804 KiB
44Accepted150ms142024 KiB
45Accepted173ms132288 KiB
46Accepted221ms130428 KiB
47Accepted193ms139292 KiB
48Accepted233ms130100 KiB
49Accepted197ms139296 KiB
50Accepted231ms131656 KiB
51Accepted182ms128376 KiB
52Accepted215ms136324 KiB
53Wrong answer202ms137988 KiB
54Accepted453ms124088 KiB
55Accepted379ms132112 KiB
56Accepted207ms134680 KiB
57Accepted216ms134684 KiB
58Time limit exceeded1.082s73648 KiB
59Accepted762ms142484 KiB
60Wrong answer155ms132012 KiB
61Time limit exceeded1.07s68288 KiB
62Time limit exceeded1.067s68204 KiB
63Time limit exceeded1.067s66812 KiB
64Time limit exceeded1.08s68904 KiB
65Time limit exceeded1.08s66656 KiB
66Time limit exceeded1.08s69672 KiB
67Accepted809ms140900 KiB
68Time limit exceeded1.077s67344 KiB
69Accepted926ms136172 KiB
70Wrong answer528ms125320 KiB
71Wrong answer663ms125420 KiB