思路
这里我是用了一个bool数组 表示第i个文档是否存在,然后建一个set里面存没有建的文档
建立文档的时候直接取set的首元素就好,删除就查询,若为true就输出Successful,并向set中插入该元素
简单来说直接模拟就好
代码
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 10005;
inline ll read(){
ll s = 0, w = 1; char ch = getchar();
while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
set<int> s;
bool vis[100005];
int main(){
int n = read();
string tmp;
int op;
for(int i = 1 ; i < 100005 ; ++i) s.insert(i);
while(n--){
cin>>tmp;
if(tmp[0] == 'N'){
auto it = s.begin();
vis[*it] = true;
cout<<*it<<endl;
s.erase(it);
}
else{
cin>>op;
if(vis[op]){
puts("Successful");
vis[op] = false;
s.insert(op);
}
else puts("Failed");
}
}
}
京公网安备 11010502036488号