답안 #256595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256595 2020-08-02T21:59:46 Z amiratou Vudu (COCI15_vudu) C++14
98 / 140
1000 ms 65540 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set= tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
ordered_set<pair<ll,int> > myset;
int A[1000001],n,k;
ll h,ans;
int32_t main(){
	boost;
	cin>>n;
	//freopen(".in","r",stdin);
	for (int i = 0; i < n; ++i)
		cin>>A[i];
	cin>>k;
	for (int i = 0; i < n; ++i)
	{
		h+=A[i]-k;
		myset.insert({h,i});
	}
	h=0;
	for (int i = 0; i < n; ++i)
	{
		ans+=sz(myset)-myset.order_of_key({h,-1});
		h+=A[i]-k;
		myset.erase({h,i});
	}
	cout<<ans<<"\n";
	return 0;
}

//do smth instead of nothing and stay organized
//long long
//array bounds
//special cases
//binary search
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 4 ms 768 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Execution timed out 1084 ms 65536 KB Time limit exceeded
5 Correct 518 ms 36984 KB Output is correct
6 Correct 893 ms 57592 KB Output is correct
7 Execution timed out 1054 ms 59872 KB Time limit exceeded
8 Correct 882 ms 52012 KB Output is correct
9 Runtime error 588 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Correct 930 ms 59384 KB Output is correct