답안 #792441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792441 2023-07-25T04:56:54 Z GEN 이지후(#10086) Real Mountains (CCO23_day1problem2) C++17
13 / 25
5000 ms 29508 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using llf = long double;
const int mod = 1e6 + 3; // 1e9 + 7;//993244853;

// I don't remember the credit of modint, but it's not mine.
// I don't remember the credit of FFT, but it's probably mine.
// Polynomial library is due to adamant:
// https://github.com/cp-algorithms/cp-algorithms-aux/blob/master/src/polynomial.cpp
// To use polynomial sqrt, need to amend sqrt for modint.

struct mint {
	int val;
	mint() { val = 0; }
	mint(const lint &v) {
		val = (-mod <= v && v < mod) ? v : v % mod;
		if (val < 0)
			val += mod;
	}

	friend ostream &operator<<(ostream &os, const mint &a) { return os << a.val; }
	friend bool operator==(const mint &a, const mint &b) { return a.val == b.val; }
	friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
	friend bool operator<(const mint &a, const mint &b) { return a.val < b.val; }

	mint operator-() const { return mint(-val); }
	mint &operator+=(const mint &m) {
		if ((val += m.val) >= mod)
			val -= mod;
		return *this;
	}
	mint &operator-=(const mint &m) {
		if ((val -= m.val) < 0)
			val += mod;
		return *this;
	}
	mint &operator*=(const mint &m) {
		val = (lint)val * m.val % mod;
		return *this;
	}
	friend mint ipow(mint a, lint p) {
		mint ans = 1;
		for (; p; p /= 2, a *= a)
			if (p & 1)
				ans *= a;
		return ans;
	}
	mint inv() const { return ipow(*this, mod - 2); }
	mint &operator/=(const mint &m) { return (*this) *= m.inv(); }

	friend mint operator+(mint a, const mint &b) { return a += b; }
	friend mint operator-(mint a, const mint &b) { return a -= b; }
	friend mint operator*(mint a, const mint &b) { return a *= b; }
	friend mint operator/(mint a, const mint &b) { return a /= b; }
	operator int64_t() const { return val; }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> coords;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		coords.push_back(a[i]);
	}
	sort(all(coords));
	coords.resize(unique(all(coords)) - coords.begin());
	lint tot = 0;
	auto sum = [&](int l, int r) { return 1ll * (r - l + 1) * (r + l) / 2; };
	int l = 0, r = n;
	for (int i = 0; i < sz(coords) - 1; i++) {
		while (l < n && a[l] <= coords[i])
			l++;
		while (r > l && a[r - 1] <= coords[i])
			r--;
		vector<int> pos;
		vector<pi> mswp;
		int mx = 1e9;
		for (int j = l; j < r; j++) {
			if (a[j] <= coords[i]) {
				pos.push_back(j);
				mswp.push_back({mx, 0});
			} else
				mx = min(mx, a[j]);
		}
		if (sz(pos) == 0)
			continue;
		int ptr = sz(pos);
		mx = 1e9;
		for (int j = r - 1; j >= l; j--) {
			if (a[j] <= coords[i]) {
				mswp[--ptr][1] = mx;
			} else
				mx = min(mx, a[j]);
		}
		if (sz(pos) == 1) {
			tot += 1ll * (coords[i + 1] - coords[i]) * (mswp[0][0] + mswp[0][1]) + sum(coords[i], coords[i + 1] - 1);
			continue;
		}
		tot += sum(coords[i], coords[i + 1] - 1) * sz(pos);
		tot += sum(coords[i] + 1, coords[i + 1]) * (2 * sz(pos) - 2);
		tot += 1ll * mswp[0][0] * (coords[i + 1] - coords[i]);
		tot += 1ll * mswp.back()[1] * (coords[i + 1] - coords[i]);
		tot += 1ll * (coords[i + 1] - coords[i]) * min(mswp[0][1], mswp.back()[0]) - sum(coords[i] + 1, coords[i + 1]);
	}
	cout << tot % 1000003 << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 172 ms 484 KB Output is correct
36 Correct 171 ms 484 KB Output is correct
37 Correct 179 ms 488 KB Output is correct
38 Correct 172 ms 480 KB Output is correct
39 Correct 171 ms 480 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 164 ms 588 KB Output is correct
44 Correct 164 ms 516 KB Output is correct
45 Correct 169 ms 600 KB Output is correct
46 Correct 156 ms 484 KB Output is correct
47 Correct 158 ms 480 KB Output is correct
48 Correct 155 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 172 ms 484 KB Output is correct
36 Correct 171 ms 484 KB Output is correct
37 Correct 179 ms 488 KB Output is correct
38 Correct 172 ms 480 KB Output is correct
39 Correct 171 ms 480 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 164 ms 588 KB Output is correct
44 Correct 164 ms 516 KB Output is correct
45 Correct 169 ms 600 KB Output is correct
46 Correct 156 ms 484 KB Output is correct
47 Correct 158 ms 480 KB Output is correct
48 Correct 155 ms 480 KB Output is correct
49 Incorrect 173 ms 488 KB Output isn't correct
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1303 ms 29360 KB Output is correct
36 Correct 1312 ms 29288 KB Output is correct
37 Correct 1310 ms 29420 KB Output is correct
38 Correct 1328 ms 29372 KB Output is correct
39 Correct 1302 ms 29464 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 193 ms 29424 KB Output is correct
43 Correct 216 ms 29508 KB Output is correct
44 Correct 194 ms 29480 KB Output is correct
45 Correct 1105 ms 29384 KB Output is correct
46 Correct 1092 ms 29484 KB Output is correct
47 Correct 1091 ms 29332 KB Output is correct
48 Correct 1135 ms 29372 KB Output is correct
49 Correct 1143 ms 29380 KB Output is correct
50 Correct 1172 ms 29456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 172 ms 484 KB Output is correct
36 Correct 171 ms 484 KB Output is correct
37 Correct 179 ms 488 KB Output is correct
38 Correct 172 ms 480 KB Output is correct
39 Correct 171 ms 480 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 164 ms 588 KB Output is correct
44 Correct 164 ms 516 KB Output is correct
45 Correct 169 ms 600 KB Output is correct
46 Correct 156 ms 484 KB Output is correct
47 Correct 158 ms 480 KB Output is correct
48 Correct 155 ms 480 KB Output is correct
49 Correct 1303 ms 29360 KB Output is correct
50 Correct 1312 ms 29288 KB Output is correct
51 Correct 1310 ms 29420 KB Output is correct
52 Correct 1328 ms 29372 KB Output is correct
53 Correct 1302 ms 29464 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 193 ms 29424 KB Output is correct
57 Correct 216 ms 29508 KB Output is correct
58 Correct 194 ms 29480 KB Output is correct
59 Correct 1105 ms 29384 KB Output is correct
60 Correct 1092 ms 29484 KB Output is correct
61 Correct 1091 ms 29332 KB Output is correct
62 Correct 1135 ms 29372 KB Output is correct
63 Correct 1143 ms 29380 KB Output is correct
64 Correct 1172 ms 29456 KB Output is correct
65 Execution timed out 5046 ms 8388 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 464 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 5 ms 496 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 272 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 172 ms 484 KB Output is correct
36 Correct 171 ms 484 KB Output is correct
37 Correct 179 ms 488 KB Output is correct
38 Correct 172 ms 480 KB Output is correct
39 Correct 171 ms 480 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 164 ms 588 KB Output is correct
44 Correct 164 ms 516 KB Output is correct
45 Correct 169 ms 600 KB Output is correct
46 Correct 156 ms 484 KB Output is correct
47 Correct 158 ms 480 KB Output is correct
48 Correct 155 ms 480 KB Output is correct
49 Incorrect 173 ms 488 KB Output isn't correct
50 Halted 0 ms 0 KB -