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;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int maxx = 2e6;
int tr[4*maxx];
void add(int x, int v){
while(x < maxx){
tr[x] += v;
x += (x & -x);
}
}
void add(int l, int r, int v){
// cout << l << " " << r << " " << v << "done\n";
if(l > r)
swap(l, r);
add(l, v);
add(r+1, -v);
}
int sum(int x){
int s = 0;
while(x > 0){
s += tr[x];
x -= (x & -x);
}
return s;
}
int a[maxx];
void S()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++){
cin >> a[i];
if(i > 1)
add(a[i-1],a[i], 1);
}
for(int i = 0; i < m; i ++){
int x;
cin >> x;
if(x == 1){
int c, b;
cin >> c >> b;
if(c > 1){
add(a[c-1], a[c], -1);
add(a[c-1], b, 1);
}
if(c < n){
add(a[c], a[c+1], -1);
add(b, a[c+1], 1);
}
a[c] = b;
}
else{
int b;
cin >> b;
cout << sum(b) << "\n";
}
}
/* for(int i = 0; i <= 5; i ++)
cout << sum(i) << " ";*/
}
int main()
{
IOS;
/*int t;
cin >> t;
while(t --)*/
S();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |