#include <bits/stdc++.h>
#define int long long
using namespace std;
const int VMAX = 1e6;
struct query_initial
{
int tip, poz, val;
};
query_initial Q[VMAX+5];
int n,q;
int v[VMAX+5];
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;
}
signed 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 'long long int get_poz(long long int)':
employment.cpp:86:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | int mij = (st+dr>>1);
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Runtime error |
4 ms |
716 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
3 ms |
588 KB |
Output is correct |
3 |
Runtime error |
5 ms |
1092 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Runtime error |
4 ms |
716 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |