Submission #87964

# Submission time Handle Problem Language Result Execution time Memory
87964 2018-12-03T10:08:30 Z Good Vudu (COCI15_vudu) C++11
42 / 140
1000 ms 66560 KB
/*
ID: blackha5
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>

#define ff first
#define ss second
#define Maxn 1000003
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
using namespace std;

ll ans;
int n, p;
ll a[Maxn];
ll T[Maxn * 4];

map <ll, int> mp;

void upd (int x, int l, int r, int v) {
	if (l == r) {
		T[v] ++;
		return;
	}
	
	if (x <= mid (l, r))
		upd (x, l, mid (l, r), v * 2);
	else
		upd (x, mid (l, r) + 1, r, v * 2 + 1);
	
	T[v] = T[v * 2] + T[v * 2 + 1];
	return;		
}

int get (int x, int y, int l, int r, int v) {
	if (l > y or r < x)
		return 0;
	if (l >= x and r <= y)
		return T[v];
	
	return get (x, y, l, mid (l, r), v * 2) + get (x, y, mid (l, r) + 1, r, v * 2 + 1);		
}

int main () {
	//freopen ("file.in", "r", stdin);
	//freopen ("file.out", "w", stdout);
	
 	//srand ((unsigned) time ( NULL ));
	//int randomNumber = rand() % 10 + 1;

	scanf ("%d", &n);
	
	for (int i = 1; i <= n; i++)
		scanf ("%d", a + i);

	scanf ("%d", &p);
	for (int i = 1; i <= n; i++)
		a[i] -= p;
		
	mp[0] = 1;	
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
		mp[a[i]] = 1;
	}	
	
	int c = 0;
	for (auto i: mp)
		mp[i.ff] = ++c;
	
	upd (mp[0], 1, c, 1);
	for (int i = 1; i <= n; i++) {
		ans += get (1, mp[a[i]], 1, c, 1);
		upd (mp[a[i]], 1, c, 1);
	}
	
	printf ("%lld\n", ans);
	return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:62:21: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf ("%d", a + i);
                ~~~~~^
vudu.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &n);
  ~~~~~~^~~~~~~~~~
vudu.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", a + i);
   ~~~~~~^~~~~~~~~~~~~
vudu.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &p);
  ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1016 KB Output is correct
2 Correct 7 ms 1016 KB Output is correct
3 Correct 7 ms 1016 KB Output is correct
4 Runtime error 718 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Execution timed out 1014 ms 66560 KB Time limit exceeded
6 Runtime error 1033 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 827 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 903 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 639 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 983 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)