10123 | 2024-03-27 17:46:45 | 111 | Maximum felosztás | cpp17 | Wrong answer 25/100 | 1.103s | 136820 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,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]=0;
b[i]=0;
c[i]=0;
c[i*2+1]=1;
c[i*2+2]=1;
}
else{
a[i]+=b[i]*(r-l+1);
if(c[i*2+1]){
a[i*2+1]=0;
b[i*2+1]=0;
c[i*2+1]=0;
}
if(c[i*2+2]){
a[i*2+2]=0;
b[i*2+2]=0;
c[i*2+2]=0;
}
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);
}
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);
}
void clear(){
fill(a.begin(),a.end(),0);
fill(b.begin(),b.end(),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;
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 | 10ms | 4864 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 3040 KiB | ||||
4 | Accepted | 3ms | 3048 KiB | ||||
5 | Accepted | 3ms | 3288 KiB | ||||
6 | Accepted | 3ms | 3492 KiB | ||||
7 | Accepted | 3ms | 3728 KiB | ||||
8 | Accepted | 3ms | 3996 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 4ms | 4196 KiB | ||||
10 | Accepted | 3ms | 4248 KiB | ||||
11 | Accepted | 3ms | 4172 KiB | ||||
12 | Accepted | 3ms | 4456 KiB | ||||
13 | Accepted | 3ms | 4496 KiB | ||||
14 | Accepted | 3ms | 4416 KiB | ||||
15 | Accepted | 4ms | 4360 KiB | ||||
16 | Accepted | 4ms | 4364 KiB | ||||
17 | Accepted | 4ms | 4584 KiB | ||||
18 | Accepted | 4ms | 4812 KiB | ||||
subtask4 | 0/15 | ||||||
19 | Accepted | 17ms | 6624 KiB | ||||
20 | Accepted | 10ms | 6620 KiB | ||||
21 | Accepted | 6ms | 6804 KiB | ||||
22 | Accepted | 6ms | 6856 KiB | ||||
23 | Accepted | 4ms | 7008 KiB | ||||
24 | Accepted | 4ms | 7092 KiB | ||||
25 | Accepted | 10ms | 7088 KiB | ||||
26 | Accepted | 10ms | 6996 KiB | ||||
27 | Accepted | 24ms | 7076 KiB | ||||
28 | Accepted | 21ms | 7160 KiB | ||||
29 | Wrong answer | 4ms | 7052 KiB | ||||
30 | Wrong answer | 6ms | 7044 KiB | ||||
31 | Accepted | 8ms | 6892 KiB | ||||
32 | Accepted | 8ms | 6896 KiB | ||||
33 | Accepted | 14ms | 7052 KiB | ||||
34 | Accepted | 14ms | 6964 KiB | ||||
35 | Accepted | 12ms | 7180 KiB | ||||
36 | Accepted | 10ms | 7324 KiB | ||||
37 | Wrong answer | 6ms | 7060 KiB | ||||
38 | Wrong answer | 6ms | 7204 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Time limit exceeded | 1.103s | 69636 KiB | ||||
40 | Time limit exceeded | 1.065s | 67412 KiB | ||||
41 | Time limit exceeded | 1.062s | 67548 KiB | ||||
42 | Time limit exceeded | 1.072s | 63720 KiB | ||||
43 | Time limit exceeded | 1.082s | 62956 KiB | ||||
44 | Time limit exceeded | 1.067s | 71988 KiB | ||||
45 | Time limit exceeded | 1.077s | 66988 KiB | ||||
46 | Time limit exceeded | 1.046s | 66052 KiB | ||||
47 | Time limit exceeded | 1.062s | 70472 KiB | ||||
48 | Time limit exceeded | 1.046s | 66052 KiB | ||||
49 | Time limit exceeded | 1.065s | 70604 KiB | ||||
50 | Time limit exceeded | 1.065s | 66988 KiB | ||||
51 | Time limit exceeded | 1.082s | 65400 KiB | ||||
52 | Wrong answer | 583ms | 135096 KiB | ||||
53 | Wrong answer | 301ms | 136820 KiB | ||||
54 | Wrong answer | 657ms | 123032 KiB | ||||
55 | Wrong answer | 421ms | 130924 KiB | ||||
56 | Time limit exceeded | 1.072s | 68588 KiB | ||||
57 | Time limit exceeded | 1.062s | 68492 KiB | ||||
58 | Time limit exceeded | 1.054s | 72344 KiB | ||||
59 | Time limit exceeded | 1.059s | 72352 KiB | ||||
60 | Wrong answer | 518ms | 130920 KiB | ||||
61 | Time limit exceeded | 1.059s | 67192 KiB | ||||
62 | Time limit exceeded | 1.082s | 67084 KiB | ||||
63 | Time limit exceeded | 1.062s | 65752 KiB | ||||
64 | Time limit exceeded | 1.074s | 67920 KiB | ||||
65 | Time limit exceeded | 1.057s | 65648 KiB | ||||
66 | Time limit exceeded | 1.062s | 68560 KiB | ||||
67 | Time limit exceeded | 1.078s | 71556 KiB | ||||
68 | Time limit exceeded | 1.07s | 66288 KiB | ||||
69 | Time limit exceeded | 1.057s | 69132 KiB | ||||
70 | Time limit exceeded | 1.046s | 63856 KiB | ||||
71 | Time limit exceeded | 1.077s | 63684 KiB |