#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
#define endl "\n"
#define MAXN 1000007
int n, m, arr[100010], bit[1000010];
void upd(int x, int v)
{
while(x<MAXN)
{
bit[x]+=v;
x+=x&(-x);
}
}
int sum(int x)
{
int suma=0;
while (x)
{
suma+=bit[x];
x-=x&(-x);
}
return suma;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=0; i<n; i++) cin>>arr[i];
for (int i=1; i<n; i++)
{
upd(min(arr[i], arr[i-1]), 1);
upd(max(arr[i], arr[i-1])+1, -1);
}
while (m--)
{
int q; cin>>q;
if (q==1)
{
int i, x; cin>>i>>x;
i--;
if (i!=0)
{
upd(min(arr[i], arr[i-1]), -1);
upd(max(arr[i], arr[i-1])+1, 1);
upd(min(x, arr[i-1]), 1);
upd(max(x, arr[i-1])+1, -1);
}
if (i!=n-1)
{
upd(min(arr[i], arr[i+1]), -1);
upd(max(arr[i], arr[i+1])+1, 1);
upd(min(x, arr[i+1]), 1);
upd(max(x, arr[i+1])+1, -1);
}
arr[i]=x;
}
else
{
int h; cin>>h;
cout<<sum(h)<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
39 ms |
1784 KB |
Output is correct |
9 |
Correct |
51 ms |
6904 KB |
Output is correct |
10 |
Correct |
49 ms |
7036 KB |
Output is correct |
11 |
Correct |
39 ms |
1656 KB |
Output is correct |
12 |
Correct |
43 ms |
2924 KB |
Output is correct |
13 |
Correct |
42 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
3968 KB |
Output is correct |
3 |
Correct |
3 ms |
3968 KB |
Output is correct |
4 |
Correct |
3 ms |
3968 KB |
Output is correct |
5 |
Correct |
3 ms |
3840 KB |
Output is correct |
6 |
Correct |
3 ms |
3968 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
39 ms |
1784 KB |
Output is correct |
9 |
Correct |
51 ms |
6904 KB |
Output is correct |
10 |
Correct |
49 ms |
7036 KB |
Output is correct |
11 |
Correct |
39 ms |
1656 KB |
Output is correct |
12 |
Correct |
43 ms |
2924 KB |
Output is correct |
13 |
Correct |
42 ms |
2808 KB |
Output is correct |
14 |
Correct |
74 ms |
6904 KB |
Output is correct |
15 |
Correct |
71 ms |
6852 KB |
Output is correct |
16 |
Correct |
69 ms |
6880 KB |
Output is correct |
17 |
Correct |
77 ms |
6904 KB |
Output is correct |
18 |
Correct |
67 ms |
6904 KB |
Output is correct |