// アイスクリーム
#include <bits/stdc++.h>
#ifndef alks
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#endif
#pragma GCC optimize("O3,unroll-loops")
#define ll long long
#define int ll
#define Yes cout<<"YES\n"; return;
#define No cout<<"NO\n"; return;
#define yes cout<<"Yes\n"; return;
#define no cout<<"No\n"; return;
#define wrans cout<<"-1\n"; return;
using namespace std;
const int N=1e6+100;
const int M=1e6+100;
const int mod1=998244353;
const int mod=1e9+7;
const int INF=1e18;
const long double eps=1e-12;
const string ab="abcdefghijklmnopqrstuvwxyz";
const string AB="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n,q;
int a[N];
int cnt[N];
int cnt1[N];
int ans[N];
int f(int a,int b,int ans){
if(a<ans && b>ans){
return 1;
}
if(a>ans && b<ans){
return 1;
}
return 0;
}
void alikosh(){
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(n<=1000 && q<=1000){
for(int t,pos,x;q--;){
cin>>t;
if(t==1){
cin>>pos>>x;
a[pos]=x;
continue;
}
cin>>x;
int sum=0;
for(int i=1;i<n;i++){
sum+=f(a[i],a[i+1],x);
}
cout<<sum<<"\n";
}
return;
}
for(int i=1;i<n;i++){
int l=min(a[i],a[i+1]);
int r=max(a[i],a[i+1]);
cnt[l+1]++;
cnt1[r]--;
}
int res=0;
for(int i=1;i<=N;i++){
res+=cnt[i];
ans[i]=res;
res+=cnt1[i];
}
for(int t,x;q--;){
cin>>t>>x;
cout<<ans[x]<<"\n";
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int alikosh1=1;
// cin>>alikosh1;
for(int i=1;i<=alikosh1;i++){
// cout<<"Case "<<i<<": ";
alikosh();
}
}
//, Ice \ \
Compilation message (stderr)
game.cpp: In function 'void alikosh()':
game.cpp:67:19: warning: iteration 1000099 invokes undefined behavior [-Waggressive-loop-optimizations]
67 | res+=cnt[i];
| ~~~~~^
game.cpp:66:18: note: within this loop
66 | for(int i=1;i<=N;i++){
| ~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |