Submission #910910


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    scanf(" %d", &n);

    vector<int> a(n);
    vector<int> f(n+1);
    rep(i,n)
    {
        scanf(" %d", &a[i]);
        f[a[i]]=i;
    }

    set<int> ids;
    ids.insert(-1);
    ids.insert(n);

    ll ans=0;

    for(int i=1; i<=n; ++i)
    {
        auto l = ids.lower_bound(f[i]);
        auto r = ids.lower_bound(f[i]);
        --l;

        ans += (ll)(f[i] - *l)*(*r - f[i])*i;
        ids.insert(f[i]);
    }

    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User imulan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 825 Byte
Status AC
Exec Time 165 ms
Memory 11136 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:15:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d", &n);
                     ^
./Main.cpp:21:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %d", &a[i]);
                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 165 ms 11136 KB
corner1 AC 161 ms 11136 KB
corner2 AC 3 ms 256 KB
corner3 AC 101 ms 11136 KB
example0 AC 3 ms 256 KB
example1 AC 3 ms 256 KB
example2 AC 3 ms 256 KB
maxrand0 AC 137 ms 11136 KB
maxrand1 AC 136 ms 11136 KB
maxrand2 AC 138 ms 11136 KB
rand0 AC 3 ms 256 KB
rand1 AC 3 ms 256 KB
rand2 AC 3 ms 256 KB