| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 380261 | saarang123 | Vudu (COCI15_vudu) | C++17 | 365 ms | 19948 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1000 * 1000 + 2;
int bit[mxn], n, p;
void upd(int x) {
for(; x <= n; x += (x & -x))
bit[x]++;
}
long long qry(int x) {
long long res = 0;
for(; x > 0; x -= (x & -x))
res += bit[x];
return res;
}
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
#ifdef saarang
freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
#endif
cin >> n;
vector<long long> a(n), b(n);
for(int i = 0; i < n; i++)
cin >> a[i];
cin >> p;
for(int i = 0; i < n; i++) {
a[i] -= p;
if(i)
a[i] += a[i - 1];
b[i] = a[i];
}
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
upd(lower_bound(b.begin(), b.end(), 0LL) - b.begin() + 1);
long long ans = 0;
for(int i = 0; i < n; i++) {
int id = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
ans += qry(id);
upd(id);
}
cout << ans << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
