답안 #968100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968100 2024-04-23T07:41:21 Z LittleOrange Real Mountains (CCO23_day1problem2) C++17
13 / 25
5000 ms 61892 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e6+3;
const ll big = 2e9;
struct l{
    ll x;
    l(const ll &x):x((x+mod)%mod){}
    l(const int &x):x((x+mod)%mod){}
    l operator+(const l& o) const{
        return l(x+o.x);
    }
    l operator-(const l& o) const{
        return l(x-o.x);
    }
    l operator*(const l& o) const{
        return l(x*o.x);
    }
    l operator+(const ll& o) const{
        return l(x+o);
    }
    l operator-(const ll& o) const{
        return l(x-o);
    }
    l operator*(const ll& o) const{
        return l(x*o);
    }
    l operator+(const int& o) const{
        return l(x+o);
    }
    l operator-(const int& o) const{
        return l(x-o);
    }
    l operator*(const int& o) const{
        return l(x*o);
    }
    operator ll() const{
        return x;
    }
};
const l rev2 = l(500002);
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll mxa = 0;
    for(ll &i : a) cin >> i,mxa = max(mxa,i);
    vector<ll> b = a;
    //for(ll i = 1;i<=mxa;i++) b.push_back(i);
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());
    l ans = 0;
    vector<ll> li = a;
    vector<ll> ri = a;
    for(ll i = 1;i<n;i++) li[i] = max(li[i],li[i-1]);
    for(ll i = n-2;i>=0;i--) ri[i] = max(ri[i],ri[i+1]);
    for(ll j = 0;j<b.size()-1;j++){
        l de = b[j+1]-b[j];
        vector<ll> v;
        for(ll i = 0;i<n;i++){
            if (a[i]<=b[j]&&li[i]>b[j]&&ri[i]>b[j]) v.push_back(i);
        }
        if(v.empty()) continue;
        //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];
        if (v.size()==1){
            ll i = v[0];
            ans = ans+l(L[i]+R[i]+b[j])*de+de*(de-1)*rev2;
        }else{
            l base = (L[v.front()]+R[v.back()]+min(R[v.front()],L[v.back()]));
            l cnt0 = (ll)v.size();
            l cnt = (cnt0*2-3);
            //cout << base << " " << cnt << " " << de << "\n";
            ans = ans+base*de+cnt*(b[j]*de+de*(de+1)*rev2)+cnt0*(b[j]*de+de*(de-1)*rev2);
        }
    }
    cout << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:58: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]
   58 |     for(ll j = 0;j<b.size()-1;j++){
      |                  ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 340 ms 988 KB Output is correct
36 Correct 339 ms 752 KB Output is correct
37 Correct 337 ms 1048 KB Output is correct
38 Correct 332 ms 748 KB Output is correct
39 Correct 344 ms 944 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 2 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 274 ms 752 KB Output is correct
44 Correct 275 ms 1072 KB Output is correct
45 Correct 269 ms 752 KB Output is correct
46 Correct 289 ms 752 KB Output is correct
47 Correct 300 ms 748 KB Output is correct
48 Correct 301 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 340 ms 988 KB Output is correct
36 Correct 339 ms 752 KB Output is correct
37 Correct 337 ms 1048 KB Output is correct
38 Correct 332 ms 748 KB Output is correct
39 Correct 344 ms 944 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 2 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 274 ms 752 KB Output is correct
44 Correct 275 ms 1072 KB Output is correct
45 Correct 269 ms 752 KB Output is correct
46 Correct 289 ms 752 KB Output is correct
47 Correct 300 ms 748 KB Output is correct
48 Correct 301 ms 752 KB Output is correct
49 Incorrect 343 ms 1248 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1917 ms 57528 KB Output is correct
36 Correct 1909 ms 61672 KB Output is correct
37 Correct 1920 ms 55644 KB Output is correct
38 Correct 1885 ms 55548 KB Output is correct
39 Correct 1969 ms 55548 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 263 ms 55592 KB Output is correct
43 Correct 280 ms 55656 KB Output is correct
44 Correct 296 ms 55584 KB Output is correct
45 Correct 1472 ms 57416 KB Output is correct
46 Correct 1518 ms 56052 KB Output is correct
47 Correct 1456 ms 55644 KB Output is correct
48 Correct 1594 ms 55636 KB Output is correct
49 Correct 1613 ms 55800 KB Output is correct
50 Correct 1547 ms 61892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 340 ms 988 KB Output is correct
36 Correct 339 ms 752 KB Output is correct
37 Correct 337 ms 1048 KB Output is correct
38 Correct 332 ms 748 KB Output is correct
39 Correct 344 ms 944 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 2 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 274 ms 752 KB Output is correct
44 Correct 275 ms 1072 KB Output is correct
45 Correct 269 ms 752 KB Output is correct
46 Correct 289 ms 752 KB Output is correct
47 Correct 300 ms 748 KB Output is correct
48 Correct 301 ms 752 KB Output is correct
49 Correct 1917 ms 57528 KB Output is correct
50 Correct 1909 ms 61672 KB Output is correct
51 Correct 1920 ms 55644 KB Output is correct
52 Correct 1885 ms 55548 KB Output is correct
53 Correct 1969 ms 55548 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 263 ms 55592 KB Output is correct
57 Correct 280 ms 55656 KB Output is correct
58 Correct 296 ms 55584 KB Output is correct
59 Correct 1472 ms 57416 KB Output is correct
60 Correct 1518 ms 56052 KB Output is correct
61 Correct 1456 ms 55644 KB Output is correct
62 Correct 1594 ms 55636 KB Output is correct
63 Correct 1613 ms 55800 KB Output is correct
64 Correct 1547 ms 61892 KB Output is correct
65 Execution timed out 5046 ms 48068 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 6 ms 772 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 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 2 ms 604 KB Output is correct
11 Correct 6 ms 764 KB Output is correct
12 Correct 6 ms 776 KB Output is correct
13 Correct 9 ms 768 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 780 KB Output is correct
17 Correct 8 ms 764 KB Output is correct
18 Correct 8 ms 780 KB Output is correct
19 Correct 8 ms 764 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 772 KB Output is correct
22 Correct 2 ms 776 KB Output is correct
23 Correct 6 ms 760 KB Output is correct
24 Correct 6 ms 752 KB Output is correct
25 Correct 8 ms 944 KB Output is correct
26 Correct 6 ms 760 KB Output is correct
27 Correct 7 ms 772 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 340 ms 988 KB Output is correct
36 Correct 339 ms 752 KB Output is correct
37 Correct 337 ms 1048 KB Output is correct
38 Correct 332 ms 748 KB Output is correct
39 Correct 344 ms 944 KB Output is correct
40 Correct 2 ms 772 KB Output is correct
41 Correct 2 ms 776 KB Output is correct
42 Correct 1 ms 740 KB Output is correct
43 Correct 274 ms 752 KB Output is correct
44 Correct 275 ms 1072 KB Output is correct
45 Correct 269 ms 752 KB Output is correct
46 Correct 289 ms 752 KB Output is correct
47 Correct 300 ms 748 KB Output is correct
48 Correct 301 ms 752 KB Output is correct
49 Incorrect 343 ms 1248 KB Output isn't correct
50 Halted 0 ms 0 KB -