#include <bits/stdc++.h>
#include "bubblesort2.h"
#define Tree int h,int l,int r
#define Left (h<<1),l,(l+r)>>1
#define Right ((h<<1)|1),((l+r)>>1)+1,r
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N=5e5+5;
ll n,q,S,L,R,dl,idx,val,Xx,Yy,a[N],pos[N],x[N],inf=-1e9;
vector < int > answer;
vector < pair < pair < ll , ll > , pair < bool , ll > > > s;
typedef struct { ll x; ll add; } res;
res v[8*N];
inline void Shift(Tree) {
if (!v[h].add) return ;
v[(h<<1)].x+=v[h].add;
v[((h<<1)|1)].x+=v[h].add;
v[(h<<1)].add+=v[h].add;
v[((h<<1)|1)].add+=v[h].add;
v[h].add=0;
}
void Upd(Tree) {
if (R<l || r<L) return ;
if (L<=l && r<=R) { v[h].add+=dl; v[h].x+=dl; return ; }
Shift(h,l,r);
Upd(Left),Upd(Right);
v[h].x=max(v[(h<<1)].x,v[((h<<1)|1)].x);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
n=A.size(),q=X.size();
for (int i=1; i<=n; i++) {
a[i]=A[i-1];
s.pb({{a[i],i},{0,i}});
}
for (int i=1; i<=q; i++) {
pos[i]=X[i-1]+1,x[i]=V[i-1];
s.pb({{x[i],pos[i]},{1,i}});
}
sort(s.begin(),s.end()),S=s.size();
for (int i=0; i<S; i++)
if (!s[i].S.F)
a[s[i].S.S]=i+1;
else
x[s[i].S.S]=i+1;
if (S!=n+q) {
answer.push_back(1/0);
return answer;
}
for (int i=1; i<=4*S; i++)
v[i].x=inf-1;
for (int i=1; i<=n; i++) {
L=a[i],R=a[i],dl=-inf+i,Upd(1,1,S);
L=a[i]+1,R=S,dl=-1,Upd(1,1,S);
}
for (int i=1; i<=q; i++) {
Xx=a[pos[i]],Yy=x[i];
L=Xx,R=Xx,dl=inf-pos[i],Upd(1,1,S);
L=min(Xx,Yy)+1,R=max(Xx,Yy)-1;
if (Xx<=Yy) dl=1; else dl=-1;
if (L<=R) Upd(1,1,S);
L=Yy,R=Yy,dl=-inf+pos[i],Upd(1,1,S);
a[pos[i]]=x[i];
answer.push_back(v[1].x);
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:57:21: warning: division by zero [-Wdiv-by-zero]
answer.push_back(1/0);
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
632 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
8 ms |
1016 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
9 ms |
888 KB |
Output is correct |
7 |
Correct |
9 ms |
888 KB |
Output is correct |
8 |
Correct |
8 ms |
888 KB |
Output is correct |
9 |
Correct |
8 ms |
1020 KB |
Output is correct |
10 |
Correct |
8 ms |
1016 KB |
Output is correct |
11 |
Correct |
10 ms |
1016 KB |
Output is correct |
12 |
Correct |
8 ms |
888 KB |
Output is correct |
13 |
Correct |
8 ms |
1016 KB |
Output is correct |
14 |
Correct |
8 ms |
1016 KB |
Output is correct |
15 |
Correct |
9 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
1016 KB |
Output is correct |
17 |
Correct |
8 ms |
1016 KB |
Output is correct |
18 |
Correct |
8 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
632 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
8 ms |
1016 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
9 ms |
888 KB |
Output is correct |
7 |
Correct |
9 ms |
888 KB |
Output is correct |
8 |
Correct |
8 ms |
888 KB |
Output is correct |
9 |
Correct |
8 ms |
1020 KB |
Output is correct |
10 |
Correct |
8 ms |
1016 KB |
Output is correct |
11 |
Correct |
10 ms |
1016 KB |
Output is correct |
12 |
Correct |
8 ms |
888 KB |
Output is correct |
13 |
Correct |
8 ms |
1016 KB |
Output is correct |
14 |
Correct |
8 ms |
1016 KB |
Output is correct |
15 |
Correct |
9 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
1016 KB |
Output is correct |
17 |
Correct |
8 ms |
1016 KB |
Output is correct |
18 |
Correct |
8 ms |
888 KB |
Output is correct |
19 |
Correct |
21 ms |
2160 KB |
Output is correct |
20 |
Correct |
22 ms |
2412 KB |
Output is correct |
21 |
Correct |
23 ms |
2416 KB |
Output is correct |
22 |
Correct |
22 ms |
2412 KB |
Output is correct |
23 |
Correct |
21 ms |
2412 KB |
Output is correct |
24 |
Correct |
21 ms |
2412 KB |
Output is correct |
25 |
Correct |
21 ms |
2412 KB |
Output is correct |
26 |
Correct |
20 ms |
2416 KB |
Output is correct |
27 |
Correct |
23 ms |
2416 KB |
Output is correct |
28 |
Correct |
20 ms |
2416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3820 KB |
Output is correct |
2 |
Correct |
75 ms |
8396 KB |
Output is correct |
3 |
Correct |
135 ms |
13152 KB |
Output is correct |
4 |
Correct |
145 ms |
13152 KB |
Output is correct |
5 |
Correct |
129 ms |
13152 KB |
Output is correct |
6 |
Correct |
127 ms |
13152 KB |
Output is correct |
7 |
Correct |
148 ms |
13152 KB |
Output is correct |
8 |
Correct |
131 ms |
13152 KB |
Output is correct |
9 |
Correct |
125 ms |
13152 KB |
Output is correct |
10 |
Correct |
101 ms |
13152 KB |
Output is correct |
11 |
Correct |
102 ms |
13280 KB |
Output is correct |
12 |
Correct |
99 ms |
13152 KB |
Output is correct |
13 |
Correct |
104 ms |
13280 KB |
Output is correct |
14 |
Correct |
102 ms |
13152 KB |
Output is correct |
15 |
Correct |
106 ms |
13240 KB |
Output is correct |
16 |
Correct |
108 ms |
13136 KB |
Output is correct |
17 |
Correct |
113 ms |
13152 KB |
Output is correct |
18 |
Correct |
108 ms |
13152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
632 KB |
Output is correct |
3 |
Correct |
9 ms |
1016 KB |
Output is correct |
4 |
Correct |
8 ms |
1016 KB |
Output is correct |
5 |
Correct |
8 ms |
888 KB |
Output is correct |
6 |
Correct |
9 ms |
888 KB |
Output is correct |
7 |
Correct |
9 ms |
888 KB |
Output is correct |
8 |
Correct |
8 ms |
888 KB |
Output is correct |
9 |
Correct |
8 ms |
1020 KB |
Output is correct |
10 |
Correct |
8 ms |
1016 KB |
Output is correct |
11 |
Correct |
10 ms |
1016 KB |
Output is correct |
12 |
Correct |
8 ms |
888 KB |
Output is correct |
13 |
Correct |
8 ms |
1016 KB |
Output is correct |
14 |
Correct |
8 ms |
1016 KB |
Output is correct |
15 |
Correct |
9 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
1016 KB |
Output is correct |
17 |
Correct |
8 ms |
1016 KB |
Output is correct |
18 |
Correct |
8 ms |
888 KB |
Output is correct |
19 |
Correct |
21 ms |
2160 KB |
Output is correct |
20 |
Correct |
22 ms |
2412 KB |
Output is correct |
21 |
Correct |
23 ms |
2416 KB |
Output is correct |
22 |
Correct |
22 ms |
2412 KB |
Output is correct |
23 |
Correct |
21 ms |
2412 KB |
Output is correct |
24 |
Correct |
21 ms |
2412 KB |
Output is correct |
25 |
Correct |
21 ms |
2412 KB |
Output is correct |
26 |
Correct |
20 ms |
2416 KB |
Output is correct |
27 |
Correct |
23 ms |
2416 KB |
Output is correct |
28 |
Correct |
20 ms |
2416 KB |
Output is correct |
29 |
Correct |
29 ms |
3820 KB |
Output is correct |
30 |
Correct |
75 ms |
8396 KB |
Output is correct |
31 |
Correct |
135 ms |
13152 KB |
Output is correct |
32 |
Correct |
145 ms |
13152 KB |
Output is correct |
33 |
Correct |
129 ms |
13152 KB |
Output is correct |
34 |
Correct |
127 ms |
13152 KB |
Output is correct |
35 |
Correct |
148 ms |
13152 KB |
Output is correct |
36 |
Correct |
131 ms |
13152 KB |
Output is correct |
37 |
Correct |
125 ms |
13152 KB |
Output is correct |
38 |
Correct |
101 ms |
13152 KB |
Output is correct |
39 |
Correct |
102 ms |
13280 KB |
Output is correct |
40 |
Correct |
99 ms |
13152 KB |
Output is correct |
41 |
Correct |
104 ms |
13280 KB |
Output is correct |
42 |
Correct |
102 ms |
13152 KB |
Output is correct |
43 |
Correct |
106 ms |
13240 KB |
Output is correct |
44 |
Correct |
108 ms |
13136 KB |
Output is correct |
45 |
Correct |
113 ms |
13152 KB |
Output is correct |
46 |
Correct |
108 ms |
13152 KB |
Output is correct |
47 |
Correct |
466 ms |
40408 KB |
Output is correct |
48 |
Correct |
1665 ms |
123724 KB |
Output is correct |
49 |
Correct |
1810 ms |
134812 KB |
Output is correct |
50 |
Correct |
1763 ms |
134684 KB |
Output is correct |
51 |
Correct |
1939 ms |
134940 KB |
Output is correct |
52 |
Correct |
1804 ms |
134940 KB |
Output is correct |
53 |
Correct |
1860 ms |
134944 KB |
Output is correct |
54 |
Correct |
1756 ms |
134864 KB |
Output is correct |
55 |
Correct |
1789 ms |
134940 KB |
Output is correct |
56 |
Correct |
1714 ms |
134824 KB |
Output is correct |
57 |
Correct |
1766 ms |
134924 KB |
Output is correct |
58 |
Correct |
1654 ms |
134812 KB |
Output is correct |
59 |
Correct |
1623 ms |
133660 KB |
Output is correct |
60 |
Correct |
1566 ms |
133660 KB |
Output is correct |
61 |
Correct |
1551 ms |
133532 KB |
Output is correct |
62 |
Correct |
1525 ms |
133404 KB |
Output is correct |
63 |
Correct |
1568 ms |
133384 KB |
Output is correct |
64 |
Correct |
1542 ms |
133452 KB |
Output is correct |
65 |
Correct |
1436 ms |
133276 KB |
Output is correct |
66 |
Correct |
1431 ms |
133332 KB |
Output is correct |
67 |
Correct |
1457 ms |
133368 KB |
Output is correct |