답안 #252697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252697 2020-07-26T06:54:33 Z islingr Vudu (COCI15_vudu) C++14
140 / 140
231 ms 16248 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int N = 1 << 20;
ll a[N], tmp[N];

ll solve(int l, int r) {
	if (r - l == 1) return 0;
	int m = l + r >> 1;
	ll res = solve(l, m) + solve(m, r);
	int i = l, j = m, k = l;
	while (i < m && j < r)
		if (a[i] <= a[j]) tmp[k++] = a[i++], res += r - j;
		else tmp[k++] = a[j++];
	while (i < m) tmp[k++] = a[i++];
	while (j < r) tmp[k++] = a[j++];
	rep(i, l, r) a[i] = tmp[i];
	return res;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	rep(i, 0, n) cin >> a[i + 1];
	int P; cin >> P;
	rep(i, 0, n) a[i + 1] -= P;
	rep(i, 0, n) a[i + 1] += a[i];

	cout << solve(0, n + 1);
}

Compilation message

vudu.cpp: In function 'll solve(int, int)':
vudu.cpp:21:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = l + r >> 1;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 231 ms 15608 KB Output is correct
5 Correct 129 ms 9080 KB Output is correct
6 Correct 210 ms 13944 KB Output is correct
7 Correct 207 ms 14456 KB Output is correct
8 Correct 180 ms 12664 KB Output is correct
9 Correct 231 ms 16248 KB Output is correct
10 Correct 203 ms 14072 KB Output is correct