This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 1e6 + 9 , mod = 1e9 + 7;
int a[N] , d[N] ;
void ad(int x , int y){
while(x <= 1000000)
d[x] += y , x += (x & -x);
}
void add(int x , int y , int k){
if(x > y) swap(x , y);
ad(x , k) , ad(y + 1 , -k);
}
ll get(int x){
ll ans = 0;
while(x > 0)
ans += d[x] , x -= (x & -x);
return ans;
}
void solve()
{
int n , q , i , x , y , k ;
cin>>n>>q;
for(i = 1; i <= n; i++){
cin>>a[i];
if(i != 1) add(a[i] , a[i - 1] , 1);
}
while(q--){
cin>>k>>x;
if(k == 1){
cin>>y;
if(x > 1)
add(a[x - 1] , a[x] , -1) , add(a[x - 1] , y , 1);
if(x < n)
add(a[x + 1] , a[x] , -1) , add(a[x + 1] , y , 1);
a[x] = y;
}else {
cout<<get(x)<<"\n";
}
}
}
int main(){
TL;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t = 1;
//cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |