#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
struct node{
int s, e, m, val, lazy;
node *l, *r;
void create(){
if (l==nullptr){
l = new node(s, m);
r = new node(m+1, e);
}
}
void propagate(){
val+=lazy*(e-s+1);
if (s!=e){
create();
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
node(int S, int E){
s = S, e = E, m = (s+e)/2;
val=lazy=0;
l=r=nullptr;
}
void up(int left, int right, int v){
propagate();
if (s==left && e==right)lazy+=v;
else{
create();
if (right<=m)l->up(left, right, v);
else if (left>m)r->up(left, right, v);
else l->up(left, m, v), r->up(m+1, right, v);
r->propagate(), l->propagate();
val=l->val+r->val;
}
}
int query(int left, int right){
propagate();
if (s==left && e==right)return val;
create();
if (right<=m)return l->query(left, right);
else if (left>m)return r->query(left, right);
else return l->query(left, m)+r->query(m+1, right);
}
}*st;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, t, a, b;
cin>>n>>q;
vector<int> vect(n+1);
st = new node(1, 1000000);
for (int i=1; i<=n; ++i){
cin>>vect[i];
if (i!=1&&vect[i]!=vect[i-1])st->up(min(vect[i], vect[i-1]), max(vect[i], vect[i-1]), 1);
}
while (q--){
cin>>t;
if (t==1){
cin>>a>>b;
if (a!=1&&vect[a]!=vect[a-1])st->up(min(vect[a], vect[a-1]), max(vect[a], vect[a-1]), -1);
if (a!=n&&vect[a]!=vect[a+1])st->up(min(vect[a], vect[a+1]), max(vect[a], vect[a+1]), -1);
vect[a]=b;
if (a!=1&&vect[a]!=vect[a-1])st->up(min(vect[a], vect[a-1]), max(vect[a], vect[a-1]), 1);
if (a!=n&&vect[a]!=vect[a+1])st->up(min(vect[a], vect[a+1]), max(vect[a], vect[a+1]), 1);
}
else cin>>a, cout<<st->query(a, a)<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |