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 int long long
#define sp << ' ' <<
#define nl << '\n'
struct FenwickTree{
vector<int> a; int n, s;
FenwickTree(int N){ a.resize((n=N)+1); }
void add(int i, int v){
for(++i; i<=n; i+=i&-i) a[i] += v;
}
int get(int i){
for(s=0; i>=1; i-=i&-i) s += a[i];
return s;
}
int get(int i, int j){ return get(j+1) - get(i); }
};
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, m, type, i, x; cin >> n >> m;
int a[n]; for(int &i : a) cin >> i;
FenwickTree b(1e6+1);
for(i=1; i<n; ++i){
b.add(min(a[i], a[i-1]), 1);
b.add(max(a[i], a[i-1]), -1);
}
while(m--){
cin >> type >> i;
if(type==1){
--i;
if(i){
b.add(min(a[i], a[i-1]), -1);
b.add(max(a[i], a[i-1]), 1);
}if(i+1<n){
b.add(min(a[i], a[i+1]), -1);
b.add(max(a[i], a[i+1]), 1);
}
cin >> a[i];
if(i){
b.add(min(a[i], a[i-1]), 1);
b.add(max(a[i], a[i-1]), -1);
}if(i+1<n){
b.add(min(a[i], a[i+1]), 1);
b.add(max(a[i], a[i+1]), -1);
}
}else{
cout << b.get(0, i) nl;
}
}
}
Compilation message (stderr)
game.cpp: In function 'int main()':
game.cpp:22:21: warning: unused variable 'x' [-Wunused-variable]
22 | int n, m, type, i, x; cin >> n >> m;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |