Submission #967995

# Submission time Handle Problem Language Result Execution time Memory
967995 2024-04-23T06:41:02 Z LittleOrange Real Mountains (CCO23_day1problem2) C++17
10 / 25
1882 ms 61548 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e6+3;
const ll big = 1e18;
struct obj{
    ll i,h;
    bool operator<(const obj &o) const{
        return h<o.h;
    }
};
struct segtree{
    ll n;
    vector<obj> a;
    segtree(ll N):n(N),a(N<<2){}
    void set(ll i, ll l, ll r, ll x, ll o){
        if (l==r) a[i] = {l,o};
        else{
            ll m = l+r>>1;
            if (x<=m) set(i<<1,l,m,x,o);
            else set(i<<1|1,m+1,r,x,o);
            a[i] = min(a[i<<1],a[i<<1|1]);
        }
    }
    void set(ll x, ll o){
        set(1,0,n-1,x,o);
    }
    obj get(ll i, ll l, ll r, ll ql, ll qr){
        if (ql<=l&&r<=qr) return a[i];
        ll m = l+r>>1;
        if (qr<=m) return get(i<<1,l,m,ql,qr);
        if (ql>m) return get(i<<1|1,m+1,r,ql,qr);
        return min(get(i<<1,l,m,ql,qr),get(i<<1|1,m+1,r,ql,qr));
    }
    obj get(ll ql, ll qr){
        return get(1,0,n-1,ql,qr);
    }
};
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll &i : a) cin >> i;
    vector<ll> b = a;
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());
    ll ans = 0;
    vector<ll> l = a;
    vector<ll> r = a;
    for(ll i = 1;i<n;i++) l[i] = max(l[i],l[i-1]);
    for(ll i = n-2;i>=0;i--) r[i] = max(r[i],r[i+1]);
    for(ll j = 0;j<b.size()-1;j++){
        ll de = b[j+1]-b[j];
        vector<ll> v;
        for(ll i = 0;i<n;i++){
            if (a[i]<=b[j]&&l[i]>b[j]&&r[i]>b[j]) v.push_back(i);
        }
        if(v.empty()) break;
        //cout << b[j] << ":";
        //for(ll i : v) cout << " " << i;
        //cout << "\n";
        vector<ll> L(n,big),R(n,big);
        for(ll i = 0;i<n;i++) if(a[i]>b[j]) L[i] = R[i] = a[i];
        for(ll i = 1;i<n;i++) L[i] = min(L[i],L[i-1]);
        for(ll i = n-2;i>=0;i--) R[i] = min(R[i],R[i+1]);
        //for(ll i = 0;i<n;i++) cout << L[i] << " \n"[i+1==n];
        //for(ll i = 0;i<n;i++) cout << R[i] << " \n"[i+1==n];
        de%=mod;
        if (v.size()==1){
            ll i = v[0];
            ans += (L[i]+R[i]+b[j])*de%mod+(de*(de-1)/2)%mod;
        }else{
            ll base = L[v.front()]+R[v.back()]+min(R[v.front()],L[v.back()]);
            ll cnt = v.size()*2-3;
            ll cnt0 = v.size();
            //cout << base << " " << cnt << " " << de << "\n";
            ans += base*de%mod+cnt*(b[j]*de%mod+de*(de+1)/2%mod)%mod+cnt0*(b[j]*de%mod+de*(de-1)/2%mod)%mod;
        }
        ans%=mod;
    }
    cout << ans%mod << "\n";
}

Compilation message

Main.cpp: In member function 'void segtree::set(ll, ll, ll, ll, ll)':
Main.cpp:19:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |             ll m = l+r>>1;
      |                    ~^~
Main.cpp: In member function 'obj segtree::get(ll, ll, ll, ll, ll)':
Main.cpp:30:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |         ll m = l+r>>1;
      |                ~^~
Main.cpp: In function 'int main()':
Main.cpp:53:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(ll j = 0;j<b.size()-1;j++){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 324 ms 756 KB Output is correct
36 Correct 318 ms 748 KB Output is correct
37 Correct 326 ms 752 KB Output is correct
38 Correct 326 ms 752 KB Output is correct
39 Correct 325 ms 992 KB Output is correct
40 Correct 2 ms 968 KB Output is correct
41 Correct 1 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 260 ms 756 KB Output is correct
44 Correct 276 ms 916 KB Output is correct
45 Correct 262 ms 752 KB Output is correct
46 Incorrect 1 ms 604 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 324 ms 756 KB Output is correct
36 Correct 318 ms 748 KB Output is correct
37 Correct 326 ms 752 KB Output is correct
38 Correct 326 ms 752 KB Output is correct
39 Correct 325 ms 992 KB Output is correct
40 Correct 2 ms 968 KB Output is correct
41 Correct 1 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 260 ms 756 KB Output is correct
44 Correct 276 ms 916 KB Output is correct
45 Correct 262 ms 752 KB Output is correct
46 Incorrect 1 ms 604 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1882 ms 56132 KB Output is correct
36 Correct 1840 ms 57584 KB Output is correct
37 Correct 1824 ms 55668 KB Output is correct
38 Correct 1821 ms 61548 KB Output is correct
39 Correct 1873 ms 55912 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 254 ms 55524 KB Output is correct
43 Correct 254 ms 55528 KB Output is correct
44 Correct 265 ms 55456 KB Output is correct
45 Correct 1423 ms 55660 KB Output is correct
46 Correct 1395 ms 55608 KB Output is correct
47 Correct 1382 ms 55528 KB Output is correct
48 Correct 1562 ms 56076 KB Output is correct
49 Correct 1564 ms 55584 KB Output is correct
50 Correct 1585 ms 55836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 324 ms 756 KB Output is correct
36 Correct 318 ms 748 KB Output is correct
37 Correct 326 ms 752 KB Output is correct
38 Correct 326 ms 752 KB Output is correct
39 Correct 325 ms 992 KB Output is correct
40 Correct 2 ms 968 KB Output is correct
41 Correct 1 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 260 ms 756 KB Output is correct
44 Correct 276 ms 916 KB Output is correct
45 Correct 262 ms 752 KB Output is correct
46 Incorrect 1 ms 604 KB Output isn't correct
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 428 KB Output is correct
4 Correct 6 ms 776 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 6 ms 772 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 8 ms 772 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 8 ms 772 KB Output is correct
17 Correct 8 ms 780 KB Output is correct
18 Correct 8 ms 748 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 1 ms 776 KB Output is correct
21 Correct 2 ms 776 KB Output is correct
22 Correct 1 ms 740 KB Output is correct
23 Correct 6 ms 776 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 6 ms 764 KB Output is correct
26 Correct 6 ms 752 KB Output is correct
27 Correct 6 ms 764 KB Output is correct
28 Correct 6 ms 764 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 324 ms 756 KB Output is correct
36 Correct 318 ms 748 KB Output is correct
37 Correct 326 ms 752 KB Output is correct
38 Correct 326 ms 752 KB Output is correct
39 Correct 325 ms 992 KB Output is correct
40 Correct 2 ms 968 KB Output is correct
41 Correct 1 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 260 ms 756 KB Output is correct
44 Correct 276 ms 916 KB Output is correct
45 Correct 262 ms 752 KB Output is correct
46 Incorrect 1 ms 604 KB Output isn't correct
47 Halted 0 ms 0 KB -