#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 + 2 , mod = 1e9 + 7;
int a[100002] , 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);
}
int get(int x){
int 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 |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4056 KB |
Output is correct |
4 |
Correct |
3 ms |
3984 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4056 KB |
Output is correct |
4 |
Correct |
3 ms |
3984 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
22 ms |
1876 KB |
Output is correct |
9 |
Correct |
34 ms |
6904 KB |
Output is correct |
10 |
Correct |
29 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
1624 KB |
Output is correct |
12 |
Correct |
24 ms |
2788 KB |
Output is correct |
13 |
Correct |
24 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
2 ms |
4056 KB |
Output is correct |
4 |
Correct |
3 ms |
3984 KB |
Output is correct |
5 |
Correct |
2 ms |
4184 KB |
Output is correct |
6 |
Correct |
2 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
22 ms |
1876 KB |
Output is correct |
9 |
Correct |
34 ms |
6904 KB |
Output is correct |
10 |
Correct |
29 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
1624 KB |
Output is correct |
12 |
Correct |
24 ms |
2788 KB |
Output is correct |
13 |
Correct |
24 ms |
2904 KB |
Output is correct |
14 |
Correct |
37 ms |
6736 KB |
Output is correct |
15 |
Correct |
38 ms |
6860 KB |
Output is correct |
16 |
Correct |
43 ms |
6868 KB |
Output is correct |
17 |
Correct |
38 ms |
6880 KB |
Output is correct |
18 |
Correct |
37 ms |
6736 KB |
Output is correct |