# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
714520 |
2023-03-24T21:29:32 Z |
four_specks |
Sails (IOI07_sails) |
C++17 |
|
22 ms |
3920 KB |
#include <bits/stdc++.h>
using namespace std;
namespace
{
template <typename T>
struct Fenwick
{
Fenwick(int _n) : n(_n), tree(n + 1, 0) {}
void add(int p, T x)
{
for (++p; p <= n; p += p & -p)
tree[p] += x;
}
T sum(int p)
{
T ret = 0;
for (; p; p -= p & -p)
ret += tree[p];
return ret;
}
private:
int n;
vector<T> tree;
};
} // namespace
void solve()
{
const int X = 100'000;
int n;
cin >> n;
assert(LONG_MAX > INT_MAX);
vector<long> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
Fenwick<long> fenw(X);
for (int i = 0; i < n; i++)
{
fenw.add(a[i] - b[i], 1);
fenw.add(a[i], -1);
}
vector<long> v(X);
for (int x = 0; x < X; x++)
v[x] = fenw.sum(x + 1);
stack<pair<long, int>> st;
for (int i = 0; i < n; i++)
{
long cur = v[i];
int cnt = 1;
while (!st.empty() && st.top().first <= v[i])
{
auto [x, y] = st.top();
st.pop();
cur += x * y;
cnt += y;
}
long q = cur / cnt, d = cur % cnt;
if (d > 0)
st.emplace(q + 1, d);
st.emplace(q, cnt - d);
}
long res = 0;
while (!st.empty())
{
auto [x, y] = st.top();
st.pop();
res += y * x * (x - 1) / 2;
}
cout << res << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
3920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
3712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |