Submission #1231013


Source Code Expand

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

pii pp[MAXN];

map<int, int> segs;

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n){
		scanf("%d", &pp[i]._1);
		pp[i]._2 = i;
	}
	sort(pp + 1, pp + n + 1);
	ll ans = 0ll;
	segs[n] = 1;
	REPN(i, 1, n){
		int ind = pp[i]._2;
		pii cur_seg = *segs.lower_bound(ind);
		ans += (ll)pp[i]._1 * (ll)(ind - cur_seg._2 + 1) * (ll)(cur_seg._1 - ind + 1);
		segs.erase(cur_seg._1);
		if (cur_seg._1 > ind){
			segs[cur_seg._1] = ind + 1;
		}
		if (ind > cur_seg._2){
			segs[ind - 1] = cur_seg._2;
		}
	}
	printf("%lld\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Submission Info

Submission Time
Task B - Minimum Sum
User Timur_Sitdikov
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1565 Byte
Status AC
Exec Time 137 ms
Memory 4096 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:42:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:44:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &pp[i]._1);
                         ^

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 35 ms 1792 KB
corner1 AC 34 ms 1792 KB
corner2 AC 1 ms 256 KB
corner3 AC 49 ms 1792 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 137 ms 4096 KB
maxrand1 AC 136 ms 4096 KB
maxrand2 AC 137 ms 4096 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB