QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185716#3101. Event Hopping 2bear0131#0 47ms17412kbC++203.0kb2023-09-22 15:42:502024-07-04 02:07:26

Judging History

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

  • [2024-07-04 02:07:26]
  • 评测
  • 测评结果:0
  • 用时:47ms
  • 内存:17412kb
  • [2023-09-22 15:42:50]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 998244353;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 100;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }

int n, k;
int l[100100], r[100100];
int ord[100100], ind[100100];
set<int> st;

int nxt[20][100100];
void precalc(){
	vector<pii> tmp; rep(i, n) tmp.emplace_back(l[i], i+1), tmp.emplace_back(r[i], -i-1);
	sort(tmp.begin(), tmp.end());
	int cur = n; l[n] = r[n] = inf, nxt[0][n] = n;
	for(int i = 2*n-1; i >= 0; --i){
		int id = abs(tmp[i].second) - 1;
		if(tmp[i].second > 0){ if(r[id] < r[cur]) cur = id; }
		else nxt[0][id] = cur;
	}
	l[n+1] = r[n+1] = -1, nxt[0][n+1] = cur;
	rep(i, 18) rep(j, n+2) nxt[i+1][j] = nxt[i][nxt[i][j]];
}

inline bool inter(int a, int b){ return max(l[a], l[b]) < min(r[a], r[b]); }
int calc(int lb, int ub){
	int ret = 0;
	for(int u = lb, i = 18; i >= 0; --i) if(r[nxt[i][u]] <= l[ub]) u = nxt[i][u], ret += (1<<i);
	return ret; 
}

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

	cin >> n >> k; rep(i, n) cin >> l[i] >> r[i];

	precalc();

	rep(i, n+2) ord[i] = i;
	sort(ord, ord+n+2, [&](int lh, int rh){ return l[lh] < l[rh]; });
	rep(i, n+2) ind[ord[i]] = i;

	st.emplace(0), st.emplace(n+1);
	int curans = calc(ord[0], ord[n+1]);
	vi ans;
	rep(i, n){
		auto ur = st.lower_bound(ind[i]), ul = prev(ur);
		int pl = ord[*ul], pr = ord[*ur];
		if(inter(i, pr) || inter(i, pl)) continue;
		int tmp = curans - calc(pl, pr) + calc(pl, i) + calc(i, pr) + 1;
		if(tmp >= k){ curans = tmp, st.emplace(ind[i]), ans.emplace_back(i); if((int)ans.size() >= k) break; }
	}

	if((int)ans.size() < k){ cout << "-1\n"; return 0; }
	rep(i, (int)ans.size()) cout << ans[i] + 1 << "\n";

	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 9740kb

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

score: 7
Accepted
time: 2ms
memory: 9656kb

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

score: 7
Accepted
time: 0ms
memory: 9872kb

input:

3 1
2 5
3 5
4 7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Wrong Answer
time: 47ms
memory: 17412kb

input:

99999 93097
40044 40749
44538 45365
46530 47401
52845 53481
59519 60065
86226 87059
88353 88992
95665 96502
95669 96575
100446 100968
121870 122544
130836 131540
146294 147230
151177 151970
160381 161376
164174 165119
166582 167438
169062 169687
173200 173849
177329 178217
189213 189811
249372 25029...

output:

-1

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #47:

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

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

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

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

score: 1
Accepted
time: 2ms
memory: 11796kb

input:

3 2
551691302 800582045
14063803 52897269
153641504 567834643

output:

1
2

result:

ok 2 lines

Test #50:

score: 0
Wrong Answer
time: 2ms
memory: 11760kb

input:

18 3
157893686 958635898
790021767 976682032
534783017 706987897
216566011 510148270
288661613 856715472
81126924 420966670
9734253 823219818
77427078 241270378
182953794 928971032
65710916 937359407
159217847 343023570
266169092 635952191
94867522 407392584
298640819 490028599
281580042 514089998
6...

output:

-1

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #74:

score: 0
Wrong Answer
time: 3ms
memory: 9932kb

input:

3000 57
226083340 261990234
392684356 462929590
468018811 841719892
495096853 606046097
196983814 256423598
331199122 967656486
802593662 931108452
74501453 679054962
294344294 752837262
295708332 547261648
265421699 652708933
272959087 727136240
165667761 846917534
61770748 157663302
608516043 8492...

output:

-1

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #111:

score: 0
Wrong Answer
time: 38ms
memory: 13136kb

input:

100000 361
136798318 785362988
255943758 535488232
175203444 266819907
766993466 893575347
67274251 589651108
662289594 883406317
830803801 849703610
729398668 798198453
202605534 677648797
66407931 925909114
174421361 601553812
522629146 701284080
136544340 295925673
299796891 499869765
736583725 8...

output:

-1

result:

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