社区讨论
WA*2求条
AT_agc029_c[AGC029C] Lexicographic constraints参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mlu9lh0b
- 此快照首次捕获于
- 2026/02/20 10:22 3 周前
- 此快照最后确认于
- 2026/02/23 11:45 2 周前
rt,写法比较奇特
CPP#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define lll __int128
#define db double
#define ldb long db
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define endl '\n'
#define ft first
#define sd second
using namespace std;
int n;
int a[200005];
bool check(int x) {
stack<pii> stk;
for(int i = 2; i <= n; i++) {
if(a[i] > a[i - 1]) {
continue;
}
while(!stk.empty() && stk.top().ft > a[i]) {
stk.pop();
}
if(stk.empty() || stk.top().ft != a[i]) {
stk.push({a[i], 2});
} else {
int lst = a[i] + 1;
while(!stk.empty() && stk.top().ft == lst - 1 && stk.top().sd == x) {
lst--;
stk.pop();
}
if(stk.empty()) {
return 0;
}
if(stk.top().ft != lst - 1) {
stk.push({lst - 1, 2});
} else {
stk.top().sd++;
}
}
}
return 1;
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
bool f = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
f &= (a[i] > a[i - 1]);
}
if(f) {
cout << 1 << endl;
return 0;
}
int l = 2, r = n;
int ans;
while(l <= r) {
int mid = (l + r) / 2;
if(check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << endl;
return 0;
}
/*
Progress is impossible without change, and those who cannot change their minds cannot change anything.
NEVER GIVE UP.
*/
回复
共 0 条回复,欢迎继续交流。
正在加载回复...