Question is intended:
to [1, n], n number, there are two modes of operation:
1 x, deleting x
2 x, the query has not been omitted in number than the minimum number of x is.
input:
5 3 1 2 2 2 2 1
output:
3 1
Method: The method and the compression path of the search set
Code:
#include<bits/stdc++.h> using namespace std; #define int long long unordered_map<int,int> mp; int getf(int x){ if(!mp.count(x)) return x; else{ return mp[x]=getf(mp[x]); } } signed main(){ int n,q; cin>>n>>q; while(q--){ int x,y; scanf("%lld%lld",&x,&y); if(x==1){ mp[y]=getf(y+1); }else{ printf("%lld\n",getf(y)); } } return 0; }