QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#325479#7950. Lucky Drawsmateberishvili#RE 1ms3816kbC++233.3kb2024-02-11 14:53:012024-02-11 14:53:02

Judging History

你现在查看的是最新测评结果

  • [2024-02-11 14:53:02]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3816kb
  • [2024-02-11 14:53:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = (int) 1e4 + 5;

pair<int, int> P[MAXN];
int n, m, k;

void compress() {
	vector<int> vals;
	
	for (int i = 1; i <= n; i++) {
		vals.push_back(P[i].first);
		vals.push_back(P[i].second);
	}
	
	sort(vals.begin(), vals.end());
	vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
	
	for (int i = 1; i <= n; i++) {
		P[i].first = lower_bound(vals.begin(), vals.end(), P[i].first) - vals.begin();
		P[i].second = lower_bound(vals.begin(), vals.end(), P[i].second) - vals.begin();
	}
	
	m = vals.size();
};

vector<int> dp[MAXN];
vector<int> ev[MAXN];
int T[MAXN];

int t[MAXN * 2];
int e[MAXN * 2];

void build(int v, int tl, int tr) {
	e[v] = 0;
	t[v] = 0;
	
	if (tl == tr) {
		t[v] = T[tl];
		return;
	}
	
	int mid = (tl + tr) >> 1;
	int c1 = v + 1, c2 = v + (mid + 1 - tl) * 2;
	
	build(c1, tl, mid);
	build(c2, mid + 1, tr);
	
	t[v] = max(t[c1], t[c2]); 
}

void push(int v, int tl, int tr) {
	if (e[v] == 0) {
		return;
	}
	
	if (tl != tr) {
		int mid = (tl + tr) >> 1;
		int c1 = v + 1, c2 = v + (mid + 1 - tl) * 2;
		e[c1] += e[v];
		e[c2] += e[v];
	}
	
	t[v] += e[v];
	e[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int x) {
	push(v, tl, tr);
	
	if (l > r || tl > r || tr < l) {
		return;
	}
	
	if (l <= tl && tr <= r) {
		e[v] += x;
		push(v, tl, tr);
		return;
	}
	
	int mid = (tl + tr) >> 1;
	int c1 = v + 1, c2 = v + (mid + 1 - tl) * 2;
	
	update(c1, tl, mid, l, r, x);
	update(c2, mid + 1, tr, l, r, x);
	
	t[v] = max(t[c1], t[c2]);
}

int query(int v, int tl, int tr, int l, int r) {
	push(v, tl, tr);
	
	if (l > r || tl > r || tr < l) {
		return 0;
	}
	
	if (l <= tl && tr <= r) {
		return t[v];
	}
	
	int mid = (tl + tr) >> 1;
	int c1 = v + 1, c2 = v + (mid + 1 - tl) * 2;
	
	return max(
		query(c1, tl, mid, l, r),
		query(c2, mid + 1, tr, l, r)
	);
}

void trav(int v, int tl, int tr) {
	push(v, tl, tr);
	
	if (tl == tr) {
		cout << t[v] << ' ';
		return;
	}
	
	int mid = (tl + tr) >> 1;
	int c1 = v + 1, c2 = v + (mid + 1 - tl) * 2;
	
	trav(c1, tl, mid);
	trav(c2, mid + 1, tr);
	
	t[v] = max(t[c1], t[c2]);
}

void dbg(string s) {
	return;
	cout << s << ": ";
	trav(1, 0, m - 1);
	cout << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); 	
	
	cin >> n >> k;
	
	for (int i = 1; i <= n; i++) {
		cin >> P[i].first >> P[i].second;
	}
	
	compress();
	
	for (int i = 0; i < m; i++) {
		dp[i] = vector<int>(m, 0);
	}
	
	for (int i = 1; i <= n; i++) {
		ev[P[i].first].push_back(i);
		ev[P[i].second + 1].push_back(-i);
	}
	
	for (int lvl = 1; lvl <= k; lvl++) {
		for (int i = 0; i < m; i++) {
			T[i] = (i > 0 ? dp[lvl - 1][i - 1] : 0);
		}
		
		build(1, 0, m - 1);
		
		for (int i = 0; i < m; i++) {	
			for (int id: ev[i]) {
				if (id > 0) {
					dbg("before: ");
					int p = P[id].first;
					update(1, 0, m - 1, 0, p, 1);
					dbg("after: ");
				}
				else {
					int p = P[-id].first;
					update(1, 0, m - 1, 0, p, -1);
				}
			}
			
			dp[lvl][i] = query(1, 0, m - 1, 0, i);
		}
	}
	
	int ans = 0;
	
	for (int lvl = 1; lvl <= k; lvl++) {
		for (int i = 0; i < m; i++) {
			ans = max(ans, dp[lvl][i]);
		}
	}
	
	cout << ans << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

input:

5 2
1 2
1 4
3 6
4 7
5 6

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

3 2
2 4
1 3
3 5

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

4 1
2 3
1 1
4 5
4 5

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

7 2
5 6
7 9
7 7
1 4
2 3
4 7
4 7

output:

6

result:

ok single line: '6'

Test #5:

score: -100
Runtime Error

input:

10000 50
-16187 -16186
743439 743441
-995450 -995449
921242 921242
-287646 -287644
110263 110264
650110 650110
897150 897151
262837 262839
935191 935193
6079 6080
815160 815162
-624776 -624774
-782088 -782086
486051 486052
-704289 -704287
-592330 -592329
-943804 -943803
43046 43047
-896912 -896910
-...

output:


result: