Submission #963272

# Submission time Handle Problem Language Result Execution time Memory
963272 2024-04-14T19:57:02 Z fzyzzz_z Fish (IOI08_fish) C++17
9 / 100
262 ms 31528 KB
#include <bits/stdc++.h>
using namespace std; 

using ll = long long; 

const int N = 500005; 

int m; 

struct seg {
	vector<int> t; 
	seg(vector<int> f) { 
		t = vector<int>(2 * f.size()); 
		for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1; 
		for (int i = f.size() - 1; i >= 1; --i) t[i] = ((ll)t[2 * i] * t[2 * i + 1]) % m; 
	} 
	void upd(int p, int v) {
		p += t.size() / 2; 
		if (t[p] == 1 && t[p] + v <= 1) return; 
		t[p] += v;  
		t[p] = max(t[p], 1); 
		for (; p > 1; p /= 2) {
			t[p / 2] = ((ll)t[p] * t[p ^ 1]) % m;
		}
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k; 
	cin >> n >> k >> m; 

	vector<int> f(k, 0); 
	vector<pair<int, int>> a(n); 
	for (auto & [x, y]: a) {
		cin >> x >> y; 
		f[--y]++; 
	}
	seg s(f), s2(f); 

	sort(a.begin(), a.end(), greater<pair<int, int>>()); 

	int ans = 0; 

	f = vector<int>(k, 0);
	vector<int> bad(k, 0); 
	vector<vector<int>> s0(n + 1); 
	for (int i = 0, j = 0; i < n; ++i) {
		for (auto x: s0[i]) s2.upd(x, -n); 

		if (f[a[i].second]) continue; 
		f[a[i].second] = 1; 

		while (a[j].first * 2 > a[i].first && j < n) {
			s.upd(a[j].second, -1); 
			s2.upd(a[j].second, -1); 
			if (i > 0) bad[a[j].second] = 1; 
			j++; 
		}

		// use 0 of prev type 
		ans += s.t[1]; 
		// cout << "A " << s.t[1] << '\n';

		if (!bad[a[i].second]) {
			int ov = s2.t[a[i].second + k]; 
			// must use max of cur type 
			s2.upd(a[i].second, -n); 
			ans += s2.t[1]; 
			// cout << "B " << s2.t[1] << '\n';
			s2.upd(a[i].second, ov - 1); 

			// must use max of cur and 0 of prev
			s.upd(a[i].second, -n); 
			ans -= s.t[1]; 
			// cout << "C " << s.t[1] << '\n';
		} else {
			s.upd(a[i].second, -n); 
		}

		s0[j].push_back(a[i].second); 

		ans += m; 
		ans %= m; 

		// cout << ans << '\n';
	}

	cout << ans << '\n'; 

	return 0; 
}

Compilation message

fish.cpp: In constructor 'seg::seg(std::vector<int>)':
fish.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1;
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 118 ms 22132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 9160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 608 KB Output is correct
2 Incorrect 2 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 13924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 22072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 14244 KB Output is correct
2 Incorrect 157 ms 23220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 139 ms 21320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 172 ms 23908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 168 ms 20572 KB Output is correct
2 Correct 212 ms 27000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 27172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 143 ms 23840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 31528 KB Output isn't correct
2 Halted 0 ms 0 KB -