#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 1e6+5;
int a[N];
struct TREE{
vector<int>tree;
int s = 2;
void init(int n){
while(s < n) s*=2;
tree.assign(2*s, 0);
}
void set(int l, int r, int v, int lx, int rx, int x){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r){
tree[x] += v;
return;
}
int m = (lx + rx)/2;
set(l, r, v, lx, m, x*2);
set(l, r, v, m+1, rx, x*2+1);
}
int fnd(int i, int lx, int rx, int x){
if(lx == rx){
return tree[x];
}
int m = (lx + rx)/2;
if(i <= m) return (tree[x] + fnd(i, lx, m, x*2));
else return (tree[x] + fnd(i, m+1, rx, x*2+1));
}
void sett(int l, int r, int v){
if(l == r) return;
set(min(l, r), max(l, r), v, 1, s, 1);
}
int rfnd(int pos){
return fnd(pos, 1, s, 1);
}
}tree;
void solve(){
fastios
int n, m;
cin>>n>>m;
tree.init(N);
for(int i=0;i<n;i++){
cin>>a[i];
if(i) tree.sett(a[i-1], a[i], 1);
}
while(m--){
int t;
cin>>t;
if(t == 1){
int p, cv;
cin>>p>>cv;
--p;
if(p) tree.sett(a[p], a[p-1], -1);
if(p+1 < n) tree.sett(a[p], a[p+1], -1);
a[p] = cv;
if(p) tree.sett(a[p-1], a[p], 1);
if(p+1 < n) tree.sett(a[p+1], a[p], 1);
}
else{
int hh;
cin>>hh;
cout<<tree.rfnd(hh)<<"\n";
}
}
return;
}
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8556 KB |
Output is correct |
2 |
Correct |
8 ms |
8556 KB |
Output is correct |
3 |
Correct |
8 ms |
8556 KB |
Output is correct |
4 |
Correct |
8 ms |
8556 KB |
Output is correct |
5 |
Correct |
9 ms |
8556 KB |
Output is correct |
6 |
Correct |
8 ms |
8556 KB |
Output is correct |
7 |
Correct |
8 ms |
8556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8556 KB |
Output is correct |
2 |
Correct |
8 ms |
8556 KB |
Output is correct |
3 |
Correct |
8 ms |
8556 KB |
Output is correct |
4 |
Correct |
8 ms |
8556 KB |
Output is correct |
5 |
Correct |
9 ms |
8556 KB |
Output is correct |
6 |
Correct |
8 ms |
8556 KB |
Output is correct |
7 |
Correct |
8 ms |
8556 KB |
Output is correct |
8 |
Correct |
62 ms |
9184 KB |
Output is correct |
9 |
Correct |
119 ms |
9580 KB |
Output is correct |
10 |
Correct |
126 ms |
9708 KB |
Output is correct |
11 |
Correct |
45 ms |
9196 KB |
Output is correct |
12 |
Correct |
97 ms |
9580 KB |
Output is correct |
13 |
Correct |
92 ms |
9580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8556 KB |
Output is correct |
2 |
Correct |
8 ms |
8556 KB |
Output is correct |
3 |
Correct |
8 ms |
8556 KB |
Output is correct |
4 |
Correct |
8 ms |
8556 KB |
Output is correct |
5 |
Correct |
9 ms |
8556 KB |
Output is correct |
6 |
Correct |
8 ms |
8556 KB |
Output is correct |
7 |
Correct |
8 ms |
8556 KB |
Output is correct |
8 |
Correct |
62 ms |
9184 KB |
Output is correct |
9 |
Correct |
119 ms |
9580 KB |
Output is correct |
10 |
Correct |
126 ms |
9708 KB |
Output is correct |
11 |
Correct |
45 ms |
9196 KB |
Output is correct |
12 |
Correct |
97 ms |
9580 KB |
Output is correct |
13 |
Correct |
92 ms |
9580 KB |
Output is correct |
14 |
Correct |
233 ms |
9324 KB |
Output is correct |
15 |
Correct |
248 ms |
9196 KB |
Output is correct |
16 |
Correct |
239 ms |
9248 KB |
Output is correct |
17 |
Correct |
232 ms |
9292 KB |
Output is correct |
18 |
Correct |
240 ms |
9464 KB |
Output is correct |