i am using a set to store here instead of a vector but its giving me tle but my program should execute well under time limit
please tell me where its taking that much time
/*
ANIKET ASH
*/
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define pf push_front
#define pi 3.14159265358979323846
#define mod 1000000007
#define mp make_pair
#define ff first
#define ss second
#define nline ‘\n’
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template void _print(vector v);
template void _print(set v);
template <class T, class V> void _print(map <T, V> v);
template void _print(multiset v);
template <class T, class V> void _print(pair <T, V> p) {cerr << “{”; _print(p.ff); cerr << “,”; _print(p.ss); cerr << “}”;}
template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << “]”;}
template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << “]”;}
template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << “]”;}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << “]”;}
void solve()
{
int n,q;
cin>>n>>q;
vector a;
multiset b;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.pb(x);
b.insert(x);
}
while(q–)
{
int r,t;
cin>>t>>r;
if(t==1)
{ auto it=b.find(a[r-1]);
b.erase(it);
a[r-1]=1-a[r-1];
b.insert(a[r-1]);
}
if(t==2)
{
auto it=b.end();
it--;
int k=1;
for(it;;it--)
{
if(k==r){
cout<<*it<<nline;
break;
}
k++;
}
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen("output.txt", "w", stdout);
freopen(“error.txt”, “w”, stderr);
#endif
ios
int t=1;
// cin>>t;
while(t–)
{
solve();
}
return 0;
}