| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 218545 | socho | Vudu (COCI15_vudu) | C++14 | 880 ms | 65540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
struct node {
int s, e, m, val;
node *l, *r;
node (int _s, int _e) {
s = _s;
e = _e;
m = (s + e)/2;
val = 0;
if (s == e) return;
l = new node(s, m);
r = new node(m+1, e);
}
void upd(int p, int v) {
if (s == p && s== e) {
val = v;
return;
}
if (p <= m) {
l->upd(p, v);
}
else {
r->upd(p, v);
}
val = l->val + r->val; // transition
}
int qry(int qs, int qe) {
if (qs <= s && e <= qe) {
return val;
}
else if (qs > e || s > qe) {
return 0; // base case
}
else {
return l->qry(qs, qe) + r->qry(qs, qe); // transition
}
}
} *root;
signed main() {
int n;
cin >> n;
long long arr[n];
for (int i=0; i<n; i++) cin >> arr[i];
int p;
cin >> p;
for (int i=0; i<n; i++) arr[i] -= p;
long long pf[n];
pf[0] = arr[0];
for (int i=1; i<n; i++) pf[i] = pf[i-1] + arr[i];
sort(pf, pf+n);
root = new node(0, n);
long long sm = 0;
long long ans = 0;
for (int i=0; i<n; i++) {
if (pf[i] >= 0) ans++;
}
for (int i=0; i<n; i++) {
sm += arr[i];
int low = lower_bound(pf, pf+n, sm) - pf;
ans += root->qry(0, low);
// cout << i << '>' << ans << endl;
root->upd(low, root->qry(low, low)+1);
}
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
