Submission #256490

# Submission time Handle Problem Language Result Execution time Memory
256490 2020-08-02T18:36:08 Z mode149256 Fish (IOI08_fish) C++14
0 / 100
465 ms 65536 KB
/*input
5
3
7
8 3
5 3
4 3
2 3
2 3
*/
#include <bits/stdc++.h>
using namespace std;

namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}
}
using namespace my_template;

ll MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 500101;

ll mypow(ll a, ll b) {
	ll ret = 1;
	while (b) {
		if (b & 1) ret = (ret * a) % MOD;

		a = (a * a) % MOD;
		b >>= 1;
	}

	return ret;
}

int N, K;

struct node {
	int l, r;
	ll lazy;
	node *left = nullptr;
	node *right = nullptr;
	node(int a, int b): l(a), r(b) {
		lazy = 1;

		if (l != r) {
			left = new node(l, (l + r) / 2);
			right = new node((l + r) / 2 + 1, r);
		}
	}

	void prod(int a, int b, ll kart) {
		if (r < a or b < l) return;
		else if (a <= l and r <= b) {
			lazy = (lazy * kart) % MOD;
		} else {
			left->prod(a, b, kart);
			right->prod(a, b, kart);
		}
	}

	ll get(int pos) {
		if (l == r) return lazy;
		else if (pos <= (l + r) / 2)
			return (left->get(pos) * lazy) % MOD;
		else
			return (right->get(pos) * lazy) % MOD;
	}
};

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> K >> MOD;
	vpl sk(N);
	for (int i = 0; i < N; ++i) {
		cin >> sk[i].x >> sk[i].y;
		sk[i].y--;
	}
	sort(sk.rbegin(), sk.rend());

	ll ats = 0;

	node med(0, N - 1);

	int j = -1;

	vi last(K, -1);
	vi kiek(K, 0);
	vi prad(K, 0);

	for (int i = 0; i < N; ++i) {
		int k = (int)sk[i].y;
		if (!kiek[k]) prad[k] = i;
		kiek[k]++;
	}

	for (int i = 0; i < N; ++i)
	{
		int k = (int)sk[i].y;
		// if (buvo[sk[i].y]) continue;
		while (sk[j + 1].x >= 2 * sk[i].x) j++;

		// if (last[k] == -1) ats += med.get(i);

		// buvo[k] = true;

		if (last[k] + 1 <= min(prad[k], j)) {
			// printf("nuo %d %d kart %d\n", last[k] + 1, min(prad[k], j), kiek[k] + 1);
			med.prod(last[k] + 1, min(prad[k], j), kiek[k] + 1);
		}

		kiek[k]--;
		last[k] = max(last[k], min(prad[k], j));
	}

	last = vi(K, -1);

	for (int i = 0; i < N; ++i)
	{
		if (last[sk[i].y] == -1) {
			last[sk[i].y] = 1;
			ll val = med.get(i);
			// printf("i = %d, sk = %lld %lld, val = %lld\n", i, sk[i].x, sk[i].y, val);
			ats = (ats + val) % MOD;
		}
	}
	printf("%lld\n", ats);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 220 ms 61236 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 768 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 24756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Incorrect 5 ms 896 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 134 ms 37300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 200 ms 61304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 154 ms 37580 KB Output is correct
2 Incorrect 232 ms 62300 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 56148 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 62960 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 198 ms 51192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 351 ms 59128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 257 ms 57208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 465 ms 65536 KB Output isn't correct
2 Halted 0 ms 0 KB -