# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
532387 |
2022-03-02T20:11:27 Z |
Vladth11 |
Vudu (COCI15_vudu) |
C++14 |
|
383 ms |
65540 KB |
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 2000001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;
ll s[NMAX];
ll v[NMAX];
map <ll, ll> mp;
ll aib[NMAX + 1];
void update(ll node, ll x){
for(; node <= NMAX; node += node&(-node))
aib[node] += x;
}
ll query(ll node){
ll x = 0;
for(; node > 0; node -= node&(-node))
x += aib[node];
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i];
}
ll p;
cin >> p;
vector <ll> a;
for(i = 1; i <= n; i++){
v[i] = v[i] - p;
s[i] = s[i - 1] + 1LL * v[i];
a.push_back(s[i]);
}
a.push_back(0);
sort(a.begin(), a.end());
ll cnt = 0;
for(ll i = 0; i < a.size(); i++){
if(i == 0 || a[i] != a[i - 1])
cnt++;
mp[a[i]] = cnt;
}
ll sol = 0;
update(mp[0] + 1, 1);
for(i = 1; i <= n; i++){
s[i] = mp[s[i]] + 1; /// sa devina si 0 -> 1
sol += 1LL * query(s[i]);
update(s[i], 1);
}
cout << sol;
return 0;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:54:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(ll i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
972 KB |
Output is correct |
2 |
Correct |
3 ms |
844 KB |
Output is correct |
3 |
Correct |
3 ms |
844 KB |
Output is correct |
4 |
Runtime error |
315 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Correct |
383 ms |
51652 KB |
Output is correct |
6 |
Runtime error |
299 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
325 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
287 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Runtime error |
300 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
293 ms |
65540 KB |
Execution killed with signal 9 |