#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}
struct BIT{
vector<int> bit;
BIT(int n = 0): bit(n + 1) {}
void update(int p, int val){
for(; p > 0; p -= p & -p)
bit[p] += val;
}
int query(int p){
int ans = 0;
for(; p < sz(bit); p += p & -p)
ans += bit[p];
return ans;
}
};
void Main()
{
int N, Q; cin >> N >> Q;
vi a(N + 1); FOR(i, 1, N) cin >> a[i];
vi comp(all(a)), op(Q + 1), C(Q + 1), D(Q + 1);
FOR(i, 1, Q){
cin >> op[i];
if(op[i] & 1){
cin >> D[i];
}
else cin >> C[i] >> D[i];
comp.eb(D[i]);
}
sort(all(comp)), compact(comp);
BIT bit(sz(comp)), countB(sz(comp)); vi b = a;
auto update = [&](int i, int op) -> void{
if(i < N){
int w = min(b[i], b[i + 1]);
w = lower_bound(all(comp), w) - comp.begin();
bit.update(w, op);
}
};
auto update_count = [&](int i, int op) -> void{
int p = lower_bound(all(comp), b[i]) - comp.begin();
countB.update(p, op);
};
FOR(i, 1, N){
update(i, +1);
update_count(i, +1);
}
FOR(i, 1, Q){
if(op[i] & 1){
int p = lower_bound(all(comp), D[i]) - comp.begin();
cout << countB.query(p) - bit.query(p) << el;
}
else{
update(C[i], -1);
if(C[i] > 1){
update(C[i] - 1, -1);
}
update_count(C[i], -1);
b[C[i]] = D[i];
update(C[i], +1);
if(C[i] > 1){
update(C[i] - 1, +1);
}
update_count(C[i], +1);
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "TUYENDUNG"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
int t = 1; while(t--) Main();
return 0;
}
Compilation message (stderr)
employment.cpp: In function 'int32_t main()':
employment.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
117 | freopen(name".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
employment.cpp:118:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |