#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
const int bs=420;
vector<pair<int*,int> >rbv;
inline void rb()
{
for(auto&t:rbv)
*t.fi=t.se;
rbv.clear();
return;
}
int n;
int v[200010];
int act[200010];
int acnt;
inline void put(int x,bool t)
{
if(t)
rbv.eb(act+x,act[x]);
act[x]=1;
if(t)
rbv.eb(&acnt,acnt);
acnt++;
if(act[x-1]==1)
acnt--;
if(act[x+1]==1)
acnt--;
return;
}
bool chk[200010];
inline void solve(vector<pi>&qv)
{
for(int i=0;i++<n;)
chk[i]=0,act[i]=0;
for(pi&t:qv)
if(t.se>0)
chk[t.fi]=1;
vector<int>vv;
for(int i=0;i++<n;)
if(!chk[i])
vv.eb(i);
sort(all(vv),[&](const int&x,const int&y){return v[x]>v[y];});
vector<pair<pi,vector<int> > >cqv;
vector<pi>curv;
for(int i=0;i++<n;)
if(chk[i])
curv.eb(i,v[i]);
int qcnt=0;
for(pi&t:qv)
{
if(t.se==0)
{
vector<int>chv;
for(pi&ct:curv)
if(ct.se>=t.fi)
chv.eb(ct.fi);
cqv.eb(pair<pi,vector<int> >(pi(qcnt++,t.fi),chv));
}
else
for(pi&ct:curv)
if(ct.fi==t.fi)
ct=t;
}
sort(all(cqv),[](pair<pi,vector<int> >&x,pair<pi,vector<int> >&y){return x.fi.se>y.fi.se;});
vector<int>ansv(qcnt);
int j=0;
for(int&t:vv)
{
while(j<(int)cqv.size()&&cqv[j].fi.se>v[t])
{
auto&cur=cqv[j];
j++;
for(int&ct:cur.se)
put(ct,1);
ansv[cur.fi.fi]=acnt;
rb();
}
put(t,0);
}
while(j<(int)cqv.size())
{
auto&cur=cqv[j];
j++;
for(int&ct:cur.se)
put(ct,1);
ansv[cur.fi.fi]=acnt;
rb();
}
for(int&t:ansv)
cout<<t<<'\n';
for(pi&t:qv)
if(t.se>0)
v[t.fi]=t.se;
return;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin>>n>>q;
for(int i=0;i++<n;)
cin>>v[i];
for(int i=0;i<q;i+=bs)
{
vector<pi>qv;
for(int j=0;j<bs&&i+j<q;j++)
{
int t,x;
cin>>t>>x;
if(t==2)
cin>>t;
else
t--;
qv.eb(x,t);
}
solve(qv);
}
cout.flush();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |