当前位置:网站首页>Mex related learning
Mex related learning
2022-07-06 07:42:00 【eva_ can(not)survive】
MEX Is the smallest positive integer that does not appear in an interval .
Therefore, adding a number to the interval is only for those who join the interval mex Value can be increased ;
Let's look at two topics
Problem - C - Codeforces
https://codeforces.com/contest/1699/problem/C First of all, we can think about an interval 【L,R】 Of mex yes x, explain 【0,x-1】 It must have happened , So if x If the position of is inside the interval, it can be at any unused position in the interval , If you are not in this range, you can only stay in that position , because x Once moved, the sequence Column mex The value will definitely be affected .
int a[MAXN];
int pos[MAXN];
const int mod = 1e9 + 7;
void solve() {
int n;
ll ans = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
pos[a[i]] = i;
}
int mx = -INF, mn = INF;
for (int i = 0; i < n; i++) {
if (pos[i] > mn && pos[i] < mx) {
ans *= (mx - mn + 1 - i);
ans %= mod;
}
mn = min(mn, pos[i]);
mx = max(mx, pos[i]);
}
printf("%lld\n", ans);
}Then there is this question We need to find the largest lexicographic sequence we can get , So we b The element obtained in the sequence must be the largest one that can be selected mex, So we can maintain a prefix mex And suffixes mex, When our prefix mex This is equal to the maximum mex The answer array can be added when , Then start directly from the next point mex Replace value with suffix mex Value
struct MEX {
int cot[MAXN];
vector<int> res;
int id = 0;
void add(int x) {
cot[x]++;
res.push_back(x);
}
int mex() {
while (cot[id])
id++;
return id;
}
void clear() {
for (int v : res) {
cot[v]--;
}
id = 0;
res.clear();
}
};
MEX now, t;
int a[MAXN];
int last[MAXN];
void solve() {
now.clear();
t.clear();
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
for (int i = n; i >= 1; i--) {
t.add(a[i]);
last[i] = t.mex();
}
vector<int> ans;
int mx = last[1];
for (int i = 1; i <= n; i++) {
now.add(a[i]);
if (mx == now.mex()) {
ans.push_back(mx);
mx = last[i + 1];
now.clear();
}
}
printf("%d\n", ans.size());
for (int v : ans) {
printf("%d ", v);
}
putchar('\n');
}
边栏推荐
- Bugku CTF daily question: do you want seeds? Blackmailed
- 智能终端设备加密防护的意义和措施
- js對象獲取屬性的方法(.和[]方式)
- NiO programming introduction
- The way to learn go (I) the basic introduction of go to the first HelloWorld
- P3047 [USACO12FEB]Nearby Cows G(树形dp)
- 合规、高效,加快药企数字化转型,全新打造药企文档资源中心
- [factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems
- Inspiration from the recruitment of bioinformatics analysts in the Department of laboratory medicine, Zhujiang Hospital, Southern Medical University
- leecode-C語言實現-15. 三數之和------思路待改進版
猜你喜欢
![[MySQL learning notes 32] mvcc](/img/0d/2df82b63d1eb3283a84e27f67c1523.png)
[MySQL learning notes 32] mvcc
![Ble of Jerry [chapter]](/img/ed/32a5d045af8876d7b420ae9058534f.png)
Ble of Jerry [chapter]
![[computer skills]](/img/30/2a4506adf72eb4cb188dd64cce417d.jpg)
[computer skills]

Apache middleware vulnerability recurrence

Google may return to the Chinese market after the Spring Festival.

Three no resumes in the software testing industry. What does the enterprise use to recruit you? Shichendahai's resume

软件测试界的三无简历,企业拿什么来招聘你,石沉大海的简历

Typescript interface and the use of generics

word中如何删除某符号前面或后面所有的文字

Simulation of Teman green interferometer based on MATLAB
随机推荐
[dictionary tree] [trie] p3879 [tjoi2010] reading comprehension
Solution: système de surveillance vidéo intelligent de patrouille sur le chantier
Get the path of edge browser
Set picture annotation in markdown
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
[MySQL learning notes 30] lock (non tutorial)
Oracle column to row -- a field is converted to multiple rows according to the specified separator
word中把帶有某個符號的行全部選中,更改為標題
Ble of Jerry [chapter]
Typescript function definition
Launch APS system to break the problem of decoupling material procurement plan from production practice
P3047 [USACO12FEB]Nearby Cows G(树形dp)
Redis list detailed explanation of character types yyds dry goods inventory
Ali's redis interview question is too difficult, isn't it? I was pressed on the ground and rubbed
MEX有关的学习
edge瀏覽器 路徑獲得
xpath中的position()函数使用
Bugku CTF daily question: do you want seeds? Blackmailed
js對象獲取屬性的方法(.和[]方式)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
https://codeforces.com/contest/1629/problem/C