10126 | 2024-03-27 18:05:18 | 111 | Maximum felosztás | cpp17 | Time limit exceeded 40/100 | 1.077s | 141668 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,MI x){
if(l>rr||r<ll){
return;
}
if(l>=ll&&r<=rr){
a[i]+=x*MI(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,MI 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1956 KiB | ||||
2 | Accepted | 6ms | 4860 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2908 KiB | ||||
4 | Accepted | 3ms | 3108 KiB | ||||
5 | Accepted | 3ms | 3044 KiB | ||||
6 | Accepted | 3ms | 3296 KiB | ||||
7 | Accepted | 3ms | 3640 KiB | ||||
8 | Accepted | 3ms | 3640 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 3ms | 3568 KiB | ||||
10 | Accepted | 3ms | 3528 KiB | ||||
11 | Accepted | 3ms | 3636 KiB | ||||
12 | Accepted | 3ms | 3808 KiB | ||||
13 | Accepted | 3ms | 3792 KiB | ||||
14 | Accepted | 3ms | 4040 KiB | ||||
15 | Accepted | 3ms | 3996 KiB | ||||
16 | Accepted | 3ms | 3996 KiB | ||||
17 | Accepted | 3ms | 4252 KiB | ||||
18 | Accepted | 3ms | 4452 KiB | ||||
subtask4 | 15/15 | ||||||
19 | Accepted | 6ms | 6512 KiB | ||||
20 | Accepted | 6ms | 6588 KiB | ||||
21 | Accepted | 4ms | 6924 KiB | ||||
22 | Accepted | 4ms | 6532 KiB | ||||
23 | Accepted | 4ms | 6808 KiB | ||||
24 | Accepted | 4ms | 6780 KiB | ||||
25 | Accepted | 4ms | 6756 KiB | ||||
26 | Accepted | 4ms | 6912 KiB | ||||
27 | Accepted | 7ms | 6952 KiB | ||||
28 | Accepted | 6ms | 7100 KiB | ||||
29 | Accepted | 4ms | 7104 KiB | ||||
30 | Accepted | 4ms | 7092 KiB | ||||
31 | Accepted | 4ms | 7052 KiB | ||||
32 | Accepted | 4ms | 7008 KiB | ||||
33 | Accepted | 6ms | 7044 KiB | ||||
34 | Accepted | 6ms | 6972 KiB | ||||
35 | Accepted | 6ms | 7092 KiB | ||||
36 | Accepted | 4ms | 7504 KiB | ||||
37 | Accepted | 4ms | 7192 KiB | ||||
38 | Accepted | 4ms | 7388 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Accepted | 224ms | 136152 KiB | ||||
40 | Accepted | 200ms | 131864 KiB | ||||
41 | Accepted | 204ms | 131992 KiB | ||||
42 | Accepted | 215ms | 123936 KiB | ||||
43 | Accepted | 250ms | 122636 KiB | ||||
44 | Accepted | 138ms | 140972 KiB | ||||
45 | Accepted | 187ms | 131112 KiB | ||||
46 | Accepted | 252ms | 129276 KiB | ||||
47 | Accepted | 209ms | 138240 KiB | ||||
48 | Accepted | 238ms | 129028 KiB | ||||
49 | Accepted | 244ms | 138260 KiB | ||||
50 | Accepted | 273ms | 130464 KiB | ||||
51 | Accepted | 187ms | 127348 KiB | ||||
52 | Accepted | 247ms | 135184 KiB | ||||
53 | Accepted | 238ms | 136940 KiB | ||||
54 | Accepted | 481ms | 123292 KiB | ||||
55 | Accepted | 382ms | 131008 KiB | ||||
56 | Accepted | 238ms | 133708 KiB | ||||
57 | Accepted | 261ms | 133608 KiB | ||||
58 | Time limit exceeded | 1.062s | 72412 KiB | ||||
59 | Accepted | 777ms | 141668 KiB | ||||
60 | Accepted | 171ms | 131232 KiB | ||||
61 | Time limit exceeded | 1.059s | 67656 KiB | ||||
62 | Time limit exceeded | 1.036s | 67496 KiB | ||||
63 | Time limit exceeded | 1.07s | 65896 KiB | ||||
64 | Time limit exceeded | 1.065s | 68068 KiB | ||||
65 | Time limit exceeded | 1.077s | 65936 KiB | ||||
66 | Time limit exceeded | 1.065s | 68888 KiB | ||||
67 | Accepted | 808ms | 140212 KiB | ||||
68 | Time limit exceeded | 1.075s | 66804 KiB | ||||
69 | Accepted | 930ms | 135596 KiB | ||||
70 | Accepted | 529ms | 124568 KiB | ||||
71 | Accepted | 666ms | 124572 KiB |