QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#302315#7950. Lucky DrawsPetroTarnavskyi#WA 173ms16684kbC++202.3kb2024-01-10 19:09:102024-01-10 19:09:10

Judging History

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

  • [2024-01-10 19:09:10]
  • 评测
  • 测评结果:WA
  • 用时:173ms
  • 内存:16684kb
  • [2024-01-10 19:09:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

struct SegTree
{
	int n;
	vector<int> mx, add;
	
	void init(int _n)
	{
		n = 2 << (32 - __builtin_clz(_n));
		mx.assign(n, 0);
		add.assign(n, 0);
	}
	void push(int v, int tl, int tr)
	{
		mx[v] += add[v];
		if(tl + 1 != tr)
		{
			FOR(t, 1, 3)
				add[2 * v + t] += add[v]; 
		}
		add[v] = 0;
	}
	void upd(int v, int tl, int tr, int l, int r, int val)
	{
		//cout << v << " " << tl << " " << tr << endl;
		push(v, tl, tr);
		if(r <= tl || tr <= l)
			return;
		if(l <= tl && tr <= r)
		{
			add[v] = val;
			push(v, tl, tr);
			return;
		}
		int tm = (tl + tr) / 2;
		upd(2 * v + 1, tl, tm, l, r, val);
		upd(2 * v + 2, tm, tr, l, r, val);
		
		mx[v] = max(mx[2 * v + 1], mx[2 * v + 2]);
	}	
};

const int N = 1 << 19;
vector<PII> events[N];

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int n, k;
	cin >> n >> k;
	VI poses;
	vector<PII> arr(n);
	FOR(i, 0, n)
	{
		cin >> arr[i].F >> arr[i].S;
		poses.PB(arr[i].F);
	}
	sort(ALL(poses));
	poses.resize(unique(ALL(poses)) - poses.begin());
	FOR(i, 0, n)
	{
		arr[i].F = (lower_bound(ALL(poses), arr[i].F) - poses.begin());
		arr[i].S = (upper_bound(ALL(poses), arr[i].S) - poses.begin());
		
		events[arr[i].F + 1].PB(MP(arr[i].F + 1, 1));
		events[arr[i].S + 1].PB(MP(arr[i].F + 1, -1));
	}
	
	n = SZ(poses) + 1;
	int ans = k;
	VI dp0(n, 0);
	
	
	FOR(draws, 1, k + 1)
	{
		SegTree T;
		T.init(n);
		FOR(i, 0, n)
		{
			T.upd(0, 0, n, i, i + 1, dp0[i]);
		}
	
		VI dp1(n, 0);
		FOR(i, 0, n)
		{
			for(auto [r, val] : events[i])
			{
				assert(r <= n);
				T.upd(0, 0, n, 0, r, val);
			}
			T.push(0, 0, n);
			dp1[i] = T.mx[0];
			ans = max(ans, dp1[i]);
		}
		dp0 = dp1;
		//FOR(i, 0, n)
		//	cout << dp1[i] << " ";
		//cout << endl;
	}
	cout << min(ans, n) << "\n";

	
	
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 15920kb

input:

3 2
2 4
1 3
3 5

output:

3

result:

ok single line: '3'

Test #3:

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

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: 15900kb

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: 0
Accepted
time: 170ms
memory: 16656kb

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:

100

result:

ok single line: '100'

Test #6:

score: -100
Wrong Answer
time: 173ms
memory: 16684kb

input:

10000 50
39778 39796
7765 7768
95957 95972
-92200 -92178
-67044 -67014
856 871
-95402 -95380
-29447 -29418
77170 77191
-50433 -50421
-18466 -18446
47582 47583
89872 89873
19175 19205
-46181 -46175
30461 30465
-83893 -83891
-87464 -87450
-92490 -92469
-95035 -95008
-60182 -60165
-9191 -9191
-61912 -6...

output:

290

result:

wrong answer 1st lines differ - expected: '265', found: '290'