有大佬浇浇吗😭这为什么不过啊
acm吧
全部回复
仅看楼主
level 7
题意概括就是:给一个字符串s和数字pos,记s中删除1个字符为v,在所有在v中字典序最小的记为s1,同样的,再在s1中删除1个中字典序最小的为s2...,将s1,s2,s3...sn-1(n=s.size()),按顺序拼成一个字符串ss,求ss的第pos位
源代码在评论,写了注释
附原题如下:
2024年06月20日 12点06分 1
level 7
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof((a)))
#define int long long
const int N=2e5+10;
const int M=1e6+10;
string s;
int lt[M],pos,wz2,ds;//删除了i个字符串包含的字符数量 所求元素位置 答案所在的字符串的第几个元素 需要删除元素个数
void solve(){
//输入
cin>>s>>pos;
stack<char>sk;
//字符串大小
int len=s.size();
//初始化lt数组 如字符串长度为5 那么有lt[1]=5 lt[2]=9 lt[3]=12 lt[4]=14 lt[5]=15
mem(lt,0);
for(int i=len;i>=1;i--)lt[len-i+1]=lt[len-i]+i;
//二分跑ds
ds=lower_bound(lt+1,lt+1+len,pos)-lt-1;
wz2=pos-lt[ds];
//删除ds个元素
for(const char c:s){
while(ds&&!sk.empty()&&sk.top()>c){
sk.pop();
ds--;
}
sk.push(c);
}
//得到答案所在的字符串,出答案
while(sk.size()!=wz2)sk.pop();
cout<<sk.top();
return;
}
signed main(){
ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
int t;cin>>t;while(t--)
solve();
}
2024年06月20日 12点06分 2
超时了
2024年06月20日 12点06分
level 7
2024年06月20日 12点06分 3
吧务
level 10
发下没用cf better翻译过的原题面或题目链接[怒]样例也没有
2024年06月21日 04点06分 6
😭😭😭
2024年06月21日 04点06分
吧务
level 10
最后的sk.size() 每求一遍耗时O(n) 原长1e6要求长1就O(n^2)爆了
2024年06月21日 04点06分 9
试了下是33ms,而且所有字符串长度总和不超过1e6吧
2024年06月21日 04点06分
level 7
https://codeforces.com/problemset/problem/1886/C
2024年06月21日 04点06分 10
level 7
总共是1e6个字符,全a也试过没超时
2024年06月21日 04点06分 12
level 7
此贴结
2024年06月21日 05点06分 13
1