10125 | 2024-03-27 18:04:09 | 111 | Maximum felosztás | cpp17 | Wrong answer 25/100 | 1.082s | 142484 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1956 KiB | ||||
2 | Accepted | 4ms | 4864 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2808 KiB | ||||
4 | Accepted | 3ms | 3084 KiB | ||||
5 | Accepted | 3ms | 3024 KiB | ||||
6 | Accepted | 3ms | 3292 KiB | ||||
7 | Accepted | 3ms | 3536 KiB | ||||
8 | Accepted | 3ms | 3492 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 3ms | 3780 KiB | ||||
10 | Accepted | 3ms | 4048 KiB | ||||
11 | Accepted | 4ms | 4220 KiB | ||||
12 | Accepted | 3ms | 4436 KiB | ||||
13 | Accepted | 3ms | 4516 KiB | ||||
14 | Accepted | 3ms | 4480 KiB | ||||
15 | Accepted | 4ms | 4756 KiB | ||||
16 | Accepted | 4ms | 4988 KiB | ||||
17 | Accepted | 3ms | 5244 KiB | ||||
18 | Accepted | 3ms | 5152 KiB | ||||
subtask4 | 0/15 | ||||||
19 | Accepted | 6ms | 7480 KiB | ||||
20 | Accepted | 6ms | 7540 KiB | ||||
21 | Accepted | 4ms | 7720 KiB | ||||
22 | Accepted | 6ms | 7704 KiB | ||||
23 | Accepted | 4ms | 8100 KiB | ||||
24 | Accepted | 4ms | 7908 KiB | ||||
25 | Accepted | 6ms | 7940 KiB | ||||
26 | Accepted | 6ms | 8224 KiB | ||||
27 | Accepted | 8ms | 8524 KiB | ||||
28 | Accepted | 6ms | 8552 KiB | ||||
29 | Wrong answer | 4ms | 8352 KiB | ||||
30 | Accepted | 4ms | 8276 KiB | ||||
31 | Accepted | 6ms | 8272 KiB | ||||
32 | Accepted | 6ms | 8292 KiB | ||||
33 | Accepted | 7ms | 8452 KiB | ||||
34 | Accepted | 6ms | 8396 KiB | ||||
35 | Accepted | 6ms | 8488 KiB | ||||
36 | Accepted | 4ms | 8576 KiB | ||||
37 | Accepted | 4ms | 8340 KiB | ||||
38 | Wrong answer | 4ms | 8564 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Accepted | 256ms | 137476 KiB | ||||
40 | Accepted | 228ms | 133056 KiB | ||||
41 | Accepted | 237ms | 133184 KiB | ||||
42 | Accepted | 244ms | 125236 KiB | ||||
43 | Accepted | 224ms | 123804 KiB | ||||
44 | Accepted | 150ms | 142024 KiB | ||||
45 | Accepted | 173ms | 132288 KiB | ||||
46 | Accepted | 221ms | 130428 KiB | ||||
47 | Accepted | 193ms | 139292 KiB | ||||
48 | Accepted | 233ms | 130100 KiB | ||||
49 | Accepted | 197ms | 139296 KiB | ||||
50 | Accepted | 231ms | 131656 KiB | ||||
51 | Accepted | 182ms | 128376 KiB | ||||
52 | Accepted | 215ms | 136324 KiB | ||||
53 | Wrong answer | 202ms | 137988 KiB | ||||
54 | Accepted | 453ms | 124088 KiB | ||||
55 | Accepted | 379ms | 132112 KiB | ||||
56 | Accepted | 207ms | 134680 KiB | ||||
57 | Accepted | 216ms | 134684 KiB | ||||
58 | Time limit exceeded | 1.082s | 73648 KiB | ||||
59 | Accepted | 762ms | 142484 KiB | ||||
60 | Wrong answer | 155ms | 132012 KiB | ||||
61 | Time limit exceeded | 1.07s | 68288 KiB | ||||
62 | Time limit exceeded | 1.067s | 68204 KiB | ||||
63 | Time limit exceeded | 1.067s | 66812 KiB | ||||
64 | Time limit exceeded | 1.08s | 68904 KiB | ||||
65 | Time limit exceeded | 1.08s | 66656 KiB | ||||
66 | Time limit exceeded | 1.08s | 69672 KiB | ||||
67 | Accepted | 809ms | 140900 KiB | ||||
68 | Time limit exceeded | 1.077s | 67344 KiB | ||||
69 | Accepted | 926ms | 136172 KiB | ||||
70 | Wrong answer | 528ms | 125320 KiB | ||||
71 | Wrong answer | 663ms | 125420 KiB |