10121 | 2024-03-27 17:33:48 | 111 | Maximum felosztás | cpp17 | Time limit exceeded 40/100 | 1.08s | 53264 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){
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(){
for(int i=0;i<n*8;i++){
a[i]=0;
b[i]=0;
}
}
};
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 | 2092 KiB | ||||
2 | Accepted | 23ms | 4028 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 7ms | 2876 KiB | ||||
4 | Accepted | 3ms | 3084 KiB | ||||
5 | Accepted | 7ms | 2940 KiB | ||||
6 | Accepted | 7ms | 3340 KiB | ||||
7 | Accepted | 3ms | 3500 KiB | ||||
8 | Accepted | 3ms | 3568 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 4ms | 3804 KiB | ||||
10 | Accepted | 4ms | 3948 KiB | ||||
11 | Accepted | 4ms | 3880 KiB | ||||
12 | Accepted | 4ms | 3888 KiB | ||||
13 | Accepted | 3ms | 4040 KiB | ||||
14 | Accepted | 3ms | 3980 KiB | ||||
15 | Accepted | 17ms | 4016 KiB | ||||
16 | Accepted | 17ms | 4024 KiB | ||||
17 | Accepted | 8ms | 4128 KiB | ||||
18 | Accepted | 8ms | 3976 KiB | ||||
subtask4 | 15/15 | ||||||
19 | Accepted | 34ms | 5592 KiB | ||||
20 | Accepted | 26ms | 5552 KiB | ||||
21 | Accepted | 12ms | 5656 KiB | ||||
22 | Accepted | 48ms | 5416 KiB | ||||
23 | Accepted | 12ms | 5808 KiB | ||||
24 | Accepted | 35ms | 5828 KiB | ||||
25 | Accepted | 20ms | 5832 KiB | ||||
26 | Accepted | 19ms | 5736 KiB | ||||
27 | Accepted | 324ms | 5812 KiB | ||||
28 | Accepted | 280ms | 5864 KiB | ||||
29 | Accepted | 16ms | 5776 KiB | ||||
30 | Accepted | 174ms | 5924 KiB | ||||
31 | Accepted | 48ms | 5980 KiB | ||||
32 | Accepted | 156ms | 5860 KiB | ||||
33 | Accepted | 167ms | 5988 KiB | ||||
34 | Accepted | 199ms | 5992 KiB | ||||
35 | Accepted | 114ms | 6224 KiB | ||||
36 | Accepted | 100ms | 6236 KiB | ||||
37 | Accepted | 28ms | 5760 KiB | ||||
38 | Accepted | 41ms | 6144 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Time limit exceeded | 1.064s | 50608 KiB | ||||
40 | Time limit exceeded | 1.067s | 48540 KiB | ||||
41 | Time limit exceeded | 1.024s | 48452 KiB | ||||
42 | Time limit exceeded | 1.059s | 44440 KiB | ||||
43 | Time limit exceeded | 1.075s | 43600 KiB | ||||
44 | Time limit exceeded | 1.044s | 52768 KiB | ||||
45 | Time limit exceeded | 1.08s | 47908 KiB | ||||
46 | Time limit exceeded | 1.064s | 46952 KiB | ||||
47 | Time limit exceeded | 1.067s | 51380 KiB | ||||
48 | Time limit exceeded | 1.072s | 46800 KiB | ||||
49 | Time limit exceeded | 1.067s | 51288 KiB | ||||
50 | Time limit exceeded | 1.077s | 47824 KiB | ||||
51 | Time limit exceeded | 1.064s | 46048 KiB | ||||
52 | Time limit exceeded | 1.064s | 49972 KiB | ||||
53 | Time limit exceeded | 1.055s | 51068 KiB | ||||
54 | Time limit exceeded | 1.067s | 43976 KiB | ||||
55 | Time limit exceeded | 1.07s | 48064 KiB | ||||
56 | Time limit exceeded | 1.059s | 49448 KiB | ||||
57 | Time limit exceeded | 1.08s | 49460 KiB | ||||
58 | Time limit exceeded | 1.072s | 53264 KiB | ||||
59 | Time limit exceeded | 1.064s | 53180 KiB | ||||
60 | Time limit exceeded | 1.072s | 48204 KiB | ||||
61 | Time limit exceeded | 1.047s | 47880 KiB | ||||
62 | Time limit exceeded | 1.075s | 47772 KiB | ||||
63 | Time limit exceeded | 1.059s | 46340 KiB | ||||
64 | Time limit exceeded | 1.044s | 48440 KiB | ||||
65 | Time limit exceeded | 1.07s | 46340 KiB | ||||
66 | Time limit exceeded | 1.047s | 49308 KiB | ||||
67 | Time limit exceeded | 1.075s | 52296 KiB | ||||
68 | Time limit exceeded | 1.07s | 46952 KiB | ||||
69 | Time limit exceeded | 1.072s | 49948 KiB | ||||
70 | Time limit exceeded | 1.07s | 44536 KiB | ||||
71 | Time limit exceeded | 1.044s | 44708 KiB |