Submission #1020151

# Submission time Handle Problem Language Result Execution time Memory
1020151 2024-07-11T15:55:10 Z bachhoangxuan Flooding Wall (BOI24_wall) C++17
100 / 100
1706 ms 131744 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const long long inf=1e18;
const int mod=1e9+7;
const int maxn=500005;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

int c[maxn];

struct node{
    int ls=0,lt=0,rs=0,rt=0,val=1,ss=1;
    node(){}
    friend node operator+(node a,node b){
        node res;
        res.ls=(a.ls*b.ss+a.val*b.ls)%mod;
        res.lt=(a.lt*b.ss+a.val*b.lt)%mod;
        res.rs=(b.rs*a.ss+b.val*a.rs)%mod;
        res.rt=(b.rt*a.ss+b.val*a.rt)%mod;
        res.val=(a.val*b.val)%mod;
        res.ss=(a.ss*b.ss)%mod;
        return res;
    }
}tree[4*maxn];

void build(int l,int r,int id){
    if(l==r){
        tree[id].ss=2;
        tree[id].val=c[l];
        tree[id].ls=tree[id].rs=(2-c[l]);
        tree[id].lt=tree[id].rt=(2-c[l])*l;
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,id<<1);build(mid+1,r,id<<1|1);
    tree[id]=tree[id<<1]+tree[id<<1|1];
}
void update(int l,int r,int id,int p){
    if(l==r){
        tree[id].val=c[l];
        tree[id].ls=tree[id].rs=(2-c[l]);
        tree[id].lt=tree[id].rt=(2-c[l])*l;
        return;
    }
    int mid=(l+r)>>1;
    if(p<=mid) update(l,mid,id<<1,p);
    else update(mid+1,r,id<<1|1,p);
    tree[id]=tree[id<<1]+tree[id<<1|1];
}
node query(int l,int r,int id,int tl,int tr){
    if(tr<l || r<tl) return node();
    if(tl<=l && r<=tr) return tree[id];
    int mid=(l+r)>>1;
    return query(l,mid,id<<1,tl,tr)+query(mid+1,r,id<<1|1,tl,tr);
}

int n,a[2][maxn];
vector<pii> p;

void solve(){
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[0][i];
    for(int i=1;i<=n;i++) cin >> a[1][i];
    for(int i=1;i<=n;i++){
        p.push_back({a[0][i],i});
        p.push_back({a[1][i],i});
    }
    sort(p.begin(),p.end());
    build(1,n,1);
    int res=0,mul=power(2,n-1);
    for(auto [x,i]:p){
        node L=(i>1?query(1,n,1,1,i-1):node());
        node R=(i<n?query(1,n,1,i+1,n):node());
        int num=0;
        num=(num+(R.lt-R.rs*i%mod+mod)*L.val%mod)%mod;
        num=(num+(L.rs*i%mod-L.rt+mod)*R.val%mod)%mod;
        num=(num+L.val*R.val)%mod;
        //cout << x << ' ' << i << ' ' << num << ' ' << L.val << ' ' << R.val << ' ' << R.lt << ' ' << R.rs << '\n';
        res=(res+x*(num-mul)%mod+mod)%mod;
        c[i]++;
        update(1,n,1,i);
    }
    cout << res << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 94300 KB Output is correct
2 Correct 34 ms 94372 KB Output is correct
3 Correct 36 ms 94292 KB Output is correct
4 Correct 35 ms 94288 KB Output is correct
5 Correct 36 ms 94316 KB Output is correct
6 Correct 36 ms 94300 KB Output is correct
7 Correct 35 ms 94292 KB Output is correct
8 Correct 34 ms 94288 KB Output is correct
9 Correct 34 ms 94288 KB Output is correct
10 Correct 33 ms 94300 KB Output is correct
11 Correct 34 ms 94300 KB Output is correct
12 Correct 34 ms 94292 KB Output is correct
13 Correct 36 ms 94388 KB Output is correct
14 Correct 33 ms 94296 KB Output is correct
15 Correct 34 ms 94292 KB Output is correct
16 Correct 35 ms 94300 KB Output is correct
17 Correct 35 ms 94292 KB Output is correct
18 Correct 42 ms 94268 KB Output is correct
19 Correct 34 ms 94300 KB Output is correct
20 Correct 34 ms 94320 KB Output is correct
21 Correct 32 ms 94312 KB Output is correct
22 Correct 36 ms 94288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 94288 KB Output is correct
2 Correct 35 ms 94288 KB Output is correct
3 Correct 33 ms 94256 KB Output is correct
4 Correct 35 ms 94360 KB Output is correct
5 Correct 34 ms 94300 KB Output is correct
6 Correct 34 ms 94292 KB Output is correct
7 Correct 33 ms 94300 KB Output is correct
8 Correct 34 ms 94296 KB Output is correct
9 Correct 37 ms 94292 KB Output is correct
10 Correct 35 ms 94288 KB Output is correct
11 Correct 34 ms 94300 KB Output is correct
12 Correct 34 ms 94292 KB Output is correct
13 Correct 33 ms 94288 KB Output is correct
14 Correct 36 ms 94288 KB Output is correct
15 Correct 34 ms 94288 KB Output is correct
16 Correct 34 ms 94300 KB Output is correct
17 Correct 34 ms 94292 KB Output is correct
18 Correct 34 ms 94300 KB Output is correct
19 Correct 47 ms 94292 KB Output is correct
20 Correct 38 ms 94296 KB Output is correct
21 Correct 36 ms 94304 KB Output is correct
22 Correct 36 ms 94296 KB Output is correct
23 Correct 37 ms 94404 KB Output is correct
24 Correct 35 ms 94292 KB Output is correct
25 Correct 37 ms 94292 KB Output is correct
26 Correct 35 ms 94292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 94288 KB Output is correct
2 Correct 35 ms 94288 KB Output is correct
3 Correct 33 ms 94256 KB Output is correct
4 Correct 35 ms 94360 KB Output is correct
5 Correct 34 ms 94300 KB Output is correct
6 Correct 34 ms 94292 KB Output is correct
7 Correct 33 ms 94300 KB Output is correct
8 Correct 34 ms 94296 KB Output is correct
9 Correct 37 ms 94292 KB Output is correct
10 Correct 35 ms 94288 KB Output is correct
11 Correct 34 ms 94300 KB Output is correct
12 Correct 34 ms 94292 KB Output is correct
13 Correct 33 ms 94288 KB Output is correct
14 Correct 36 ms 94288 KB Output is correct
15 Correct 34 ms 94288 KB Output is correct
16 Correct 34 ms 94300 KB Output is correct
17 Correct 34 ms 94292 KB Output is correct
18 Correct 34 ms 94300 KB Output is correct
19 Correct 47 ms 94292 KB Output is correct
20 Correct 38 ms 94296 KB Output is correct
21 Correct 36 ms 94304 KB Output is correct
22 Correct 36 ms 94296 KB Output is correct
23 Correct 37 ms 94404 KB Output is correct
24 Correct 35 ms 94292 KB Output is correct
25 Correct 37 ms 94292 KB Output is correct
26 Correct 35 ms 94292 KB Output is correct
27 Correct 55 ms 95072 KB Output is correct
28 Correct 55 ms 95200 KB Output is correct
29 Correct 57 ms 95236 KB Output is correct
30 Correct 53 ms 95184 KB Output is correct
31 Correct 52 ms 95192 KB Output is correct
32 Correct 54 ms 95188 KB Output is correct
33 Correct 51 ms 95192 KB Output is correct
34 Correct 53 ms 95192 KB Output is correct
35 Correct 53 ms 95188 KB Output is correct
36 Correct 53 ms 95192 KB Output is correct
37 Correct 53 ms 95136 KB Output is correct
38 Correct 52 ms 95188 KB Output is correct
39 Correct 54 ms 95196 KB Output is correct
40 Correct 53 ms 95188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 94300 KB Output is correct
2 Correct 34 ms 94372 KB Output is correct
3 Correct 36 ms 94292 KB Output is correct
4 Correct 35 ms 94288 KB Output is correct
5 Correct 36 ms 94316 KB Output is correct
6 Correct 36 ms 94300 KB Output is correct
7 Correct 35 ms 94292 KB Output is correct
8 Correct 34 ms 94288 KB Output is correct
9 Correct 34 ms 94288 KB Output is correct
10 Correct 33 ms 94300 KB Output is correct
11 Correct 34 ms 94300 KB Output is correct
12 Correct 34 ms 94292 KB Output is correct
13 Correct 36 ms 94388 KB Output is correct
14 Correct 33 ms 94296 KB Output is correct
15 Correct 34 ms 94292 KB Output is correct
16 Correct 35 ms 94300 KB Output is correct
17 Correct 35 ms 94292 KB Output is correct
18 Correct 42 ms 94268 KB Output is correct
19 Correct 34 ms 94300 KB Output is correct
20 Correct 34 ms 94320 KB Output is correct
21 Correct 32 ms 94312 KB Output is correct
22 Correct 36 ms 94288 KB Output is correct
23 Correct 34 ms 94288 KB Output is correct
24 Correct 35 ms 94288 KB Output is correct
25 Correct 33 ms 94256 KB Output is correct
26 Correct 35 ms 94360 KB Output is correct
27 Correct 34 ms 94300 KB Output is correct
28 Correct 34 ms 94292 KB Output is correct
29 Correct 33 ms 94300 KB Output is correct
30 Correct 34 ms 94296 KB Output is correct
31 Correct 37 ms 94292 KB Output is correct
32 Correct 35 ms 94288 KB Output is correct
33 Correct 34 ms 94300 KB Output is correct
34 Correct 34 ms 94292 KB Output is correct
35 Correct 33 ms 94288 KB Output is correct
36 Correct 36 ms 94288 KB Output is correct
37 Correct 34 ms 94288 KB Output is correct
38 Correct 34 ms 94300 KB Output is correct
39 Correct 34 ms 94292 KB Output is correct
40 Correct 34 ms 94300 KB Output is correct
41 Correct 47 ms 94292 KB Output is correct
42 Correct 38 ms 94296 KB Output is correct
43 Correct 36 ms 94304 KB Output is correct
44 Correct 36 ms 94296 KB Output is correct
45 Correct 37 ms 94404 KB Output is correct
46 Correct 35 ms 94292 KB Output is correct
47 Correct 37 ms 94292 KB Output is correct
48 Correct 35 ms 94292 KB Output is correct
49 Correct 55 ms 95072 KB Output is correct
50 Correct 55 ms 95200 KB Output is correct
51 Correct 57 ms 95236 KB Output is correct
52 Correct 53 ms 95184 KB Output is correct
53 Correct 52 ms 95192 KB Output is correct
54 Correct 54 ms 95188 KB Output is correct
55 Correct 51 ms 95192 KB Output is correct
56 Correct 53 ms 95192 KB Output is correct
57 Correct 53 ms 95188 KB Output is correct
58 Correct 53 ms 95192 KB Output is correct
59 Correct 53 ms 95136 KB Output is correct
60 Correct 52 ms 95188 KB Output is correct
61 Correct 54 ms 95196 KB Output is correct
62 Correct 53 ms 95188 KB Output is correct
63 Correct 56 ms 95188 KB Output is correct
64 Correct 58 ms 95196 KB Output is correct
65 Correct 53 ms 95192 KB Output is correct
66 Correct 54 ms 95192 KB Output is correct
67 Correct 55 ms 95292 KB Output is correct
68 Correct 52 ms 95188 KB Output is correct
69 Correct 54 ms 95192 KB Output is correct
70 Correct 55 ms 95192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 94384 KB Output is correct
2 Correct 35 ms 94288 KB Output is correct
3 Correct 38 ms 94292 KB Output is correct
4 Correct 36 ms 94292 KB Output is correct
5 Correct 36 ms 94292 KB Output is correct
6 Correct 37 ms 94300 KB Output is correct
7 Correct 35 ms 94296 KB Output is correct
8 Correct 35 ms 94300 KB Output is correct
9 Correct 33 ms 94300 KB Output is correct
10 Correct 50 ms 95084 KB Output is correct
11 Correct 52 ms 95196 KB Output is correct
12 Correct 53 ms 95456 KB Output is correct
13 Correct 53 ms 95084 KB Output is correct
14 Correct 1093 ms 123808 KB Output is correct
15 Correct 1095 ms 123644 KB Output is correct
16 Correct 1109 ms 123672 KB Output is correct
17 Correct 1109 ms 123808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 94300 KB Output is correct
2 Correct 34 ms 94372 KB Output is correct
3 Correct 36 ms 94292 KB Output is correct
4 Correct 35 ms 94288 KB Output is correct
5 Correct 36 ms 94316 KB Output is correct
6 Correct 36 ms 94300 KB Output is correct
7 Correct 35 ms 94292 KB Output is correct
8 Correct 34 ms 94288 KB Output is correct
9 Correct 34 ms 94288 KB Output is correct
10 Correct 33 ms 94300 KB Output is correct
11 Correct 34 ms 94300 KB Output is correct
12 Correct 34 ms 94292 KB Output is correct
13 Correct 36 ms 94388 KB Output is correct
14 Correct 33 ms 94296 KB Output is correct
15 Correct 34 ms 94292 KB Output is correct
16 Correct 35 ms 94300 KB Output is correct
17 Correct 35 ms 94292 KB Output is correct
18 Correct 42 ms 94268 KB Output is correct
19 Correct 34 ms 94300 KB Output is correct
20 Correct 34 ms 94320 KB Output is correct
21 Correct 32 ms 94312 KB Output is correct
22 Correct 36 ms 94288 KB Output is correct
23 Correct 34 ms 94288 KB Output is correct
24 Correct 35 ms 94288 KB Output is correct
25 Correct 33 ms 94256 KB Output is correct
26 Correct 35 ms 94360 KB Output is correct
27 Correct 34 ms 94300 KB Output is correct
28 Correct 34 ms 94292 KB Output is correct
29 Correct 33 ms 94300 KB Output is correct
30 Correct 34 ms 94296 KB Output is correct
31 Correct 37 ms 94292 KB Output is correct
32 Correct 35 ms 94288 KB Output is correct
33 Correct 34 ms 94300 KB Output is correct
34 Correct 34 ms 94292 KB Output is correct
35 Correct 33 ms 94288 KB Output is correct
36 Correct 36 ms 94288 KB Output is correct
37 Correct 34 ms 94288 KB Output is correct
38 Correct 34 ms 94300 KB Output is correct
39 Correct 34 ms 94292 KB Output is correct
40 Correct 34 ms 94300 KB Output is correct
41 Correct 47 ms 94292 KB Output is correct
42 Correct 38 ms 94296 KB Output is correct
43 Correct 36 ms 94304 KB Output is correct
44 Correct 36 ms 94296 KB Output is correct
45 Correct 37 ms 94404 KB Output is correct
46 Correct 35 ms 94292 KB Output is correct
47 Correct 37 ms 94292 KB Output is correct
48 Correct 35 ms 94292 KB Output is correct
49 Correct 55 ms 95072 KB Output is correct
50 Correct 55 ms 95200 KB Output is correct
51 Correct 57 ms 95236 KB Output is correct
52 Correct 53 ms 95184 KB Output is correct
53 Correct 52 ms 95192 KB Output is correct
54 Correct 54 ms 95188 KB Output is correct
55 Correct 51 ms 95192 KB Output is correct
56 Correct 53 ms 95192 KB Output is correct
57 Correct 53 ms 95188 KB Output is correct
58 Correct 53 ms 95192 KB Output is correct
59 Correct 53 ms 95136 KB Output is correct
60 Correct 52 ms 95188 KB Output is correct
61 Correct 54 ms 95196 KB Output is correct
62 Correct 53 ms 95188 KB Output is correct
63 Correct 56 ms 95188 KB Output is correct
64 Correct 58 ms 95196 KB Output is correct
65 Correct 53 ms 95192 KB Output is correct
66 Correct 54 ms 95192 KB Output is correct
67 Correct 55 ms 95292 KB Output is correct
68 Correct 52 ms 95188 KB Output is correct
69 Correct 54 ms 95192 KB Output is correct
70 Correct 55 ms 95192 KB Output is correct
71 Correct 37 ms 94384 KB Output is correct
72 Correct 35 ms 94288 KB Output is correct
73 Correct 38 ms 94292 KB Output is correct
74 Correct 36 ms 94292 KB Output is correct
75 Correct 36 ms 94292 KB Output is correct
76 Correct 37 ms 94300 KB Output is correct
77 Correct 35 ms 94296 KB Output is correct
78 Correct 35 ms 94300 KB Output is correct
79 Correct 33 ms 94300 KB Output is correct
80 Correct 50 ms 95084 KB Output is correct
81 Correct 52 ms 95196 KB Output is correct
82 Correct 53 ms 95456 KB Output is correct
83 Correct 53 ms 95084 KB Output is correct
84 Correct 1093 ms 123808 KB Output is correct
85 Correct 1095 ms 123644 KB Output is correct
86 Correct 1109 ms 123672 KB Output is correct
87 Correct 1109 ms 123808 KB Output is correct
88 Correct 1694 ms 131436 KB Output is correct
89 Correct 1706 ms 131484 KB Output is correct
90 Correct 1180 ms 123920 KB Output is correct
91 Correct 1234 ms 131740 KB Output is correct
92 Correct 1190 ms 123812 KB Output is correct
93 Correct 1198 ms 123804 KB Output is correct
94 Correct 1220 ms 131744 KB Output is correct
95 Correct 1202 ms 123976 KB Output is correct
96 Correct 1219 ms 127648 KB Output is correct
97 Correct 1221 ms 127768 KB Output is correct