#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
using namespace std;
int a[100001];
int N,Right,n,Left;
int seg[3000001];
int bg = 0;
void Update(int pos, int val){
int ind = 0;
if(pos + 1 < n and bg != 0){
int aa = min(a[pos], a[pos + 1]), bb = max(a[pos], a[pos + 1]);
seg[aa + N - 1]--;
seg[bb + N]++;
ind = aa + N - 1;
while(ind/=2) seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];
ind = bb + N;
while(ind/=2) seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];
}
a[pos] = val;
if(pos + 1 < n){
int aa = min(a[pos], a[pos + 1]), bb = max(a[pos], a[pos + 1]);
seg[aa + N - 1]++;
seg[bb + N]--;
ind = aa + N - 1;
while(ind/=2) seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];
ind = bb + N;
while(ind/=2) seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];
}
}
int Query(int l = 1, int r = N, int ind = 1){
if(l > Right or r < Left) return 0;
if(l >= Left and r <= Right){
//cout << seg[ind] << ' ' << l << ' ' << r << endl;
return seg[ind];
}
int mid = (l + r) / 2;
return Query(l, mid, ind * 2) + Query(mid + 1,r, ind * 2 + 1);
}
signed main() {
int m; cin >> n >> m;
N = exp2(ceil(log2(1e6)));
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) {
if(i != n - 1) Update(i,a[i]);
}
bg = 1;
Left = 1;
while(m--){
int t; cin >> t;
if(t == 1){
int pos,val; cin >> pos >> val;
Update(pos - 1, val);
}else{
int H; cin >> H;
Right = H;
cout << Query() << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
7 ms |
11476 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
7 ms |
11476 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
7 ms |
11476 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |