Submission #317299

# Submission time Handle Problem Language Result Execution time Memory
317299 2020-10-29T10:56:57 Z soroush Vudu (COCI15_vudu) C++14
140 / 140
463 ms 29652 KB
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll  ,ll > pii;
 
typedef long double ld;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn  = 3e6+100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
 
#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
 
ll n  , ans;
ll a[maxn] , p;
int fen[maxn];
vector < ll > vec;
 
void update(ll x){
	for(;x<=n ;x+=x&-x)
		fen[x]++;
}
 
int get(ll pos){
	int ans = 0;
	for(;pos;pos-=pos&-pos)
		ans+=fen[pos];
	return(ans);
}

int comp(ll x){
	return(lower_bound(vec.begin() , vec.end() , x) - vec.begin() + 1);
}
 
int main(){
    migmig
	cin >> n;
	for(int i = 1 ; i <= n ; i ++)
		cin >> a[i];
	cin >> p;
	for(int i = 1 ; i <= n ; i ++)
		a[i]-=p;
	ll sum = 0;
	for(int i = 1 ; i <= n ; i ++){
		sum+=a[i];
		vec.pb(sum);
	}
	sort(vec.begin() , vec.end());
	vec.resize(unique(vec.begin() , vec.end()) - vec.begin());
	sum = 0;
	for(int i = 1 ; i <= n ; i ++){
		sum+=a[i];
		ans+=get(comp(sum)) + (sum>=0);
		update(comp(sum));
	}
	cout << ans;
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 463 ms 28756 KB Output is correct
5 Correct 242 ms 13032 KB Output is correct
6 Correct 393 ms 25508 KB Output is correct
7 Correct 388 ms 26452 KB Output is correct
8 Correct 367 ms 21460 KB Output is correct
9 Correct 441 ms 29652 KB Output is correct
10 Correct 389 ms 25872 KB Output is correct