# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
97569 |
2019-02-17T08:17:30 Z |
win11905 |
Vudu (COCI15_vudu) |
C++11 |
|
543 ms |
24424 KB |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author win11905
*/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e6+5;
class vudu {
private:
int n, p, A[N];
int t[N];
long pref[N], ans;
vector<long> coor;
void update(int x) {
for(int i = x+1; i < N; i += i & -i) t[i-1]++;
}
int query(int x, int v = 0) {
for(int i = x+1; i; i -= i & -i) v += t[i-1];
return v;
}
int get(long x) { return upper_bound(all(coor), x) - coor.begin() - 1; }
public:
void solve(istream& cin, ostream& cout) {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> A[i];
cin >> p;
for(int i = 1; i <= n; ++i) {
pref[i] = pref[i-1] + A[i] - p;
coor.emplace_back(pref[i]);
}
coor.emplace_back(0);
sort(all(coor));
coor.resize(unique(all(coor)) - coor.begin());
update(get(0));
for(int i = 1; i <= n; ++i) {
ans += query(get(pref[i]));
update(get(pref[i]));
}
cout << ans << endl;
}
};
class Solver {
public:
void solve(std::istream& in, std::ostream& out) {
vudu *obj = new vudu();
obj->solve(in, out);
}
};
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
16128 KB |
Output is correct |
2 |
Correct |
16 ms |
16128 KB |
Output is correct |
3 |
Correct |
17 ms |
16128 KB |
Output is correct |
4 |
Correct |
543 ms |
24340 KB |
Output is correct |
5 |
Correct |
303 ms |
24296 KB |
Output is correct |
6 |
Correct |
511 ms |
24424 KB |
Output is correct |
7 |
Correct |
447 ms |
24424 KB |
Output is correct |
8 |
Correct |
356 ms |
24424 KB |
Output is correct |
9 |
Correct |
517 ms |
24424 KB |
Output is correct |
10 |
Correct |
442 ms |
24420 KB |
Output is correct |