# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
75374 |
2018-09-09T13:17:44 Z |
damien_g |
Vudu (COCI15_vudu) |
C++14 |
|
1000 ms |
66560 KB |
#include <cstdio>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
struct Node
{
int l, r;
int nb;
Node *left, *right;
Node() {};
Node(int _l, int _r, int _nb, Node* _left, Node* _right): l(_l), r(_r), nb(_nb), left(_left), right(_right) {};
};
Node* root;
void add(Node *act, ll value)
{
if(act->r != act->l)
{
if(value <= (act->l+act->r)/2)
{
if(!act->left)
act->left = new Node(act->l, (act->l+act->r)/2, 0, NULL, NULL);
add(act->left, value);
}
else
{
if(!act->right)
act->right = new Node((act->l+act->r)/2+1, act->r, 0, NULL, NULL);
add(act->right, value);
}
}
act->nb++;
}
ll rsq(Node* node, ll l, ll r)
{
if((r < node->l) || (node->r < l))
return 0;
if((l <= node->l) && (node->r <= r))
return node->nb;
ll a = (node->left)?rsq(node->left, l, r):0;
ll b = (node->right)?rsq(node->right, l, r):0;
return a+b;
}
int N;
ll a[1 << 20];
ll P;
int main()
{
scanf("%d", &N);
for(int i = 0; i < N; i++)
scanf("%lld", &a[i]);
scanf("%lld", &P);
for(int i = 0; i < N; i++)
a[i] -= P;
root = new Node(0, 1 << 20, 0, NULL, NULL);
ll ans = 0, S = 0;
set<ll> sums;
sums.insert(0);
for(int i = 0; i < N; i++)
{
S += a[i];
sums.insert(S);
}
int k = 0;
map<ll, int> hash;
for(ll u : sums)
hash[u] = k++;
sums.clear();
add(root, hash[0]);
S = 0;
for(int i = 0; i < N; i++)
{
S += a[i];
ans += rsq(root, 0, hash[S]);
add(root, hash[S]);
}
printf("%lld\n", ans);
return 0;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
vudu.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &a[i]);
~~~~~^~~~~~~~~~~~~~~
vudu.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &P);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1528 KB |
Output is correct |
2 |
Correct |
9 ms |
1528 KB |
Output is correct |
3 |
Correct |
9 ms |
1528 KB |
Output is correct |
4 |
Runtime error |
794 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Execution timed out |
1068 ms |
66560 KB |
Time limit exceeded |
6 |
Runtime error |
693 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
619 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
646 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
647 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
663 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |