Skip to content

Commit 5142074

Browse files
committed
Merge branch 'master' of https://github.com/fsq/codeforces
2 parents d69c865 + 7c9073d commit 5142074

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

1151.E. Number of Components.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <cstdio>
2+
#include <iostream>
3+
#include <cstring>
4+
#include <cmath>
5+
#include <ctime>
6+
#include <vector>
7+
#include <string>
8+
#include <algorithm>
9+
#include <map>
10+
#include <set>
11+
#include <unordered_map>
12+
#include <unordered_set>
13+
#include <queue>
14+
#include <deque>
15+
#include <stack>
16+
#include <numeric>
17+
#include <memory>
18+
#include <list>
19+
#include <climits>
20+
#include <fstream>
21+
#include <sstream>
22+
#include <random>
23+
#include <functional>
24+
25+
#define PB push_back
26+
#define F first
27+
#define S second
28+
29+
#define REP(i,from,to) for(auto i=(from); i<=(to); ++i)
30+
#define PER(i,from,to) for(auto i=(from); i>=(to); --i)
31+
#define REP_IF(i,from,to,assert) for(auto i=(from); i<=(to); ++i) if (assert)
32+
33+
#define FOR(i,less_than) for (auto i=0; i<(less_than); ++i)
34+
#define FORI(i, container) for (auto i=0; i<(container).size(); ++i)
35+
#define FORI_IF(i, container, assert) for (auto i=0; i<(container).size(); ++i) if (assert)
36+
#define ROFI(i, container) for (auto i=SZ(container)-1; i>=0; --i)
37+
#define FOREACH(elem, container) for (auto elem : (container))
38+
#define FOREACH_IF(elem, container, assert) for (auto elem : (container)) if (assert)
39+
40+
#define MEMSET(container, value) memset(container, value, sizeof(container))
41+
#define MEMSET0(container) memset(container, 0, sizeof(container))
42+
#define FILL(container, value) fill(container.begin(), container.end(), value)
43+
#define FILL0(container) fill(container.begin(), container.end(), 0)
44+
#define ALL(container) (container).begin(), (container).end()
45+
#define SZ(container) (int)((container).size())
46+
47+
#define BACK(set_map) *prev((set_map).end(), 1)
48+
#define FRONT(set_map) *(set_map).begin()
49+
50+
#define POP(var, container) auto var=(container.front()); container.pop();
51+
52+
using PII = std::pair<int,int>;
53+
using LL = long long;
54+
using VI = std::vector<int>;
55+
using CVI = const VI;
56+
using VLL = std::vector<LL>;
57+
using VVI = std::vector<VI>;
58+
using VVLL = std::vector<VLL>;
59+
60+
using namespace std;
61+
62+
int main() {
63+
ios::sync_with_stdio(false);
64+
int n;
65+
cin >> n;
66+
VLL a(n+1), f(n+1);
67+
a[0] = n + 1;
68+
REP(i, 1, n) {
69+
cin >> a[i];
70+
f[i] = f[i-1];
71+
if (a[i] > a[i-1])
72+
f[i] += (a[i]-a[i-1]) * (n-a[i]+1);
73+
else if (a[i] < a[i-1])
74+
f[i] += a[i] * (a[i-1]-a[i]);
75+
}
76+
cout << f[n] << endl;
77+
return 0;
78+
}

0 commit comments

Comments
 (0)