# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
519694 |
2022-01-27T04:30:48 Z |
Killer2501 |
Vudu (COCI15_vudu) |
C++14 |
|
404 ms |
56980 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e6+5;
const int M = 1e2+2;
const ll base = 1e4;
const ll mod = 998244353;
const int inf = 1e9;
const double ex = 1e-9;
int k, t, n;
int a[N], b[N], tong, m, fe[N];
ll ans, sum[N];
pii mx[N];
vector<ll> vi, adj[N];
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
void add(int id, int x)
{
for(; id <= n+1; id += id & -id)fe[id] += x;
}
int get(int id)
{
int res = 0;
for(; id; id -= id & -id)res += fe[id];
return res;
}
int lwr(ll x)
{
return lower_bound(vi.begin(), vi.end(), x) - vi.begin() + 1;
}
void sol(int icase)
{
cin >> n;
for(int i = 1; i <= n; i ++)cin >> a[i];
cin >> k;
for(int i = 1; i <= n; i ++)
{
sum[i] = sum[i-1] + a[i] - k;
vi.pb(sum[i]);
}
vi.pb(sum[0]);
sort(vi.begin(), vi.end());
vi.erase(unique(vi.begin(), vi.end()), vi.end());
add(lwr(0), 1);
for(int i = 1; i <= n; i ++)
{
ans = ans + get(lwr(sum[i]));
add(lwr(sum[i]), 1);
}
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
for(int i = 1; i <= test; i ++)sol(i);
return 0;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:66:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
vudu.cpp:67:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
24096 KB |
Output is correct |
2 |
Correct |
14 ms |
23980 KB |
Output is correct |
3 |
Correct |
15 ms |
23952 KB |
Output is correct |
4 |
Correct |
404 ms |
55932 KB |
Output is correct |
5 |
Correct |
202 ms |
43608 KB |
Output is correct |
6 |
Correct |
324 ms |
52320 KB |
Output is correct |
7 |
Correct |
354 ms |
53556 KB |
Output is correct |
8 |
Correct |
301 ms |
49468 KB |
Output is correct |
9 |
Correct |
374 ms |
56980 KB |
Output is correct |
10 |
Correct |
320 ms |
52604 KB |
Output is correct |