Submission #2873171
Source Code Expand
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;
const ll MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);
constexpr int MAX_N = 200005;
struct BIT {
int n;
vector<ll> bit;
BIT(int n_) {
n_++;
n = n_;
bit.resize(MAX_N);
REP(i, n)add(i, 1);
}
ll sum(ll i) {
i++;
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(ll i, ll x) {
i++;
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
//変数
int N;
ll K;
vector<ll> a;
//サブ関数
//入力
void input()
{
cin >> N >> K;
a.resize(N + 1);
REP(i, N)cin >> a[i + 1];
REP(i, N)a[i + 1] -= K;
REP(i, N)a[i + 1] += a[i];
}
vector<pair<ll, ll>> make_sample(vector<ll> a)
{
vector<pair<ll, ll>> sample;
REP(i, N + 1)sample.push_back({ a[i],i });
sort(sample.begin(), sample.end());
return sample;
}
ll count(
vector<pair<ll, ll>>& sample,
BIT& bit,
pair<ll, ll> alpha)
{
auto itr = lower_bound(sample.begin(), sample.end(), alpha);
if (alpha != *itr)exit(1);
int id = distance(sample.begin(), itr);
int res = bit.sum(N) - bit.sum(id);
bit.add(id, -1);
return res;
}
//計算
void calc()
{
ll res = 0;
BIT bit(N);
auto sample = make_sample(a);
REP(i, N+1)res += count(sample, bit, { a[i],i });
cout << res << endl;
}
//出力
void output()
{
}
//デバッグ
void debug()
{
int N;
cin>>N;
}
//メイン関数
int main()
{
input();
calc();
output();
debug();
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Meaningful Mean |
User |
toma25 |
Language |
C++14 (GCC 5.4.1) |
Score |
600 |
Code Size |
2019 Byte |
Status |
AC |
Exec Time |
124 ms |
Memory |
11120 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
a01, a02, a03 |
All |
a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23 |
Case Name |
Status |
Exec Time |
Memory |
a01 |
AC |
2 ms |
1792 KB |
a02 |
AC |
2 ms |
1792 KB |
a03 |
AC |
2 ms |
1792 KB |
b04 |
AC |
2 ms |
1792 KB |
b05 |
AC |
117 ms |
9456 KB |
b06 |
AC |
106 ms |
10736 KB |
b07 |
AC |
123 ms |
9328 KB |
b08 |
AC |
123 ms |
9200 KB |
b09 |
AC |
94 ms |
9968 KB |
b10 |
AC |
97 ms |
11120 KB |
b11 |
AC |
2 ms |
1792 KB |
b12 |
AC |
2 ms |
1792 KB |
b13 |
AC |
43 ms |
5108 KB |
b14 |
AC |
121 ms |
9456 KB |
b15 |
AC |
61 ms |
9456 KB |
b16 |
AC |
108 ms |
9840 KB |
b17 |
AC |
120 ms |
10224 KB |
b18 |
AC |
120 ms |
10864 KB |
b19 |
AC |
106 ms |
10352 KB |
b20 |
AC |
124 ms |
10352 KB |
b21 |
AC |
113 ms |
10608 KB |
b22 |
AC |
121 ms |
9840 KB |
b23 |
AC |
119 ms |
10224 KB |