Submission #678247

# Submission time Handle Problem Language Result Execution time Memory
678247 2023-01-05T10:59:45 Z vjudge1 Fish (IOI08_fish) C++17
0 / 100
880 ms 39600 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 1e6+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 22;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, k, m;
pair<int, int> niz[maxn];
int cnt[maxn];
int tour[treesiz];
bool bio[maxn];
int id[maxn], fir[maxn];

int mul(int a, int b) {
	a %= m, b %= m;
	return (a * b) % m;
}

void update(int x, int val) {
	x += off;
	tour[x] += val;

	x /= 2;
	while (x > 0) tour[x] = mul(tour[x * 2], tour[x * 2 + 1]), x /= 2;
}

int query(int a, int b, int l, int r, int node) {
	if (l > b || r < a) return 1;
	if (l >= a && r <= b) return tour[node];

	int mid = (l + r) / 2;
	return mul(query(a, b, l, mid, node * 2), query(a, b, mid + 1, r, node * 2 + 1));
}

int main() {
	scanf("%d%d%d", &n, &k, &m);
	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		niz[i] = {a, b};
	}
	sort(niz, niz+n);
	reverse(niz, niz+n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int col = niz[i].Y;
		if (bio[col]) continue;
		bio[col] = true;

		fir[cnt] = i;
		id[col] = cnt++;
	}
	for (int i = 0; i < n; i++) 
		niz[i].Y = id[niz[i].Y];

	for (int i = 0; i < treesiz; i++) tour[i] = 1;
	for (int i = 0; i < n; i++) update(niz[i].Y, 1);

	int sol = 0;
	int ptr = 0;
	memset(bio, false, sizeof bio);
	for (int i = 0; i < n; i++) {
		int len = niz[i].X;
		int col = niz[i].Y;
		if (bio[col]) continue;
		bio[col] = true;

		while (ptr < n && niz[ptr].X * 2 > niz[i].X) 
			update(niz[ptr++].Y, -1);
		update(col, -1);
		sol += query(niz[i].Y + 1, k, 0, off - 1, 1), sol %= m;

		int lo = 0, hi = k;
		while (lo < hi) {
			int mid = (lo + hi) / 2;
			if (fir[mid] >= 2 * len) lo = mid + 1;
			else hi = mid;
		}
		sol += mul(query(0, lo - 1, 0, off - 1, 1), query(lo + 1, k, 0, off - 1, 1)), sol %= m;
		update(niz[i].Y, 1);
	}
	printf("%d\n", sol);
	return 0;
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d%d%d", &n, &k, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fish.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 34132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 34140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 34128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 34040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 34072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 34132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 34152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 34136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 186 ms 35676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 34172 KB Output is correct
2 Incorrect 23 ms 34144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 232 ms 36480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 437 ms 38040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 269 ms 36424 KB Output is correct
2 Incorrect 428 ms 38072 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 378 ms 37648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 451 ms 38168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 438 ms 37576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 730 ms 38820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 731 ms 38824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 880 ms 39600 KB Output isn't correct
2 Halted 0 ms 0 KB -