/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,k,cnt;
ll t[4000010],add[4000010];
ll a[1000010];
void push(ll v, ll tl, ll tr)
{
if(add[v]!=0)
{
add[v+v]+=add[v];
add[v+v+1]+=add[v];
ll tm=(tl+tr)>>1;
t[v+v]+=(tm-tl+1)*add[v];
t[v+v+1]+=(tr-tm)*add[v];
add[v]=0;
}
}
void upd(ll v,ll tl,ll tr,ll l,ll r,ll val)
{
//cout<<v<<" "<<tl<<" "<<tr<<" "<<l<<" "<<r<<" "<<val<<"\n";
if(tl>tr || l>r)
{
return;
}
if(tl==l && tr==r)
{
t[v]+=(tr-tl+1)*val;
add[v]+=val;
return;
}
push(v,tl,tr);
ll tm=(tl+tr)>>1;
upd(v+v,tl,tm,l,min(r,tm),val);
upd(v+v+1,tm+1,tr,max(tm+1,l),r,val);
t[v]=t[v+v]+t[v+v+1];
}
ll get(ll v,ll tl,ll tr,ll pos)
{
if(tl==tr)
{
return t[v];
}
push(v,tl,tr);
ll tm=(tl+tr)>>1;
if(tm>=pos)
{
return get(v+v,tl,tm,pos);
}
else
{
return get(v+v+1,tm+1,tr,pos);
}
}
void anomalous_solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<n;i++)
{
//cout<<min(a[i],a[i+1])<<" "<<max(a[i],a[i+1])<<"\n";
upd(1,1,1000000,min(a[i],a[i+1]),max(a[i],a[i+1]),1);
}
//cout<<"-------------------------\n";
ll tp,pos,val,h;
while(m--)
{
cin>>tp;
if(tp==1)
{
cin>>pos>>val;
if(pos<n)upd(1,1,1000000,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),-1);
if(pos>1)upd(1,1,1000000,min(a[pos],a[pos-1]),max(a[pos],a[pos-1]),-1);
a[pos]=val;
if(pos<n)upd(1,1,1000000,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),1);
if(pos>1)upd(1,1,1000000,min(a[pos],a[pos-1]),max(a[pos],a[pos-1]),1);
}
else
{
cin>>h;
cout<<get(1,1,1000000,h)<<"\n";
}
}
}
int main()
{
//freopen("INPUT.txt","r",stdin);
//freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
10 ms |
35676 KB |
Output is correct |
3 |
Correct |
10 ms |
35208 KB |
Output is correct |
4 |
Correct |
11 ms |
35676 KB |
Output is correct |
5 |
Correct |
9 ms |
35676 KB |
Output is correct |
6 |
Correct |
14 ms |
35164 KB |
Output is correct |
7 |
Correct |
6 ms |
37212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
10 ms |
35676 KB |
Output is correct |
3 |
Correct |
10 ms |
35208 KB |
Output is correct |
4 |
Correct |
11 ms |
35676 KB |
Output is correct |
5 |
Correct |
9 ms |
35676 KB |
Output is correct |
6 |
Correct |
14 ms |
35164 KB |
Output is correct |
7 |
Correct |
6 ms |
37212 KB |
Output is correct |
8 |
Correct |
71 ms |
14992 KB |
Output is correct |
9 |
Correct |
169 ms |
38484 KB |
Output is correct |
10 |
Correct |
183 ms |
38612 KB |
Output is correct |
11 |
Correct |
63 ms |
13488 KB |
Output is correct |
12 |
Correct |
104 ms |
17824 KB |
Output is correct |
13 |
Correct |
94 ms |
40016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
10 ms |
35676 KB |
Output is correct |
3 |
Correct |
10 ms |
35208 KB |
Output is correct |
4 |
Correct |
11 ms |
35676 KB |
Output is correct |
5 |
Correct |
9 ms |
35676 KB |
Output is correct |
6 |
Correct |
14 ms |
35164 KB |
Output is correct |
7 |
Correct |
6 ms |
37212 KB |
Output is correct |
8 |
Correct |
71 ms |
14992 KB |
Output is correct |
9 |
Correct |
169 ms |
38484 KB |
Output is correct |
10 |
Correct |
183 ms |
38612 KB |
Output is correct |
11 |
Correct |
63 ms |
13488 KB |
Output is correct |
12 |
Correct |
104 ms |
17824 KB |
Output is correct |
13 |
Correct |
94 ms |
40016 KB |
Output is correct |
14 |
Correct |
301 ms |
38228 KB |
Output is correct |
15 |
Correct |
294 ms |
38368 KB |
Output is correct |
16 |
Correct |
300 ms |
38276 KB |
Output is correct |
17 |
Correct |
296 ms |
38312 KB |
Output is correct |
18 |
Correct |
300 ms |
38224 KB |
Output is correct |