Submission #1003504

# Submission time Handle Problem Language Result Execution time Memory
1003504 2024-06-20T12:01:44 Z vjudge1 Flooding Wall (BOI24_wall) C++17
56 / 100
2115 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

const int N = 5e5+5, mod = 1e9+7;

int n, a[N], b[N], c[N], pre2[N], suf2[N];
vector<int> pre[N], suf[N];
vector<pair<int, int>> cp;

int pw(int x, int y) {
  return (!y ? 1 : pw(x*x % mod, y/2) * (y%2 ? x : 1) % mod);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] > b[i]) swap(a[i], b[i]);
  }

    vector<int> u;
    u.push_back(0);
    for (int i = 0; i < n; i++) {
      u.push_back(a[i]);
      u.push_back(b[i]);
    }
    sort(all(u));
    u.erase(unique(all(u)), u.end());

    int sz = u.size();
    for (int i = 0; i < sz; i++) {
      cp.push_back(make_pair(u[i], u[i]));

      if (i+1 < sz && u[i]+1 <= u[i+1]-1) cp.push_back(make_pair(u[i]+1, u[i+1]-1));
    }
    sz = cp.size();

    for (int i = 0; i < n; i++) {
      pre[i].resize(sz);
      suf[i].resize(sz);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < sz; j++) {
        pre[i][j] = (i ? pre[i-1][j] : 1);
        
        if (b[i] <= cp[j].second) {
          pre[i][j] *= 2;
          pre[i][j] %= mod;
        }
        else if (a[i] > cp[j].second) pre[i][j] = 0;
      }
    }

    for (int i = n-1; i >= 0; i--) {
      for (int j = 0; j < sz; j++) {
        suf[i][j] = (i+1 < n ? suf[i+1][j] : 1);
        
        if (b[i] <= cp[j].second) {
          suf[i][j] *= 2;
          suf[i][j] %= mod;
        }
        else if (a[i] > cp[j].second) suf[i][j] = 0;
      }
    }

    int ans = 0;
    for (int i = 1; i < n-1; i++) {
      for (int j = 1; j < sz; j++) {
        int x = 0;

        x += pw(2, n-1-i) * pre[i-1][j-1] % mod;
        x %= mod;

        x += pw(2, i) * suf[i+1][j-1] % mod;
        x %= mod;

        x = (x - pre[i-1][j-1] * suf[i+1][j-1] % mod + mod) % mod;

        if (a[i] < cp[j].first) {
          ans += (pw(2, n-1) - x + mod) % mod * (cp[j].second-cp[j].first+1) % mod;
          ans %= mod;
        }

        if (b[i] < cp[j].first) {
          ans += (pw(2, n-1) - x + mod) % mod * (cp[j].second-cp[j].first+1) % mod;
          ans %= mod;
        }
      }
    }

    cout << ans << "\n";
  //}
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23924 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 9 ms 23956 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 9 ms 23896 KB Output is correct
9 Correct 8 ms 23900 KB Output is correct
10 Correct 9 ms 23900 KB Output is correct
11 Correct 10 ms 23896 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 13 ms 23784 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23956 KB Output is correct
16 Correct 8 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23868 KB Output is correct
19 Correct 10 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 9 ms 23900 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23952 KB Output is correct
3 Correct 9 ms 23900 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 10 ms 23964 KB Output is correct
6 Correct 10 ms 23956 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 9 ms 23820 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 12 ms 23896 KB Output is correct
11 Correct 9 ms 23896 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 13 ms 23900 KB Output is correct
14 Correct 10 ms 23968 KB Output is correct
15 Correct 13 ms 24664 KB Output is correct
16 Correct 12 ms 24412 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23880 KB Output is correct
19 Correct 10 ms 23896 KB Output is correct
20 Correct 13 ms 24156 KB Output is correct
21 Correct 12 ms 23900 KB Output is correct
22 Correct 10 ms 23812 KB Output is correct
23 Correct 10 ms 23928 KB Output is correct
24 Correct 14 ms 23804 KB Output is correct
25 Correct 11 ms 24132 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 10 ms 23952 KB Output is correct
3 Correct 9 ms 23900 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 10 ms 23964 KB Output is correct
6 Correct 10 ms 23956 KB Output is correct
7 Correct 11 ms 23900 KB Output is correct
8 Correct 9 ms 23820 KB Output is correct
9 Correct 10 ms 23900 KB Output is correct
10 Correct 12 ms 23896 KB Output is correct
11 Correct 9 ms 23896 KB Output is correct
12 Correct 10 ms 23900 KB Output is correct
13 Correct 13 ms 23900 KB Output is correct
14 Correct 10 ms 23968 KB Output is correct
15 Correct 13 ms 24664 KB Output is correct
16 Correct 12 ms 24412 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23880 KB Output is correct
19 Correct 10 ms 23896 KB Output is correct
20 Correct 13 ms 24156 KB Output is correct
21 Correct 12 ms 23900 KB Output is correct
22 Correct 10 ms 23812 KB Output is correct
23 Correct 10 ms 23928 KB Output is correct
24 Correct 14 ms 23804 KB Output is correct
25 Correct 11 ms 24132 KB Output is correct
26 Correct 11 ms 23900 KB Output is correct
27 Correct 2039 ms 181040 KB Output is correct
28 Correct 2115 ms 180948 KB Output is correct
29 Correct 15 ms 24796 KB Output is correct
30 Correct 17 ms 24900 KB Output is correct
31 Correct 37 ms 26080 KB Output is correct
32 Correct 36 ms 26508 KB Output is correct
33 Correct 50 ms 27104 KB Output is correct
34 Correct 37 ms 26080 KB Output is correct
35 Correct 37 ms 26332 KB Output is correct
36 Correct 59 ms 27104 KB Output is correct
37 Correct 15 ms 24960 KB Output is correct
38 Correct 15 ms 25052 KB Output is correct
39 Correct 33 ms 26080 KB Output is correct
40 Correct 34 ms 26152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23924 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 9 ms 23956 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 9 ms 23896 KB Output is correct
9 Correct 8 ms 23900 KB Output is correct
10 Correct 9 ms 23900 KB Output is correct
11 Correct 10 ms 23896 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 13 ms 23784 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23956 KB Output is correct
16 Correct 8 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23868 KB Output is correct
19 Correct 10 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 9 ms 23900 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 12 ms 23900 KB Output is correct
24 Correct 10 ms 23952 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23896 KB Output is correct
27 Correct 10 ms 23964 KB Output is correct
28 Correct 10 ms 23956 KB Output is correct
29 Correct 11 ms 23900 KB Output is correct
30 Correct 9 ms 23820 KB Output is correct
31 Correct 10 ms 23900 KB Output is correct
32 Correct 12 ms 23896 KB Output is correct
33 Correct 9 ms 23896 KB Output is correct
34 Correct 10 ms 23900 KB Output is correct
35 Correct 13 ms 23900 KB Output is correct
36 Correct 10 ms 23968 KB Output is correct
37 Correct 13 ms 24664 KB Output is correct
38 Correct 12 ms 24412 KB Output is correct
39 Correct 10 ms 23900 KB Output is correct
40 Correct 10 ms 23880 KB Output is correct
41 Correct 10 ms 23896 KB Output is correct
42 Correct 13 ms 24156 KB Output is correct
43 Correct 12 ms 23900 KB Output is correct
44 Correct 10 ms 23812 KB Output is correct
45 Correct 10 ms 23928 KB Output is correct
46 Correct 14 ms 23804 KB Output is correct
47 Correct 11 ms 24132 KB Output is correct
48 Correct 11 ms 23900 KB Output is correct
49 Correct 2039 ms 181040 KB Output is correct
50 Correct 2115 ms 180948 KB Output is correct
51 Correct 15 ms 24796 KB Output is correct
52 Correct 17 ms 24900 KB Output is correct
53 Correct 37 ms 26080 KB Output is correct
54 Correct 36 ms 26508 KB Output is correct
55 Correct 50 ms 27104 KB Output is correct
56 Correct 37 ms 26080 KB Output is correct
57 Correct 37 ms 26332 KB Output is correct
58 Correct 59 ms 27104 KB Output is correct
59 Correct 15 ms 24960 KB Output is correct
60 Correct 15 ms 25052 KB Output is correct
61 Correct 33 ms 26080 KB Output is correct
62 Correct 34 ms 26152 KB Output is correct
63 Runtime error 363 ms 1048576 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 9 ms 23956 KB Output is correct
3 Correct 10 ms 23944 KB Output is correct
4 Correct 9 ms 24152 KB Output is correct
5 Correct 9 ms 23900 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23972 KB Output is correct
8 Correct 8 ms 23972 KB Output is correct
9 Correct 11 ms 23976 KB Output is correct
10 Correct 16 ms 24888 KB Output is correct
11 Correct 16 ms 24804 KB Output is correct
12 Correct 16 ms 24808 KB Output is correct
13 Correct 13 ms 24800 KB Output is correct
14 Correct 374 ms 72624 KB Output is correct
15 Correct 408 ms 72736 KB Output is correct
16 Correct 365 ms 72620 KB Output is correct
17 Correct 354 ms 72628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23924 KB Output is correct
4 Correct 9 ms 23900 KB Output is correct
5 Correct 10 ms 23896 KB Output is correct
6 Correct 9 ms 23956 KB Output is correct
7 Correct 8 ms 23900 KB Output is correct
8 Correct 9 ms 23896 KB Output is correct
9 Correct 8 ms 23900 KB Output is correct
10 Correct 9 ms 23900 KB Output is correct
11 Correct 10 ms 23896 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 13 ms 23784 KB Output is correct
14 Correct 10 ms 23896 KB Output is correct
15 Correct 10 ms 23956 KB Output is correct
16 Correct 8 ms 23900 KB Output is correct
17 Correct 10 ms 23900 KB Output is correct
18 Correct 10 ms 23868 KB Output is correct
19 Correct 10 ms 23900 KB Output is correct
20 Correct 10 ms 23900 KB Output is correct
21 Correct 9 ms 23900 KB Output is correct
22 Correct 10 ms 23900 KB Output is correct
23 Correct 12 ms 23900 KB Output is correct
24 Correct 10 ms 23952 KB Output is correct
25 Correct 9 ms 23900 KB Output is correct
26 Correct 9 ms 23896 KB Output is correct
27 Correct 10 ms 23964 KB Output is correct
28 Correct 10 ms 23956 KB Output is correct
29 Correct 11 ms 23900 KB Output is correct
30 Correct 9 ms 23820 KB Output is correct
31 Correct 10 ms 23900 KB Output is correct
32 Correct 12 ms 23896 KB Output is correct
33 Correct 9 ms 23896 KB Output is correct
34 Correct 10 ms 23900 KB Output is correct
35 Correct 13 ms 23900 KB Output is correct
36 Correct 10 ms 23968 KB Output is correct
37 Correct 13 ms 24664 KB Output is correct
38 Correct 12 ms 24412 KB Output is correct
39 Correct 10 ms 23900 KB Output is correct
40 Correct 10 ms 23880 KB Output is correct
41 Correct 10 ms 23896 KB Output is correct
42 Correct 13 ms 24156 KB Output is correct
43 Correct 12 ms 23900 KB Output is correct
44 Correct 10 ms 23812 KB Output is correct
45 Correct 10 ms 23928 KB Output is correct
46 Correct 14 ms 23804 KB Output is correct
47 Correct 11 ms 24132 KB Output is correct
48 Correct 11 ms 23900 KB Output is correct
49 Correct 2039 ms 181040 KB Output is correct
50 Correct 2115 ms 180948 KB Output is correct
51 Correct 15 ms 24796 KB Output is correct
52 Correct 17 ms 24900 KB Output is correct
53 Correct 37 ms 26080 KB Output is correct
54 Correct 36 ms 26508 KB Output is correct
55 Correct 50 ms 27104 KB Output is correct
56 Correct 37 ms 26080 KB Output is correct
57 Correct 37 ms 26332 KB Output is correct
58 Correct 59 ms 27104 KB Output is correct
59 Correct 15 ms 24960 KB Output is correct
60 Correct 15 ms 25052 KB Output is correct
61 Correct 33 ms 26080 KB Output is correct
62 Correct 34 ms 26152 KB Output is correct
63 Runtime error 363 ms 1048576 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -