답안 #1029951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029951 2024-07-21T14:27:36 Z yeediot Flooding Wall (BOI24_wall) C++17
100 / 100
679 ms 67892 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
#ifdef local
void CHECK();
void setio(){
    freopen("/Users/iantsai/cpp/input.txt","r",stdin);
    freopen("/Users/iantsai/cpp/output.txt","w",stdout);
}
#else
void setio(){}
#endif
#define TOI_is_so_de ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);setio();
const int mxn = 1e6 + 105, mod = 1e9 + 7;
int n, a[mxn], b[mxn], pw[mxn], A[mxn], B[mxn];
#define s seg[id]
#define L seg[id * 2]
#define R seg[id * 2 + 1]
struct node{
    int val, tag;
};
vector<int>temp, v;
struct segment_tree{
    int tmr = 0;
    #ifdef local
    node seg[4000];
    #else
    node seg[4 * mxn];
    #endif
    void merge(int id){
        s.val = ((long long)L.val + R.val) % mod;
    }
    void build(int l, int r, int id){
        s.tag = 1;
        if(l == r){
            s.val = v[l];
            return;
        }
        int mm = l + r >> 1;
        build(l, mm, id * 2);
        build(mm + 1, r, id * 2 + 1);
        merge(id);
    }
    void push(int id, int l, int r){
        L.tag = (long long)L.tag * s.tag % mod;
        R.tag = (long long)R.tag * s.tag % mod;
        L.val = (long long)L.val * s.tag % mod;
        R.val = (long long)R.val * s.tag % mod;
        s.tag = 1;
    }
    void modify(int l, int r, int id, int ql, int qr, int v){
        if(s.tag == 0) return;
        if(qr < l or r < ql) return;
        if(ql <= l and r <= qr){
            s.val = (long long)s.val * v % mod;
            s.tag = (long long)s.tag * v % mod;
            return;
        }
        push(id, l, r);
        int mm = l + r >> 1;
        modify(l, mm, id * 2, ql, qr, v);
        modify(mm + 1, r, id * 2 + 1, ql, qr, v);
        merge(id);
    }
};
void solve(){
    cin >> n;
    pw[0] = 1;
    for(int i = 1; i <= n; i++){
        pw[i] = pw[i - 1] * 2 % mod;
    }
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i];
        if(a[i] > b[i]) swap(a[i], b[i]);
        temp.pb(a[i]);
        temp.pb(b[i]);
    }
    temp.pb(1);
    temp.pb(0);
    temp.pb(mod);
    sort(all(temp));
    temp.resize(unique(all(temp))-temp.begin());
    int prev = 0;
    for(auto x : temp){
        v.pb(x - prev);
        prev = x;
    }
    for(int i = 1; i <= n; i++){
        A[i] = lower_bound(all(temp), a[i]) - temp.begin();
        B[i] = lower_bound(all(temp), b[i]) - temp.begin();
    }
    long long ans = 0;
    segment_tree t1;
    int N = sz(temp) - 1;
    t1.build(1, N, 1);
    for(int i = 1; i <= n; i++){
        t1.modify(1, N, 1, 1, A[i], 0);
        t1.modify(1, N, 1, B[i] + 1, N, 2);
        ans = (ans - (long long)t1.seg[1].val * pw[n - i] % mod) % mod;
    }
    t1.build(1, N, 1);
    for(int i = n; i >= 1; i--){
        t1.modify(1, N, 1, 1, A[i], 0);
        t1.modify(1, N, 1, B[i] + 1, N, 2);
        ans = (ans - (long long)t1.seg[1].val * pw[i - 1] % mod) % mod;
    }
    ans = ((long long)ans + (long long)n * t1.seg[1].val % mod);
    for(int i = 1; i <= n; i++){
        ans = ((long long)ans + pw[n - 1] * ((long long)b[i] - a[i] + (mod - b[i]) * 2LL % mod)) % mod;
    }
    if(ans < 0) ans += mod;
    cout << ans << '\n';
}
signed main(){
    TOI_is_so_de;
    int t = 1;
    while(t--){
        solve();
    }
}
/*
input:
 
*/

Compilation message

Main.cpp: In member function 'void segment_tree::build(int, int, int)':
Main.cpp:52:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |         int mm = l + r >> 1;
      |                  ~~^~~
Main.cpp: In member function 'void segment_tree::modify(int, int, int, int, int, int)':
Main.cpp:73:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |         int mm = l + r >> 1;
      |                  ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 39768 KB Output is correct
2 Correct 18 ms 39772 KB Output is correct
3 Correct 15 ms 39772 KB Output is correct
4 Correct 15 ms 39908 KB Output is correct
5 Correct 15 ms 39772 KB Output is correct
6 Correct 15 ms 39772 KB Output is correct
7 Correct 16 ms 39744 KB Output is correct
8 Correct 14 ms 39816 KB Output is correct
9 Correct 18 ms 39772 KB Output is correct
10 Correct 16 ms 39772 KB Output is correct
11 Correct 17 ms 39792 KB Output is correct
12 Correct 14 ms 39768 KB Output is correct
13 Correct 19 ms 39768 KB Output is correct
14 Correct 17 ms 39772 KB Output is correct
15 Correct 14 ms 39968 KB Output is correct
16 Correct 18 ms 39904 KB Output is correct
17 Correct 21 ms 39772 KB Output is correct
18 Correct 15 ms 39792 KB Output is correct
19 Correct 18 ms 39952 KB Output is correct
20 Correct 20 ms 39768 KB Output is correct
21 Correct 20 ms 40028 KB Output is correct
22 Correct 19 ms 39764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 39772 KB Output is correct
2 Correct 22 ms 39768 KB Output is correct
3 Correct 21 ms 39772 KB Output is correct
4 Correct 16 ms 39772 KB Output is correct
5 Correct 19 ms 39932 KB Output is correct
6 Correct 18 ms 39768 KB Output is correct
7 Correct 17 ms 39768 KB Output is correct
8 Correct 20 ms 39772 KB Output is correct
9 Correct 18 ms 39772 KB Output is correct
10 Correct 18 ms 39768 KB Output is correct
11 Correct 17 ms 39772 KB Output is correct
12 Correct 18 ms 39884 KB Output is correct
13 Correct 16 ms 39772 KB Output is correct
14 Correct 17 ms 39916 KB Output is correct
15 Correct 19 ms 39828 KB Output is correct
16 Correct 20 ms 39888 KB Output is correct
17 Correct 15 ms 39772 KB Output is correct
18 Correct 14 ms 39832 KB Output is correct
19 Correct 19 ms 39772 KB Output is correct
20 Correct 15 ms 39976 KB Output is correct
21 Correct 21 ms 39808 KB Output is correct
22 Correct 19 ms 39768 KB Output is correct
23 Correct 19 ms 39772 KB Output is correct
24 Correct 18 ms 39772 KB Output is correct
25 Correct 18 ms 39768 KB Output is correct
26 Correct 14 ms 39768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 39772 KB Output is correct
2 Correct 22 ms 39768 KB Output is correct
3 Correct 21 ms 39772 KB Output is correct
4 Correct 16 ms 39772 KB Output is correct
5 Correct 19 ms 39932 KB Output is correct
6 Correct 18 ms 39768 KB Output is correct
7 Correct 17 ms 39768 KB Output is correct
8 Correct 20 ms 39772 KB Output is correct
9 Correct 18 ms 39772 KB Output is correct
10 Correct 18 ms 39768 KB Output is correct
11 Correct 17 ms 39772 KB Output is correct
12 Correct 18 ms 39884 KB Output is correct
13 Correct 16 ms 39772 KB Output is correct
14 Correct 17 ms 39916 KB Output is correct
15 Correct 19 ms 39828 KB Output is correct
16 Correct 20 ms 39888 KB Output is correct
17 Correct 15 ms 39772 KB Output is correct
18 Correct 14 ms 39832 KB Output is correct
19 Correct 19 ms 39772 KB Output is correct
20 Correct 15 ms 39976 KB Output is correct
21 Correct 21 ms 39808 KB Output is correct
22 Correct 19 ms 39768 KB Output is correct
23 Correct 19 ms 39772 KB Output is correct
24 Correct 18 ms 39772 KB Output is correct
25 Correct 18 ms 39768 KB Output is correct
26 Correct 14 ms 39768 KB Output is correct
27 Correct 20 ms 40024 KB Output is correct
28 Correct 20 ms 40028 KB Output is correct
29 Correct 18 ms 40028 KB Output is correct
30 Correct 21 ms 40028 KB Output is correct
31 Correct 25 ms 39976 KB Output is correct
32 Correct 19 ms 40204 KB Output is correct
33 Correct 16 ms 40236 KB Output is correct
34 Correct 19 ms 40000 KB Output is correct
35 Correct 17 ms 40044 KB Output is correct
36 Correct 20 ms 40180 KB Output is correct
37 Correct 18 ms 40028 KB Output is correct
38 Correct 21 ms 40028 KB Output is correct
39 Correct 19 ms 40028 KB Output is correct
40 Correct 18 ms 40280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 39768 KB Output is correct
2 Correct 18 ms 39772 KB Output is correct
3 Correct 15 ms 39772 KB Output is correct
4 Correct 15 ms 39908 KB Output is correct
5 Correct 15 ms 39772 KB Output is correct
6 Correct 15 ms 39772 KB Output is correct
7 Correct 16 ms 39744 KB Output is correct
8 Correct 14 ms 39816 KB Output is correct
9 Correct 18 ms 39772 KB Output is correct
10 Correct 16 ms 39772 KB Output is correct
11 Correct 17 ms 39792 KB Output is correct
12 Correct 14 ms 39768 KB Output is correct
13 Correct 19 ms 39768 KB Output is correct
14 Correct 17 ms 39772 KB Output is correct
15 Correct 14 ms 39968 KB Output is correct
16 Correct 18 ms 39904 KB Output is correct
17 Correct 21 ms 39772 KB Output is correct
18 Correct 15 ms 39792 KB Output is correct
19 Correct 18 ms 39952 KB Output is correct
20 Correct 20 ms 39768 KB Output is correct
21 Correct 20 ms 40028 KB Output is correct
22 Correct 19 ms 39764 KB Output is correct
23 Correct 16 ms 39772 KB Output is correct
24 Correct 22 ms 39768 KB Output is correct
25 Correct 21 ms 39772 KB Output is correct
26 Correct 16 ms 39772 KB Output is correct
27 Correct 19 ms 39932 KB Output is correct
28 Correct 18 ms 39768 KB Output is correct
29 Correct 17 ms 39768 KB Output is correct
30 Correct 20 ms 39772 KB Output is correct
31 Correct 18 ms 39772 KB Output is correct
32 Correct 18 ms 39768 KB Output is correct
33 Correct 17 ms 39772 KB Output is correct
34 Correct 18 ms 39884 KB Output is correct
35 Correct 16 ms 39772 KB Output is correct
36 Correct 17 ms 39916 KB Output is correct
37 Correct 19 ms 39828 KB Output is correct
38 Correct 20 ms 39888 KB Output is correct
39 Correct 15 ms 39772 KB Output is correct
40 Correct 14 ms 39832 KB Output is correct
41 Correct 19 ms 39772 KB Output is correct
42 Correct 15 ms 39976 KB Output is correct
43 Correct 21 ms 39808 KB Output is correct
44 Correct 19 ms 39768 KB Output is correct
45 Correct 19 ms 39772 KB Output is correct
46 Correct 18 ms 39772 KB Output is correct
47 Correct 18 ms 39768 KB Output is correct
48 Correct 14 ms 39768 KB Output is correct
49 Correct 20 ms 40024 KB Output is correct
50 Correct 20 ms 40028 KB Output is correct
51 Correct 18 ms 40028 KB Output is correct
52 Correct 21 ms 40028 KB Output is correct
53 Correct 25 ms 39976 KB Output is correct
54 Correct 19 ms 40204 KB Output is correct
55 Correct 16 ms 40236 KB Output is correct
56 Correct 19 ms 40000 KB Output is correct
57 Correct 17 ms 40044 KB Output is correct
58 Correct 20 ms 40180 KB Output is correct
59 Correct 18 ms 40028 KB Output is correct
60 Correct 21 ms 40028 KB Output is correct
61 Correct 19 ms 40028 KB Output is correct
62 Correct 18 ms 40280 KB Output is correct
63 Correct 19 ms 40284 KB Output is correct
64 Correct 28 ms 40328 KB Output is correct
65 Correct 24 ms 39996 KB Output is correct
66 Correct 19 ms 40024 KB Output is correct
67 Correct 26 ms 40088 KB Output is correct
68 Correct 25 ms 39976 KB Output is correct
69 Correct 22 ms 40028 KB Output is correct
70 Correct 29 ms 40028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 39756 KB Output is correct
2 Correct 15 ms 39772 KB Output is correct
3 Correct 20 ms 39980 KB Output is correct
4 Correct 19 ms 39780 KB Output is correct
5 Correct 20 ms 39772 KB Output is correct
6 Correct 21 ms 39832 KB Output is correct
7 Correct 17 ms 39772 KB Output is correct
8 Correct 19 ms 39856 KB Output is correct
9 Correct 23 ms 39760 KB Output is correct
10 Correct 19 ms 40028 KB Output is correct
11 Correct 23 ms 40220 KB Output is correct
12 Correct 23 ms 40008 KB Output is correct
13 Correct 24 ms 40116 KB Output is correct
14 Correct 127 ms 54360 KB Output is correct
15 Correct 117 ms 54212 KB Output is correct
16 Correct 114 ms 54216 KB Output is correct
17 Correct 126 ms 54216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 39768 KB Output is correct
2 Correct 18 ms 39772 KB Output is correct
3 Correct 15 ms 39772 KB Output is correct
4 Correct 15 ms 39908 KB Output is correct
5 Correct 15 ms 39772 KB Output is correct
6 Correct 15 ms 39772 KB Output is correct
7 Correct 16 ms 39744 KB Output is correct
8 Correct 14 ms 39816 KB Output is correct
9 Correct 18 ms 39772 KB Output is correct
10 Correct 16 ms 39772 KB Output is correct
11 Correct 17 ms 39792 KB Output is correct
12 Correct 14 ms 39768 KB Output is correct
13 Correct 19 ms 39768 KB Output is correct
14 Correct 17 ms 39772 KB Output is correct
15 Correct 14 ms 39968 KB Output is correct
16 Correct 18 ms 39904 KB Output is correct
17 Correct 21 ms 39772 KB Output is correct
18 Correct 15 ms 39792 KB Output is correct
19 Correct 18 ms 39952 KB Output is correct
20 Correct 20 ms 39768 KB Output is correct
21 Correct 20 ms 40028 KB Output is correct
22 Correct 19 ms 39764 KB Output is correct
23 Correct 16 ms 39772 KB Output is correct
24 Correct 22 ms 39768 KB Output is correct
25 Correct 21 ms 39772 KB Output is correct
26 Correct 16 ms 39772 KB Output is correct
27 Correct 19 ms 39932 KB Output is correct
28 Correct 18 ms 39768 KB Output is correct
29 Correct 17 ms 39768 KB Output is correct
30 Correct 20 ms 39772 KB Output is correct
31 Correct 18 ms 39772 KB Output is correct
32 Correct 18 ms 39768 KB Output is correct
33 Correct 17 ms 39772 KB Output is correct
34 Correct 18 ms 39884 KB Output is correct
35 Correct 16 ms 39772 KB Output is correct
36 Correct 17 ms 39916 KB Output is correct
37 Correct 19 ms 39828 KB Output is correct
38 Correct 20 ms 39888 KB Output is correct
39 Correct 15 ms 39772 KB Output is correct
40 Correct 14 ms 39832 KB Output is correct
41 Correct 19 ms 39772 KB Output is correct
42 Correct 15 ms 39976 KB Output is correct
43 Correct 21 ms 39808 KB Output is correct
44 Correct 19 ms 39768 KB Output is correct
45 Correct 19 ms 39772 KB Output is correct
46 Correct 18 ms 39772 KB Output is correct
47 Correct 18 ms 39768 KB Output is correct
48 Correct 14 ms 39768 KB Output is correct
49 Correct 20 ms 40024 KB Output is correct
50 Correct 20 ms 40028 KB Output is correct
51 Correct 18 ms 40028 KB Output is correct
52 Correct 21 ms 40028 KB Output is correct
53 Correct 25 ms 39976 KB Output is correct
54 Correct 19 ms 40204 KB Output is correct
55 Correct 16 ms 40236 KB Output is correct
56 Correct 19 ms 40000 KB Output is correct
57 Correct 17 ms 40044 KB Output is correct
58 Correct 20 ms 40180 KB Output is correct
59 Correct 18 ms 40028 KB Output is correct
60 Correct 21 ms 40028 KB Output is correct
61 Correct 19 ms 40028 KB Output is correct
62 Correct 18 ms 40280 KB Output is correct
63 Correct 19 ms 40284 KB Output is correct
64 Correct 28 ms 40328 KB Output is correct
65 Correct 24 ms 39996 KB Output is correct
66 Correct 19 ms 40024 KB Output is correct
67 Correct 26 ms 40088 KB Output is correct
68 Correct 25 ms 39976 KB Output is correct
69 Correct 22 ms 40028 KB Output is correct
70 Correct 29 ms 40028 KB Output is correct
71 Correct 18 ms 39756 KB Output is correct
72 Correct 15 ms 39772 KB Output is correct
73 Correct 20 ms 39980 KB Output is correct
74 Correct 19 ms 39780 KB Output is correct
75 Correct 20 ms 39772 KB Output is correct
76 Correct 21 ms 39832 KB Output is correct
77 Correct 17 ms 39772 KB Output is correct
78 Correct 19 ms 39856 KB Output is correct
79 Correct 23 ms 39760 KB Output is correct
80 Correct 19 ms 40028 KB Output is correct
81 Correct 23 ms 40220 KB Output is correct
82 Correct 23 ms 40008 KB Output is correct
83 Correct 24 ms 40116 KB Output is correct
84 Correct 127 ms 54360 KB Output is correct
85 Correct 117 ms 54212 KB Output is correct
86 Correct 114 ms 54216 KB Output is correct
87 Correct 126 ms 54216 KB Output is correct
88 Correct 437 ms 58236 KB Output is correct
89 Correct 436 ms 67892 KB Output is correct
90 Correct 158 ms 56448 KB Output is correct
91 Correct 210 ms 64216 KB Output is correct
92 Correct 151 ms 56320 KB Output is correct
93 Correct 152 ms 56512 KB Output is correct
94 Correct 206 ms 64192 KB Output is correct
95 Correct 136 ms 50736 KB Output is correct
96 Correct 679 ms 56620 KB Output is correct
97 Correct 624 ms 56452 KB Output is correct