Submission #838250

# Submission time Handle Problem Language Result Execution time Memory
838250 2023-08-26T12:06:55 Z caganyanmaz Fish (IOI08_fish) C++17
95 / 100
893 ms 65536 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp(x...) array<int, 2>({x})
using namespace std;

//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif

constexpr static int MXN = 5e5;
constexpr static int MXST = MXN<<1;
constexpr static int INF = 1e9;
int MOD, n, k;
int add() { return 0; }
int mul() { return 1; }
template<typename... V>
int add(int a, V... v) { return (a+add(v...)) % MOD; }
template<typename... V>
int mul(int64_t a, V... v) { return (a*mul(v...)) % MOD; }
int st[MXST];
array<int, 2> v[MXN];


void update(int i, int val) { for (st[i+=k]+=val;i>1;i>>=1) st[i>>1] = mul(st[i], st[i^1]); }
int query(int l, int r)
{
	int res = 1;
	for (l+=k,r+=k;l<r;l>>=1,r>>=1)
	{
		if (l&1) res = mul(res, st[l++]);
		if (r&1) res = mul(res, st[--r]);
	}
	return res;
}

array<int, 2> last[MXN];
set<int> pos[MXN];
int p[MXN];

void manage_types()
{
	vector<int> a;
	for (int i = 0; i < n; i++)
		a.pb(v[i][1]);
	sort(a.begin(), a.end());
	auto it = unique(a.begin(), a.end());
	a.erase(it, a.end());
	for (int i = 0; i < n; i++)
		v[i][1] = lower_bound(a.begin(), a.end(), v[i][1]) - a.begin();
	for (int i = 0; i < n; i++)
		last[v[i][1]] = {i, v[i][1]};
	sort(last, last + k);
	for (int i = 0; i < k; i++)
		p[last[i][1]] = k-i-1;
	for (int i = 0; i < n; i++)
		v[i][1] = -p[v[i][1]];
	sort(v, v + n);
	for (int i = 0; i < n; i++)
		v[i][1] = -v[i][1];
}

void manage_pos()
{
	for (int i = 0; i < n; i++)
		pos[v[i][1]].insert(v[i][0]);
}

set<array<int, 2>> ee;

int main()
{
	cin >> n;
	cin >> k;
	cin >> MOD;
	for (int i = 0; i < n; i++)
		cin >> v[i][0] >> v[i][1];
	sort(v, v + n);
	fill(st, st + 2*k, 1);
	manage_types();
	manage_pos();
	for (int i = 0; i < n; i++)
		debug(v[i]);
	int r;
	for (r = 0; v[r][0]*2 <= v[n-1][0]; r++)
		update(v[r][1], 1);
	int sum = query(0, k);
	debug(sum);
	ee.insert({v[n-1][0], 0});
	int j = 1; 
	for (int i = n-2; i >= 0; i--)
	{
		debug(v[i][1], j);
		if (v[i][1] != j)
			continue;
		while (v[r-1][0]*2>v[i][0])
		{
			debug(r-1);
			update(v[--r][1], -1);
		}
		int last_point = *pos[v[i][1]].upper_bound(v[i][0] / 2);
		auto it = ee.lower_bound(mp(last_point*2, -INF));
		if (it != ee.begin())
			it--;
		int ls;
		if (it == ee.end())
			ls = 0;
		else
		{
			ls = -(*it)[1];
			if (last_point*2 <= (*it)[0])
				ls++;
		}
		debug(v[i][1], ls, *it, last_point);
		int all_zero = query(j, k);
		debug(ls, j, j+1, k);
		int some_zero = mul(query(ls, j), query(j+1, k));
		int inter = query(j+1, k);
		debug(all_zero, some_zero, inter);
		debug(v[i][0], j, all_zero, some_zero, inter);
		sum = add(sum, all_zero, some_zero, -inter);
		debug(v[i][0], v[i][1]);
		ee.insert(mp(v[i][0], -v[i][1]));// Current point
		j++;
	}
	cout << sum << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23812 KB Output is correct
2 Correct 12 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23844 KB Output is correct
2 Correct 423 ms 57104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 35296 KB Output is correct
2 Correct 231 ms 40632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 24076 KB Output is correct
2 Correct 18 ms 24200 KB Output is correct
3 Correct 16 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 44316 KB Output is correct
2 Correct 525 ms 57896 KB Output is correct
3 Correct 490 ms 57968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 443 ms 35956 KB Output is correct
2 Correct 545 ms 58320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 44820 KB Output is correct
2 Correct 556 ms 58540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 539 ms 55464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 594 ms 59120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 55144 KB Output is correct
2 Correct 598 ms 65500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 741 ms 65508 KB Output is correct
2 Correct 487 ms 54732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 610 ms 61264 KB Output is correct
2 Correct 750 ms 65492 KB Output is correct
3 Correct 717 ms 65536 KB Output is correct
4 Correct 758 ms 65476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 893 ms 65536 KB Output is correct
2 Runtime error 670 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -