답안 #684807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684807 2023-01-22T13:40:28 Z US3RN4M3 Vudu (COCI15_vudu) C++17
140 / 140
576 ms 37656 KB
#include<ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
template<int size>
struct st {
	st<size / 2> l, r;
	int val = 0;
	st() {}
	void add(int pos) {
		val++;
		if(pos < size/2) l.add(pos);
		else r.add(pos - size/2);
	}
	int get(int pos) {
		if(pos == size / 2) return l.val;
		else if(pos > size / 2) {
			return l.val + r.get(pos - size / 2);
		} else return l.get(pos);

	}
};
template<>
struct st<1> {
	int val = 0;
	st() {}
	void add(int) {
		val++;
	}
	int get(int) {
		return val;
	}
};
st<1048576> t;
main() {
	int n; cin >> n;
	vector<int> nums(n);
	for(int & i : nums) cin >> i;
	ll p; cin >> p;
	vector<pair<ll, int>> vals(n);
	ll sum = 0;
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		sum += nums[i];
		ll goal = p*(i + 1);
		vals[i] = {sum - goal, i};
		if(sum >= goal) ans++;
	}
	sort(vals.begin(), vals.end());
	for(int i = 0; i < n; i++) {
		ans += t.get(vals[i].second);
		t.add(vals[i].second);
	}
	cout << ans << endl;
}

Compilation message

vudu.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8660 KB Output is correct
2 Correct 6 ms 8588 KB Output is correct
3 Correct 6 ms 8532 KB Output is correct
4 Correct 557 ms 34012 KB Output is correct
5 Correct 295 ms 19148 KB Output is correct
6 Correct 471 ms 25156 KB Output is correct
7 Correct 513 ms 25920 KB Output is correct
8 Correct 458 ms 23596 KB Output is correct
9 Correct 576 ms 37656 KB Output is correct
10 Correct 486 ms 25456 KB Output is correct