답안 #232623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232623 2020-05-17T16:35:28 Z soroush Vudu (COCI15_vudu) C++14
56 / 140
661 ms 65540 KB
#pragma GCC optimize("O2")
#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  = 1e6+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;
ll fen[maxn];
vector < ll > vec;
map < ll , ll > mp;

void update(ll x){
	for(;x<=n ;x+=x&-x)
		fen[x]++;
}

int get(ll pos){
	ll ans = 0;
	for(;pos;pos-=pos&-pos)
		ans+=fen[pos];
	return(ans);
}

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());
	ll cur = 0;
	for(auto i : vec){
		if(mp[i] == 0)mp[i] = ++cur;
	}
	swap(n , cur);
	sum = 0;
	for(int i = 1 ; i <= cur ; i ++){
		sum+=a[i];
		ans+=get(mp[sum]) + (sum>=0);
		update(mp[sum]);
	}
	cout << ans;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1024 KB Output is correct
2 Correct 8 ms 896 KB Output is correct
3 Correct 8 ms 768 KB Output is correct
4 Runtime error 530 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Correct 661 ms 47444 KB Output is correct
6 Runtime error 513 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 514 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 561 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 531 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 503 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)