# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
380207 | alrad | Vudu (COCI15_vudu) | C++17 | 930 ms | 65536 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
/*
#pragma comment(linker, "/STACK:256000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
template <class T> inline T gcd(T a , T b) { return !a ? b : gcd(b % a , a); }
template <class T> inline T lcm(T a , T b) { return (a * b) / gcd(a , b) ; }
mt19937 rnd(time(0));
#define all(x) x.begin(), x.end()
#define debug(x) { cerr << #x << " = " << x << endl; }
const int N = 1e6 + 2;
long long T[N + 5];
void upd(int i, int D) {
for (; i < N; i = (i | (i + 1))) {
T[i] += D;
}
return;
}
long long calc(int R) {
long long result = 0;
for (; R >= 0; R = (R & (R + 1)) - 1) {
result += T[R];
}
return result;
}
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int P;
cin >> P;
for (int i = 0; i < n; i++) {
a[i] -= P;
}
vector<ll> pref(n, 0ll);
for (int i = 0; i < n; i++) {
pref[i] = a[i];
if (i) {
pref[i] += pref[i - 1];
}
}
int pos = -1;
auto compress = [&](void) {
vector<long long> b = pref;
b.push_back(0);
sort(all(b));
int key = 1;
unordered_map<long long, int> ct;
for (int i = 0; i < n + 1; i++) {
if (ct[b[i]] == 0) {
ct[b[i]] = key;
key++;
}
}
for (int i = 0; i < n; i++) {
pref[i] = ct[pref[i]];
}
pos = ct[0];
return;
};
compress();
upd(pos, +1);
long long ans = 0ll;
for (int i = 0; i < n; i++) {
ans += calc(pref[i]);
upd(pref[i], +1);
}
cout << ans << '\n';
return;
}
signed main() {
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |