Submission #1295133


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

signed main() { 
        int n = lin();
        vi a(n);
        rep(i, n) a[i] = lin();
        set<int> s;
        s.insert(0);
        s.insert(n + 1);
        vi pos(n);
        rep(i, n) pos[a[i] - 1] = i + 1;
        int ans = 0;
        rep(i, n) {
                auto lb = s.lower_bound(pos[i]);
                int left = pos[i] - *(-- lb);
                int right = *(++ lb) - pos[i];
                ans += left * right * (i + 1);
                s.insert(pos[i]);
        }
        cout << ans << endl;
        return 0;
}               

Submission Info

Submission Time
Task B - Minimum Sum
User KokiYmgch
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2288 Byte
Status AC
Exec Time 123 ms
Memory 12800 KB

Compile Error

./Main.cpp: In function ‘long long int in()’:
./Main.cpp:35:35: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
 int in() { int _x; scanf("%d", &_x); return _x; }
                                   ^
./Main.cpp:35:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int in() { int _x; scanf("%d", &_x); return _x; }
                                    ^
./Main.cpp: In function ‘long long int lin()’:
./Main.cpp:36:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 long long lin() {long long _x; scanf("%lld", &_x); return _x; };
                                                  ^

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 121 ms 12800 KB
corner1 AC 123 ms 12800 KB
corner2 AC 1 ms 256 KB
corner3 AC 77 ms 12800 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 112 ms 12800 KB
maxrand1 AC 112 ms 12800 KB
maxrand2 AC 112 ms 12800 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB