#include <bits/stdc++.h>
using namespace std;
const int VMAX = 5e5;
struct query_initial
{
int tip, poz, val;
};
query_initial Q[200005];
int n,q;
int v[200005];
vector<int> a;
int aib[VMAX+5];
int ub(int x)
{
return (x&(-x));
}
void update(int poz, int val)
{
for(int i=poz;i<=VMAX;i+=ub(i))
{
aib[i] += val;
}
}
int query(int poz)
{
int rez = 0;
for(int i=poz;i>=1;i-=ub(i))
{
rez += aib[i];
}
return rez;
}
void update_array(int poz, int val)
{
if(v[poz]>v[poz-1])
{
update(v[poz-1]+1,-1);
update(v[poz]+1,+1);
}
if(v[poz+1]>v[poz])
{
update(v[poz]+1,-1);
update(v[poz+1]+1,+1);
}
v[poz] = val;
if(v[poz]>v[poz-1])
{
update(v[poz-1]+1,+1);
update(v[poz]+1,-1);
}
if(v[poz+1]>v[poz])
{
update(v[poz]+1,+1);
update(v[poz+1]+1,-1);
}
}
void update_init(int poz)
{
if(v[poz]>v[poz-1])
{
update(v[poz-1]+1,+1);
update(v[poz]+1,-1);
}
}
int get_poz(int val)
{
int st = 1;
int dr = a.size();
int poz = 0;
while(st<=dr)
{
int mij = (st+dr>>1);
if(a[mij-1]<=val)
{
poz = val;
st = mij+1;
}
else
{
dr = mij-1;
}
}
return poz;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>v[i];
a.push_back(v[i]);
}
for(int i=1;i<=q;i++)
{
cin>>Q[i].tip;
if(Q[i].tip==1)
{
cin>>Q[i].val;
a.push_back(Q[i].val);
}
else
{
cin>>Q[i].poz>>Q[i].val;
a.push_back(Q[i].val);
}
}
sort(a.begin(),a.end());
for(int i=1;i<=n;i++)
{
v[i] = get_poz(v[i]);
update_init(i);
}
for(int i=1;i<=q;i++)
{
if(Q[i].tip==1)
{
int val = get_poz(Q[i].val);
cout<<query(val)<<'\n';
}
else
{
int poz = Q[i].poz;
int val = get_poz(Q[i].val);
update_array(poz,val);
}
}
return 0;
}
Compilation message
employment.cpp: In function 'int get_poz(int)':
employment.cpp:85:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int mij = (st+dr>>1);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
464 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Runtime error |
2 ms |
864 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |