#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 1e6+5;
int a[N];
struct TREE{
vector<int>tree;
int s = 2;
void init(int n){
while(s < n) s*=2;
tree.assign(2*s, 0);
}
void set(int l, int r, int v, int lx, int rx, int x){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x] += v;
return;
}
int m = (lx + rx)/2;
set(l, r, v, lx, m, x*2);
set(l, r, v, m+1, rx, x*2+1);
}
int fnd(int i, int lx, int rx, int x){
if(lx == rx){
return tree[x];
}
int m = (lx + rx)/2;
if(i <= m) return (tree[x] + fnd(i, lx, m, x*2));
else return (tree[x] + fnd(i, m+1, rx, x*2+1));
}
void sett(int l, int r, int v){
set(min(l, r), max(l, r), v, 1, s, 1);
}
int rfnd(int pos){
return fnd(pos, 1, s, 1);
}
}tree;
void solve(){
fastios
int n, m;
cin>>n>>m;
tree.init(n);
for(int i=0;i<n;i++){
cin>>a[i];
if(i && a[i] != a[i-1]) tree.sett(a[i-1], a[i], 1);
}
while(m--){
int t;
cin>>t;
if(t == 1){
int p, cv;
cin>>p>>cv;
p--;
if(p && a[p] != a[p-1]){
tree.sett(a[p], a[p-1], -1);
}if(p < n-1 && a[p] != a[p+1]){
tree.sett(a[p], a[p+1], -1);
}
a[p] = cv;
if(p && a[p] != a[p-1]) tree.sett(a[p-1], a[p], 1);
p++;
if(p && a[p] != a[p-1]) tree.sett(a[p-1], a[p], 1);
}
else{
int hh;
cin>>hh;
cout<<tree.rfnd(hh)<<"\n";
}
}
return;
}
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |