QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563861#7950. Lucky Drawssentheta#WA 207ms19396kbC++202.6kb2024-09-14 16:26:002024-09-14 16:26:00

Judging History

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

  • [2024-09-14 16:26:00]
  • 评测
  • 测评结果:WA
  • 用时:207ms
  • 内存:19396kb
  • [2024-09-14 16:26:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)a; i<(int)b; i++)
#define Int long long
#define int long long
#define V vector

void solve();
signed main(){
	solve();
}

#define cerr if(0) cerr

const int N = 5e5+5;
const int Z = 2*N;
const int INF = 1e9;

int n, k;
int a[N], b[N];

int z; // max zipped value
map<int,int> zip;

// dp[i][j] = min # skipped interval if we selected i value and the last one is j
// value 0 must be chosen.
V<int> dp[N];

// range add update
// range min query
// point assign update
#define mid (tl+tr)/2
#define lc (v+1)
#define rc (v+2*(mid-tl+1))
struct Segtree{
	int st[2*Z], lz[2*Z];
	void add(int l,int r,int x,int v=0,int tl=0,int tr=z){
		if(r<tl || tr<l) return;
		if(l<=tl && tr<=r){
			st[v] += x; lz[v] += x; return;
		}
		if(lz[v]){
			add(1,n,lz[v], lc,tl,mid);
			add(1,n,lz[v], rc,mid+1,tr);
			lz[v] = 0;
		}
		add(l,r,x, lc,tl,mid);
		add(l,r,x, rc,mid+1,tr);
		st[v] = min(st[lc], st[rc]);
	}
	void assign(int i,int x,int v=0,int tl=0,int tr=z){
		if(tl==tr){
			st[v] = x; return;
		}
		if(lz[v]){
			add(1,n,lz[v], lc,tl,mid);
			add(1,n,lz[v], rc,mid+1,tr);
			lz[v] = 0;
		}
		if(i<=mid) assign(i,x, lc,tl,mid);
		else assign(i,x, rc,mid+1,tr);
		st[v] = min(st[lc], st[rc]);
	}
	int qry(int l,int r,int v=0,int tl=0,int tr=z){
		if(r<tl || tr<l) return INF;
		if(l<=tl && tr<=r) return st[v];
		if(lz[v]){
			add(1,n,lz[v], lc,tl,mid);
			add(1,n,lz[v], rc,mid+1,tr);
			lz[v] = 0;
		}
		return min({
			qry(l,r, lc,tl,mid),
			qry(l,r, rc,mid+1,tr)
		});
	}
} segtree;


V<int> endHere[Z];

void solve(){
	cin >> n >> k;

	rep(i,1,n+1){
		cin >> a[i] >> b[i];
		zip[a[i]];
		zip[b[i]];
	}

	// compress value
	zip[-INF];
	zip[INF];
	z = -1;
	for(auto&[x,y] : zip) y = ++z;
	cerr << "z: " << z << endl;

	rep(i,1,n+1){
		a[i] = zip[a[i]];
		b[i] = zip[b[i]];

		// cerr << "ab[i] " << a[i] << " " << b[i] << endl;
		endHere[b[i]].push_back(a[i]);
	}

	dp[1] = V<int>(z+1, INF);
	dp[1][0] = 0;

	rep(i,2,k+3){
		dp[i] = V<int>(z+1);
		// cerr << "i: " << i << endl;

		// insert previous raw dp values into segtree
		for(int x=0; x<=z; x++){
			segtree.assign(x, dp[i-1][x]);
		}

		// calculate current dp
		for(int x=0; x<=z; x++){
			// dp[i][x] = min(dp[i][x], dp[i-1][y] + #skippedInterval)
			dp[i][x] = segtree.qry(0,x);
			// cerr << dp[i][x] << " ";

			for(int y : endHere[x]){
				segtree.add(0,y-1, 1);
			}
		}
		cerr << endl;
	}

	cerr << "n: " << n << endl;
	cerr << "dp[k+2][z]: " << dp[k+2][z] << endl;
	int ans = n - dp[k+2][z];
	cout << ans << '\n';



}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 9844kb

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: 2ms
memory: 9828kb

input:

3 2
2 4
1 3
3 5

output:

3

result:

ok single line: '3'

Test #3:

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

input:

4 1
2 3
1 1
4 5
4 5

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 2ms
memory: 9824kb

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: 199ms
memory: 18348kb

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: 207ms
memory: 19396kb

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:

305

result:

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