# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
532385 |
2022-03-02T20:09:54 Z |
Vladth11 |
Vudu (COCI15_vudu) |
C++14 |
|
393 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 = 1000001;
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];
int v[NMAX];
map <ll, ll> mp;
int aib[NMAX + 1];
void update(int node, int x){
for(; node <= NMAX; node += node&(-node))
aib[node] += x;
}
int query(int node){
int 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);
int n, i;
cin >> n;
for(i = 1; i <= n; i++){
cin >> v[i];
}
int p;
cin >> p;
vector <int> 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());
int cnt = 0;
for(int 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:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int 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 |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
716 KB |
Output is correct |
4 |
Runtime error |
368 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Runtime error |
393 ms |
65540 KB |
Execution killed with signal 9 |
6 |
Runtime error |
357 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
363 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
328 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Runtime error |
365 ms |
65540 KB |
Execution killed with signal 9 |
10 |
Runtime error |
360 ms |
65540 KB |
Execution killed with signal 9 |