답안 #219225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219225 2020-04-04T16:08:40 Z gabrc52 Vudu (COCI15_vudu) C++14
42 / 140
1000 ms 65540 KB
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
typedef long long ll;

const int MAXN=1e6;
int N;
int arr[MAXN];
int P;
indexed_multiset s;
ll ac[MAXN];
ll sum[MAXN];
ll dif[MAXN];
ll than;
ll ans;

void remove(ll val) {
	s.erase(s.find_by_order(s.order_of_key(val)));
}

int countLowerOrEqual(ll val) {
	return s.order_of_key(val+1);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>N;
	for (int i=0; i<N; i++) {
		cin>>arr[i];
	}
	cin>>P;
	ac[0] = arr[0];
	for (int i=1; i<N; i++) {
		ac[i] = arr[i] + ac[i-1];
	}
	sum[0] = P;
	dif[0] = sum[0] - ac[0];
	for (int i=1; i<=N; i++) {
		sum[i] = sum[i-1] + P;
		dif[i] = sum[i] - ac[i];
	};
	for (int i=0; i<N; i++) {
		s.insert(dif[i]);
	}
	than = 0;
	ans += countLowerOrEqual(0);
	for (int i=1; i<N; i++) {
		remove(dif[i-1]);
		than += P - arr[i-1];
		ans += countLowerOrEqual(than);
	}
	cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1024 KB Output is correct
2 Correct 8 ms 896 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
4 Runtime error 920 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Execution timed out 1091 ms 42232 KB Time limit exceeded
6 Execution timed out 1102 ms 64760 KB Time limit exceeded
7 Runtime error 956 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Execution timed out 1096 ms 59384 KB Time limit exceeded
9 Runtime error 894 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Execution timed out 1092 ms 65528 KB Time limit exceeded