# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92221 | diamond_duke | Fish (IOI08_fish) | C++11 | 1177 ms | 46100 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
using ll = long long;
int idx[500005], seg[1000005];
bool vis[500005];
std::pair<int, int> arr[500005];
std::vector<int> vec[500005];
int main()
{
// freopen("IOI2008-D1T3.in", "r", stdin);
int n, MOD, cnt = 0, ans = 0;
scanf("%d%*d%d", &n, &MOD);
for (int i = 0; i < n; i++)
scanf("%d%d", &arr[i].first, &arr[i].second);
std::sort(arr, arr + n);
for (int i = n - 1; i >= 0; i--)
{
if (!vis[arr[i].second])
{
vis[arr[i].second] = true;
idx[arr[i].second] = cnt++;
}
arr[i].second = idx[arr[i].second];
}
for (int i = 0; i < n; i++)
vec[arr[i].second].push_back(i);
for (int i = 0; i < cnt << 1; i++)
seg[i] = 1;
auto modify = [&] (int pos, int x)
{
for (seg[pos += cnt] += x; pos; pos >>= 1)
seg[pos >> 1] = (ll)seg[pos] * seg[pos ^ 1] % MOD;
};
auto query = [&] (int l, int r)
{
int res = 1;
for (l += cnt, r += cnt + 1; l < r; l >>= 1, r >>= 1)
{
if (l & 1)
res = (ll)res * seg[l++] % MOD;
if (r & 1)
res = (ll)res * seg[--r] % MOD;
}
return res;
};
for (int i = 0, j = 0; i < n; i++)
{
while (j < n && arr[j].first << 1 <= arr[i].first)
modify(arr[j++].second, 1);
if (vec[arr[i].second].back() != i)
continue;
modify(arr[i].second, -1);
ans = (ans + query(arr[i].second, cnt - 1)) % MOD;
int pos = -1;
for (int x : vec[arr[i].second])
{
if (-1 == pos && arr[x].first << 1 > arr[i].first)
pos = x;
}
int l = 0, r = arr[i].second, res = -1;
while (l <= r)
{
int m = l + r >> 1;
if (arr[pos].first << 1 > arr[vec[m].back()].first)
{
res = m;
r = m - 1;
}
else
l = m + 1;
}
ans = (ans + (ll)query(res, arr[i].second - 1) * query(arr[i].second + 1, cnt - 1)) % MOD;
modify(arr[i].second, 1);
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |