Submission #1013398

# Submission time Handle Problem Language Result Execution time Memory
1013398 2024-07-03T13:54:38 Z BackNoob Real Mountains (CCO23_day1problem2) C++14
0 / 25
1 ms 2396 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e6 + 3;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
}

int n;
int a[mxN];
bool vis[mxN];
pair<int, int> seg[mxN];

int getsum(int l, int r) {
    if(l > r) return 0;
    return (1LL * (r + l) * (r - l + 1) / 2) % mod;
}
 
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int mx = -1;
    int p = -1;
    for(int i = n; i >= 1; i--) {
        if(maximize(mx, a[i]) == true) p = i;
    }

    int res = 0;
    int temp = -1;
    for(int i = 1; i <= p; i++) {
        maximize(temp, a[i]);
        res += getsum(a[i], temp - 1);
        seg[i] = {a[i], temp};
    }
    temp = -1;
    for(int i = n; i > p; i--) {
        maximize(temp, a[i]);
        res += getsum(a[i], temp - 1);
        seg[i] = {a[i], temp};
    }



    for(int i = 1; i <= n; i++) {
        int temp = -1;
        for(int j = 100; j >= 1; j--) {
            if(vis[j] == true) temp = j;
            if(seg[i].fi < j && j <= seg[i].se) {
                res += temp;
            }
        }
        for(int j = seg[i].fi; j <= seg[i].se; j++) vis[j] = true;
    }

    for(int j = 1; j <= 100; j++) vis[j] = false;
    for(int i = n; i >= 1; i--) {
        int temp = -1;
        for(int j = 100; j >= 1; j--) {
            if(vis[j] == true) temp = j;
            if(seg[i].fi < j && j <= seg[i].se) {
                res += temp;
            }
        }
        for(int j = seg[i].fi; j <= seg[i].se; j++) vis[j] = true;
    }


    cout << res;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen(TASK".inp" , "r" , stdin);
    // freopen(TASK".out" , "w" , stdout);
 
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -