#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
const int N = 1e6+1;
int T[N*4], lazy[N*4];
void push(int v, int l, int r){
if ( !lazy[v] ) return;
if ( l != r ){
lazy[v*2] += lazy[v];
lazy[v*2+1] += lazy[v];
}
else T[v] += lazy[v];
lazy[v] = 0;
}
void upd(int v, int l, int r, int tl, int tr, int val){
push(v, l, r);
if ( l > tr or tl > r ) return;
if ( tl <= l and tr >= r ){
lazy[v] += val;
push(v, l, r);
return;
}
int md = (l+r)>>1;
upd(v*2, l, md, tl, tr, val), upd(v*2+1, md+1, r, tl, tr, val);
}
int get(int v, int l, int r, int pos){
push(v, l, r);
if ( l == r ) return T[v];
int md = (l+r)>>1;
if ( pos <= md ) return get(v*2, l, md, pos);
return get(v*2+1, md+1, r, pos);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q; cin >> n >> q;
vector <int> val(n);
for ( auto &i: val ) cin >> i;
if ( n == 1 ) upd(1, 1, n, val.back(), val.back(), 1);
auto modify = [&](int l, int r, int value){
if ( l > r ) swap(l, r);
upd(1, 1, n, l, r, value);
};
for ( int i = 0; i+1 < n; i++ ) modify(val[i], val[i+1], 1);
while ( q-- ){
int t; cin >> t;
if ( t == 1 ){
int pos, v; cin >> pos >> v;
--pos;
if ( pos ){
modify(val[pos], val[pos-1], -1);
modify(v, val[pos-1], 1);
}
if ( pos+1 < n ){
modify(val[pos], val[pos+1], -1);
modify(v, val[pos+1], 1);
}
if ( n == 1 ){
modify(val[pos], val[pos], -1);
modify(v, v, 1);
}
val[pos] = v;
}
else{
int x; cin >> x;
cout << get(1, 1, n, x) << ln;
}
}
cout << '\n';
}
Compilation message
game.cpp: In function 'void IO(std::string)':
game.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |