Submission #91809

# Submission time Handle Problem Language Result Execution time Memory
91809 2018-12-30T06:31:16 Z diamond_duke Fish (IOI08_fish) C++11
100 / 100
1129 ms 38136 KB
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
using ll = long long;
std::pair<int, int> arr[500005];
int idx[500005], seg[1000005], cnt, MOD;
bool app[500005];
std::vector<int> vec[500005];
void modify(int pos, int x)
{
	for (seg[pos += cnt] += x; pos; pos >>= 1)
		seg[pos >> 1] = (ll)seg[pos] * seg[pos ^ 1] % MOD;
}
int 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;
}
int main()
{
	int n, 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 (app[arr[i].second])
			continue;
		app[arr[i].second] = true;
		idx[arr[i].second] = cnt++;
	}
	for (int i = 0; i < n; i++)
	{
		arr[i].second = idx[arr[i].second];
		vec[arr[i].second].push_back(i);
	}
	for (int i = 0; i < cnt << 1; i++)
		seg[i] = 1;
	for (int i = 0, cur = 0; i < n; i++)
	{
		while (arr[cur].first << 1 <= arr[i].first)
			modify(arr[cur++].second, 1);
		if (vec[arr[i].second].back() != i)
			continue;
		modify(arr[i].second, -1);
		(ans += query(arr[i].second, cnt - 1)) >= MOD ? (ans -= MOD) : 0;
		int pos = -1;
		for (int x : vec[arr[i].second])
		{
			if (arr[x].first << 1 > arr[i].first)
			{
				pos = x;
				break;
			}
		}
		int l = 0, r = arr[i].second, res = -1;
		while (l <= r)
		{
			int m = l + r >> 1;
			if (arr[vec[m].back()].first < arr[pos].first << 1)
			{
				r = m - 1;
				res = m;
			}
			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

fish.cpp: In function 'int main()':
fish.cpp:68:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int m = l + r >> 1;
            ~~^~~
fish.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%*d%d", &n, &MOD);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &arr[i].first, &arr[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12024 KB Output is correct
2 Correct 11 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12024 KB Output is correct
2 Correct 190 ms 18700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 14844 KB Output is correct
2 Correct 116 ms 15524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 12152 KB Output is correct
2 Correct 16 ms 12152 KB Output is correct
3 Correct 13 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 16424 KB Output is correct
2 Correct 261 ms 18460 KB Output is correct
3 Correct 247 ms 25576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 18868 KB Output is correct
2 Correct 245 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 16376 KB Output is correct
2 Correct 263 ms 18888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 259 ms 18668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 19736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 18424 KB Output is correct
2 Correct 446 ms 22176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 714 ms 22904 KB Output is correct
2 Correct 494 ms 21368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 23624 KB Output is correct
2 Correct 575 ms 22264 KB Output is correct
3 Correct 618 ms 26084 KB Output is correct
4 Correct 542 ms 22144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 909 ms 25052 KB Output is correct
2 Correct 1121 ms 38048 KB Output is correct
3 Correct 958 ms 38136 KB Output is correct
4 Correct 1129 ms 33704 KB Output is correct