#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,m,i,j,k,p,ans[1000005],q,a[100005],plyus[1000005],h,u,v,t;
struct anun
{
ll tiv,kod;
};
bool operator<(const anun &a, const anun &b)
{
return a.tiv<b.tiv;
}
anun b[100005];
set<ll> s;
void ban();
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
if(n*m<=1000000)
{
ban();
return 0;
}
for(i=1;i<=n;i++)
{
cin>>a[i];
s.insert(a[i]);
b[i].tiv=a[i];
b[i].kod=i;
}
sort(b+1,b+1+n);
if(b[n].kod!=n && a[b[n].kod+1]<b[n].tiv)
plyus[b[n].tiv]++;
if(b[n].kod!=1 && a[b[n].kod-1]<b[n].tiv)
plyus[b[n].tiv]++;
for(i=n-1;i>=1;i--)
{
if(b[i].tiv!=b[i+1].tiv)
{
ans[b[i].tiv]=ans[b[i+1].tiv]+plyus[b[i+1].tiv];
if(b[i+1].kod!=n && a[b[i+1].kod+1]>b[i+1].tiv)
ans[b[i].tiv]--;
if(b[i+1].kod!=1 && a[b[i+1].kod-1]>b[i+1].tiv)
ans[b[i].tiv]--;
}
if(b[i].kod!=n && a[b[i].kod+1]<b[i].tiv)
plyus[b[i].tiv]++;
if(b[i].kod!=1 && a[b[i].kod-1]<b[i].tiv)
plyus[b[i].tiv]++;
}
/*for(i=1;i<=n;i++)
cout<<ans[b[i].tiv]<<" ";
cout<<endl;*/
for(i=1;i<=m;i++)
{
ll w;
cin>>w;
if(w==2)
{
cin>>h;
if(h<b[1].tiv || h>b[n].tiv)
cout<<0<<endl;
else
{
set<ll>::iterator it=s.lower_bound(h);
it--;
cout<<ans[*it]<<endl;
}
}
}
return 0;
}
void ban()
{
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=m;i++)
{
cin>>t;
if(t==1)
{
cin>>u>>v;
a[u]=v;
}
else
{
cin>>h;
ll anss=0;
for(j=2;j<=n;j++)
{
u=max(a[j-1],a[j]);
v=min(a[j-1],a[j]);
if(h>=v && h<=u)
anss++;
}
cout<<anss<<endl;
}
}
}
/*
10 5
20 2 8 4 10 12 14 6 16 18
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
294 ms |
3704 KB |
Output is correct |
9 |
Incorrect |
451 ms |
24952 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
294 ms |
3704 KB |
Output is correct |
9 |
Incorrect |
451 ms |
24952 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |