12852022-03-30 09:41:50Valaki2Maximum felosztáscpp14Runtime error 40/1001.077s497700 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int mod = 1e9 + 7;
const int maxn = 1e5;

void solve() {
    int n, m;
    cin >> n >> m;
    // mistaking n, m ?
    vector<int> a(1 + n, 0);
    vector<int> b(1 + m, 0);
    vector<int> v(1, 0);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        v.pb(a[i]);
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
        v.pb(b[i]);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for(int i = 1; i <= n; i++) {
        a[i] = (int) (lower_bound(v.begin(), v.end(), a[i]) - v.begin());
    }
    for(int i = 1; i <= m; i++) {
        b[i] = (int) (lower_bound(v.begin(), v.end(), b[i]) - v.begin());
    }
    // all elements between 1 and n+m<=2e5
    /*for(int i = 1; i <= n; i++) {
        cout << a[i] << " ";
    }
    cout << "\n";
    for(int i = 1; i <= m; i++) {
        cout << b[i] << " ";
    }
    cout << "\n";*/
    vector<vector<pair<int, int> > > intervals(1 + 2 * maxn);
    for(int l = 1; l <= n; l++) {
        int maxi = 0;
        for(int r = l; r <= n; r++) {
            maxi = max(maxi, a[r]);
            intervals[maxi].pb(mp(l, r));
        }
    }
    vector<int> dp;
    dp.assign(1 + n, 0);
    dp[0] = 1;
    for(int i = 1; i <= m; i++) {
        vector<int> new_dp(1 + n, 0);
        for(pair<int, int> p : intervals[b[i]]) {
            new_dp[p.se] = (new_dp[p.se] + dp[p.fi - 1]) % mod;
        }
        dp = new_dp;
    }
    cout << dp[n] << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted7ms11000 KiB
2Accepted81ms83348 KiB
subtask210/10
3Accepted9ms16204 KiB
4Accepted9ms15832 KiB
5Accepted9ms15984 KiB
6Accepted8ms15716 KiB
7Accepted9ms15708 KiB
8Accepted8ms15584 KiB
subtask315/15
9Accepted9ms16412 KiB
10Accepted8ms15604 KiB
11Accepted10ms15996 KiB
12Accepted10ms16136 KiB
13Accepted10ms15688 KiB
14Accepted8ms15776 KiB
15Accepted10ms16792 KiB
16Accepted8ms16488 KiB
17Accepted9ms16628 KiB
18Accepted8ms16324 KiB
subtask415/15
19Accepted90ms91648 KiB
20Accepted85ms109772 KiB
21Accepted75ms96996 KiB
22Accepted82ms96804 KiB
23Accepted101ms101692 KiB
24Accepted79ms84900 KiB
25Accepted68ms86732 KiB
26Accepted65ms80580 KiB
27Accepted59ms88708 KiB
28Accepted150ms91596 KiB
29Accepted57ms77388 KiB
30Accepted82ms83288 KiB
31Accepted54ms80664 KiB
32Accepted98ms87832 KiB
33Accepted59ms82560 KiB
34Accepted107ms89896 KiB
35Accepted54ms84088 KiB
36Accepted116ms90992 KiB
37Accepted57ms80388 KiB
38Accepted86ms89392 KiB
subtask50/60
39Runtime error426ms322032 KiB
40Runtime error414ms384804 KiB
41Time limit exceeded367ms190440 KiB
42Time limit exceeded458ms208360 KiB
43Runtime error298ms333632 KiB
44Time limit exceeded363ms178048 KiB
45Runtime error363ms330372 KiB
46Runtime error337ms319856 KiB
47Time limit exceeded446ms215864 KiB
48Time limit exceeded449ms198900 KiB
49Runtime error340ms340616 KiB
50Runtime error314ms298048 KiB
51Time limit exceeded400ms204028 KiB
52Time limit exceeded437ms209568 KiB
53Time limit exceeded402ms201276 KiB
54Runtime error375ms449204 KiB
55Time limit exceeded354ms201144 KiB
56Time limit exceeded518ms224656 KiB
57Time limit exceeded411ms223912 KiB
58Time limit exceeded375ms205136 KiB
59Time limit exceeded1.026s198588 KiB
60Runtime error282ms278040 KiB
61Time limit exceeded398ms230896 KiB
62Runtime error294ms398780 KiB
63Runtime error898ms497556 KiB
64Time limit exceeded293ms213064 KiB
65Runtime error917ms497700 KiB
66Runtime error312ms407020 KiB
67Time limit exceeded1.047s216184 KiB
68Runtime error314ms393484 KiB
69Time limit exceeded1.077s228940 KiB
70Runtime error356ms328544 KiB
71Time limit exceeded819ms231040 KiB