#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define int long long
#define all(pr1) pr1.begin(),pr1.end()
#define alr(pr1) pr1.rbegin(),pr1.rend()
#define CEIL(pr1, pr2) (pr1 + pr2 - 1) / pr2
#define IOS std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define RT(s) return cout<<s,0
#define sz(s) (int)(s.size())
const long long N = 1e5 + 9, M = 3e9 + 9, MOD = 1e9 + 7, OO = 0x3f3f3f3f, MAX = 2147483647, LOO = 0x3f3f3f3f3f3f3f3f;
bool fun(int x, int z)
{
return (x < 0 || x >= z);
}
int32_t main()
{
IOS;
int n, m;
cin >> n;
vector<int> a, c;
vector<pair<int, int>> b;
map<int, int> mp;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
a.push_back(x);
}
cin >> m;
for (int i = 0; i < n; i++)
{
if (fun(i, sz(a)))
{
cout << "5454652\n";
return 0;
}
a[i] -= m;
}
for (int i = 1; i < n; i++)
{
if (fun(i, sz(a)) || fun(i - 1, sz(a)))
{
cout << "5454652\n";
return 0;
}
a[i] += a[i - 1];
}
for (int i = 0; i < n; i++)
{
if (fun(i, sz(a)))
{
cout << "5454652\n";
return 0;
}
mp[a[i]]++;
}
for (auto ch : mp)
b.push_back({ ch.first, ch.second });
sort(alr(b));
for (int i = 1; i < sz(b); i++)
{
if (fun(i, sz(b)) || fun(i - 1, sz(b)))
{
cout << "5454652\n";
return 0;
}
b[i].second += b[i - 1].second;
}
sort(all(b));
for (int i = 0; i < sz(b); i++)
{
if (fun(i, sz(b)))
{
cout << "5454652\n";
return 0;
}
c.push_back(b[i].first);
}
tree <pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> st;
int cur = 0, ans = 0;
for (int i = 0; i < n; i++)
{
if (c.back() >= cur)
{
int x = (lower_bound(all(c), cur) - c.begin());
int y = (i - st.order_of_key({ cur, 0 }));
if (fun(x, sz(b)))
{
cout << "5454652\n";
return 0;
}
ans += (b[x].second - y);
}
if (fun(i, sz(a)))
{
cout << "5454652\n";
return 0;
}
st.insert({ a[i], i });
cur = a[i];
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1492 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
4 ms |
1108 KB |
Output is correct |
4 |
Runtime error |
354 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
328 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
292 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
273 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
259 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
297 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
293 ms |
65536 KB |
Execution killed with signal 9 |