//https://www.instagram.com/_modwwe/
//#include "bubblesort2.h"
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans ","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int inf=1e9;
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int kk;
int el=29;
ib t[4000001];
void ff(int x)
{
for(int i=x*2;i<=x*2+1;i++)
t[i].a+=t[x].b,
t[i].b+=t[x].b;
t[x].b=0;
}
void upd(int node,int l,int r,int l1,int r1,int x)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1) {t[node].b+=x;t[node].a+=x; return;}
if(t[node].b!=0)
ff(node);
int mid=l+r>>1;
upd(node<<1,l,mid,l1,r1,x);
upd(node<<1|1,mid+1,r,l1,r1,x);
t[node].a=max(t[node<<1].a,t[node<<1|1].a);
}
void upd2(int node,int l,int r,int l1,int x)
{
if(l==r)
{
t[node].a+=x;
return;
}
if(t[node].b!=0)
ff(node);
int mid=l+r>>1;
if(l1<=mid) upd2(node<<1,l,mid,l1,x);
else upd2(node<<1|1,mid+1,r,l1,x);
t[node].a=max(t[node<<1].a,t[node<<1|1].a);
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> y)
{
n=a.size();
m=x.size();
vector<int> c(m);
vector<pair<int,int>> v;
for(int i=0;i<n;i++) v.pb({a[i],i});
for(int i=0;i<m;i++)v.pb({y[i],x[i]});
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
l=v.size()-1;
for(int i=1;i<=l*4;i++)
t[i].a=-inf;
for(int i=0;i<n;i++)
{
s2=lower_bound(v.begin(),v.end(),make_pair(a[i],i))-v.begin();
upd2(1,0,l,s2,i+inf);
if(s2!=l)
upd(1,0,l,s2+1,l,-1);
}
for(int i=0;i<m;i++)
{
s2=lower_bound(v.begin(),v.end(),make_pair(a[x[i]],x[i]))-v.begin();
upd2(1,0,l,s2,-x[i]-inf);
if(s2!=l)
upd(1,0,l,s2+1,l,1);
a[x[i]]=y[i];
s2=lower_bound(v.begin(),v.end(),make_pair(a[x[i]],x[i]))-v.begin();
upd2(1,0,l,s2,x[i]+inf);
if(s2!=l)
upd(1,0,l,s2+1,l,-1);
c[i]=t[1].a;
}
return c;
}
/*main()
{
vector<int>a,b,c;
a.resize(4);
a={1,2,3,4};
b.resize(2);
c.resize(2);
b={0,2};
c={3,1};
vector<int> z=countScans(a,b,c);
for(auto x:z)
cout<<x,down
}*/
Compilation message
bubblesort2.cpp: In function 'void upd(int, int, int, int, int, int)':
bubblesort2.cpp:64:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid=l+r>>1;
| ~^~
bubblesort2.cpp: In function 'void upd2(int, int, int, int, int)':
bubblesort2.cpp:78:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
78 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
12 ms |
1500 KB |
Output is correct |
21 |
Correct |
15 ms |
1512 KB |
Output is correct |
22 |
Correct |
13 ms |
1624 KB |
Output is correct |
23 |
Correct |
11 ms |
1372 KB |
Output is correct |
24 |
Correct |
11 ms |
1484 KB |
Output is correct |
25 |
Correct |
11 ms |
1368 KB |
Output is correct |
26 |
Correct |
10 ms |
1372 KB |
Output is correct |
27 |
Correct |
10 ms |
1372 KB |
Output is correct |
28 |
Correct |
10 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2016 KB |
Output is correct |
2 |
Correct |
52 ms |
4320 KB |
Output is correct |
3 |
Correct |
85 ms |
6352 KB |
Output is correct |
4 |
Correct |
88 ms |
6396 KB |
Output is correct |
5 |
Correct |
94 ms |
6132 KB |
Output is correct |
6 |
Correct |
82 ms |
6348 KB |
Output is correct |
7 |
Correct |
83 ms |
6084 KB |
Output is correct |
8 |
Correct |
89 ms |
6352 KB |
Output is correct |
9 |
Correct |
86 ms |
6192 KB |
Output is correct |
10 |
Correct |
66 ms |
5068 KB |
Output is correct |
11 |
Correct |
64 ms |
4852 KB |
Output is correct |
12 |
Correct |
63 ms |
5072 KB |
Output is correct |
13 |
Correct |
64 ms |
5072 KB |
Output is correct |
14 |
Correct |
64 ms |
4976 KB |
Output is correct |
15 |
Correct |
64 ms |
5076 KB |
Output is correct |
16 |
Correct |
58 ms |
5072 KB |
Output is correct |
17 |
Correct |
59 ms |
5068 KB |
Output is correct |
18 |
Correct |
58 ms |
4916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
600 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
708 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
508 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
12 ms |
1500 KB |
Output is correct |
21 |
Correct |
15 ms |
1512 KB |
Output is correct |
22 |
Correct |
13 ms |
1624 KB |
Output is correct |
23 |
Correct |
11 ms |
1372 KB |
Output is correct |
24 |
Correct |
11 ms |
1484 KB |
Output is correct |
25 |
Correct |
11 ms |
1368 KB |
Output is correct |
26 |
Correct |
10 ms |
1372 KB |
Output is correct |
27 |
Correct |
10 ms |
1372 KB |
Output is correct |
28 |
Correct |
10 ms |
1372 KB |
Output is correct |
29 |
Correct |
20 ms |
2016 KB |
Output is correct |
30 |
Correct |
52 ms |
4320 KB |
Output is correct |
31 |
Correct |
85 ms |
6352 KB |
Output is correct |
32 |
Correct |
88 ms |
6396 KB |
Output is correct |
33 |
Correct |
94 ms |
6132 KB |
Output is correct |
34 |
Correct |
82 ms |
6348 KB |
Output is correct |
35 |
Correct |
83 ms |
6084 KB |
Output is correct |
36 |
Correct |
89 ms |
6352 KB |
Output is correct |
37 |
Correct |
86 ms |
6192 KB |
Output is correct |
38 |
Correct |
66 ms |
5068 KB |
Output is correct |
39 |
Correct |
64 ms |
4852 KB |
Output is correct |
40 |
Correct |
63 ms |
5072 KB |
Output is correct |
41 |
Correct |
64 ms |
5072 KB |
Output is correct |
42 |
Correct |
64 ms |
4976 KB |
Output is correct |
43 |
Correct |
64 ms |
5076 KB |
Output is correct |
44 |
Correct |
58 ms |
5072 KB |
Output is correct |
45 |
Correct |
59 ms |
5068 KB |
Output is correct |
46 |
Correct |
58 ms |
4916 KB |
Output is correct |
47 |
Correct |
304 ms |
19644 KB |
Output is correct |
48 |
Correct |
1182 ms |
60824 KB |
Output is correct |
49 |
Correct |
1263 ms |
66228 KB |
Output is correct |
50 |
Correct |
1270 ms |
66224 KB |
Output is correct |
51 |
Correct |
1236 ms |
66220 KB |
Output is correct |
52 |
Correct |
1234 ms |
66208 KB |
Output is correct |
53 |
Correct |
1242 ms |
66080 KB |
Output is correct |
54 |
Correct |
1082 ms |
66228 KB |
Output is correct |
55 |
Correct |
1238 ms |
66212 KB |
Output is correct |
56 |
Correct |
1089 ms |
66220 KB |
Output is correct |
57 |
Correct |
1055 ms |
66696 KB |
Output is correct |
58 |
Correct |
1128 ms |
66220 KB |
Output is correct |
59 |
Correct |
1079 ms |
61100 KB |
Output is correct |
60 |
Correct |
1022 ms |
61088 KB |
Output is correct |
61 |
Correct |
1018 ms |
60952 KB |
Output is correct |
62 |
Correct |
1030 ms |
59052 KB |
Output is correct |
63 |
Correct |
946 ms |
59124 KB |
Output is correct |
64 |
Correct |
990 ms |
59024 KB |
Output is correct |
65 |
Correct |
950 ms |
56744 KB |
Output is correct |
66 |
Correct |
858 ms |
56884 KB |
Output is correct |
67 |
Correct |
887 ms |
56960 KB |
Output is correct |