10122 | 2024-03-27 17:37:06 | 111 | Maximum felosztás | cpp17 | Time limit exceeded 40/100 | 1.083s | 103632 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){
}
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;
vector<MI>a,b;
ST(int n):n(n),a(n*8),b(n*8){
}
void push(int i,int l,int r){
if(b[i]==-1){
a[i]=0;
b[i]=0;
b[i*2+1]=-1;
b[i*2+2]=-1;
}
else{
a[i]+=b[i];
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;
}
push(i,l,r);
if(l>=ll&&r<=rr){
b[i]+=x;
push(i,l,r);
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);
// for(int i=l;i<=r;i++){
// a[i]+=x;
// }
}
MI sum(int i,int l,int r,int ll,int rr){
if(l>rr||r<ll){
return 0;
}
push(i,l,r);
if(l>=ll&&r<=rr){
return a[i];
}
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);
// MI x=0;
// for(int i=l;i<=r;i++){
// x+=a[i];
// }
// return x;
}
void clear(){
b[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;
for(int k=j;k>0&&v[k]<=w[i];k--){
x+=dp[i&1^1].sum(k-1,k-1);
}
for(int k=j;k<=N&&(k==j||v[k]<w[i]);k++){
dp[i&1].add(k,k,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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2112 KiB | ||||
2 | Accepted | 12ms | 4164 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 7ms | 2928 KiB | ||||
4 | Accepted | 3ms | 3020 KiB | ||||
5 | Accepted | 8ms | 3112 KiB | ||||
6 | Accepted | 7ms | 3324 KiB | ||||
7 | Accepted | 3ms | 3536 KiB | ||||
8 | Accepted | 3ms | 3724 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 4ms | 3944 KiB | ||||
10 | Accepted | 4ms | 4212 KiB | ||||
11 | Accepted | 4ms | 4016 KiB | ||||
12 | Accepted | 4ms | 4276 KiB | ||||
13 | Accepted | 3ms | 4524 KiB | ||||
14 | Accepted | 3ms | 4724 KiB | ||||
15 | Accepted | 16ms | 4752 KiB | ||||
16 | Accepted | 16ms | 4756 KiB | ||||
17 | Accepted | 8ms | 4868 KiB | ||||
18 | Accepted | 8ms | 4612 KiB | ||||
subtask4 | 15/15 | ||||||
19 | Accepted | 10ms | 5964 KiB | ||||
20 | Accepted | 14ms | 6108 KiB | ||||
21 | Accepted | 10ms | 6352 KiB | ||||
22 | Accepted | 52ms | 5916 KiB | ||||
23 | Accepted | 12ms | 6308 KiB | ||||
24 | Accepted | 37ms | 6428 KiB | ||||
25 | Accepted | 9ms | 6508 KiB | ||||
26 | Accepted | 8ms | 6512 KiB | ||||
27 | Accepted | 307ms | 6520 KiB | ||||
28 | Accepted | 266ms | 6512 KiB | ||||
29 | Accepted | 16ms | 6512 KiB | ||||
30 | Accepted | 195ms | 6508 KiB | ||||
31 | Accepted | 45ms | 6400 KiB | ||||
32 | Accepted | 171ms | 6428 KiB | ||||
33 | Accepted | 153ms | 6412 KiB | ||||
34 | Accepted | 202ms | 6508 KiB | ||||
35 | Accepted | 104ms | 6516 KiB | ||||
36 | Accepted | 96ms | 6604 KiB | ||||
37 | Accepted | 26ms | 6232 KiB | ||||
38 | Accepted | 45ms | 6600 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Time limit exceeded | 1.06s | 51160 KiB | ||||
40 | Time limit exceeded | 1.06s | 49084 KiB | ||||
41 | Time limit exceeded | 1.052s | 49068 KiB | ||||
42 | Time limit exceeded | 1.075s | 45180 KiB | ||||
43 | Time limit exceeded | 1.062s | 44332 KiB | ||||
44 | Accepted | 615ms | 103632 KiB | ||||
45 | Time limit exceeded | 1.072s | 48448 KiB | ||||
46 | Time limit exceeded | 1.078s | 47572 KiB | ||||
47 | Accepted | 963ms | 100568 KiB | ||||
48 | Time limit exceeded | 1.065s | 47436 KiB | ||||
49 | Time limit exceeded | 1.006s | 100628 KiB | ||||
50 | Time limit exceeded | 1.075s | 48192 KiB | ||||
51 | Time limit exceeded | 1.07s | 46532 KiB | ||||
52 | Time limit exceeded | 1.067s | 50460 KiB | ||||
53 | Time limit exceeded | 1.055s | 51548 KiB | ||||
54 | Time limit exceeded | 1.054s | 44468 KiB | ||||
55 | Time limit exceeded | 1.077s | 48372 KiB | ||||
56 | Accepted | 578ms | 96104 KiB | ||||
57 | Accepted | 588ms | 96016 KiB | ||||
58 | Time limit exceeded | 1.069s | 53504 KiB | ||||
59 | Time limit exceeded | 1.065s | 53600 KiB | ||||
60 | Time limit exceeded | 1.067s | 48532 KiB | ||||
61 | Time limit exceeded | 1.072s | 48548 KiB | ||||
62 | Time limit exceeded | 1.067s | 48256 KiB | ||||
63 | Time limit exceeded | 1.052s | 46952 KiB | ||||
64 | Time limit exceeded | 1.075s | 49092 KiB | ||||
65 | Time limit exceeded | 1.075s | 46816 KiB | ||||
66 | Time limit exceeded | 1.075s | 49796 KiB | ||||
67 | Time limit exceeded | 1.083s | 52920 KiB | ||||
68 | Time limit exceeded | 1.059s | 47680 KiB | ||||
69 | Time limit exceeded | 1.064s | 50620 KiB | ||||
70 | Time limit exceeded | 1.078s | 45296 KiB | ||||
71 | Time limit exceeded | 1.05s | 45272 KiB |