Submission #548700

# Submission time Handle Problem Language Result Execution time Memory
548700 2022-04-14T10:02:46 Z NachoLibre Fish (IOI08_fish) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;

const int F = 500005, K = F;
int f, k, mo, z, c[K];
array<int, 2> a[F], b[F], ab[F];
vector<int> s;
struct oo {
	oo() {
		l = r = 0;
		x = 1;
	}
	oo *l, *r;
	int x;

	void P() {
		int lx = (!l ? 1 : l->x);
		int rx = (!r ? 1 : r->x);
		x = lx * rx % mo;
	}
} *root;

void upd(int i, int x, int l = 1, int r = k, oo *&t = root) {
	if(!t) t = new oo();
	if(l == r) {
		t->x = x;
		return;
	}
	int m = l + r >> 1;
	if(m >= i) upd(i, x, l, m, t->l);
	else upd(i, x, m + 1, r, t->r);
	t->P();
}

void updc(int g) {
	upd(g, c[g] + 1);
}

int x(int sl, int sr, int l = 1, int r = k, oo *&t = root) {
	if(l > sr || r < sl || !t) return 1;
	if(l >= sl && r <= sr) return t->x;
	int m = l + r >> 1;
	return x(sl, sr, l, m, t->l) * x(sl, sr, m + 1, r, t->r) % mo;
}

void moz(int i) {
	while(a[z][0] * 2 > a[i][0]) {
		c[a[z][1]] -= 1;
		updc(a[z][1]);
		z -= 1;
	}
	while(a[z + 1][0] * 2 <= a[i][0]) {
		z += 1;
		c[a[z][1]] += 1;
		updc(a[z][1]);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifdef x
	freopen("x.txt", "r", stdin);
	#endif
	cin >> f >> k >> mo;
	for(int i = 1; i <= f; ++i) {
		cin >> a[i][0] >> a[i][1];
	}
	a[f + 1][0] = 2e9;
	a[f + 1][1] = k + 1;
	sort(a + 1, a + f + 1);
	vector<int> smxf(f + 2, 0);
	smxf[f + 1] = k + 1;
	{
		vector<int> fg(k + 1, 0);
		int kg = k;
		for(int i = f; i >= 1; --i) {
			if(!fg[a[i][1]]) {
				fg[a[i][1]] = kg;
				kg -= 1;
			}
		}
		assert(kg == 0);
		for(int i = 1; i <= f; ++i) {
			a[i][1] = fg[a[i][1]];
			b[i][0] = a[i][1];
			b[i][1] = i;
		}
		sort(b + 1, b + f + 1);
		for(int i = 1; i <= k; ++i) {
			ab[i][0] = 1e9;
		}
		for(int i = 1; i <= f; ++i) {
			ab[b[i][0]][0] = min(ab[b[i][0]][0], i - 1);
			ab[b[i][0]][1] = i;
			s.push_back(b[i][1]);
		}
		vector<bool> fasd(f + 1, 0);
		for(int i = f; i >= 1; --i) {
			smxf[i] = smxf[i + 1];
			if(!fasd[a[i][1]]) {
				fasd[a[i][1]] = 1;
				smxf[i] = a[i][1];
			}
		}
	}
	moz(f);
	int fp = x(1, k);
	vector<bool> xm(k + 1);
	xm[k] = 1;
	for(int i = f - 1; i >= 1; --i) {
		if(!xm[a[i][1]]) {
			xm[a[i][1]] = 1;
			moz(i);
			upd(a[i][1], c[a[i][1]]);
			(fp += x(1, a[i][1])) %= mo;
			updc(a[i][1]);
			int y = *upper_bound(s.begin() + ab[a[i][1]][0], s.begin() + ab[a[i][1]][1], z);
			int l = y + 1, r = f + 1;
			while(l < r) {
				int m = l + r >> 1;
				if(a[y][0] * 2 <= a[m][0]) r = m;
				else l = m + 1;
			}
			int ff = smxf[l];
			fp += x(1, a[i][1] - 1) * x(a[i][1] + 1, ff - 1) % mo;
			fp %= mo;
		}
	}
	assert(fp >= 0 && fp < m);
	cout << fp << endl;
	return 0;
}

Compilation message

fish.cpp: In function 'void upd(int, int, int, int, oo*&)':
fish.cpp:33:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |  int m = l + r >> 1;
      |          ~~^~~
fish.cpp: In function 'int x(int, int, int, int, oo*&)':
fish.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |  int m = l + r >> 1;
      |          ~~^~~
fish.cpp: In function 'int main()':
fish.cpp:125:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  125 |     int m = l + r >> 1;
      |             ~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fish.cpp:1:
fish.cpp:134:25: error: 'm' was not declared in this scope; did you mean 'xm'?
  134 |  assert(fp >= 0 && fp < m);
      |                         ^