# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421444 |
2021-06-09T07:29:14 Z |
송준혁(#7507) |
Bubble Sort 2 (JOI18_bubblesort2) |
C++17 |
|
3277 ms |
57592 KB |
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M, Q;
int F[1010101];
int T[5050505], lz[5050505];
vector<pii> C;
vector<int> ans;
void busy(int id){
T[id*2] += lz[id], T[id*2+1] += lz[id];
lz[id*2] += lz[id], lz[id*2+1] += lz[id];
lz[id] = 0;
}
void upd(int id, int s, int e, int x, int v){
if (e <= x) return;
if (s > x){T[id] += v, lz[id] += v; return;}
int m=s+e>>1; busy(id);
upd(id*2, s, m, x, v);
upd(id*2+1, m+1, e, x, v);
T[id] = max(T[id*2], T[id*2+1]);
}
void setv(int id, int s, int e, int x, int v){
if (e < x || x < s) return;
if (s == e) {T[id] = v; return;}
int m=s+e>>1; busy(id);
setv(id*2, s, m, x, v);
setv(id*2+1, m+1, e, x, v);
T[id] = max(T[id*2], T[id*2+1]);
}
void up(int k, int v){k++;while(k<=M+1)F[k]+=v,k+=k&-k;}
int f(int k){int r=0;k++;while(k)r+=F[k],k^=k&-k;return r;}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
N=A.size(), Q=X.size();
for (int i=0; i<N; i++) C.pb(pii(A[i], i));
for (int i=0; i<Q; i++) C.pb(pii(V[i], X[i]));
sort(C.begin(), C.end());
C.erase(unique(C.begin(), C.end()), C.end());
M = C.size()-1;
upd(1, 0, M, -1, -2*N);
for (int i=0; i<N; i++){
int id = lb(C.begin(), C.end(), pii(A[i], i))-C.begin();
setv(1, 0, M, id, i-f(id));
upd(1, 0, M, id, -1);
up(id, 1);
}
for (int i=0; i<Q; i++){
int id = lb(C.begin(), C.end(), pii(A[X[i]], X[i]))-C.begin();
setv(1, 0, M, id, -2*N);
upd(1, 0, M, id, 1);
up(id, -1);
A[X[i]] = V[i];
id = lb(C.begin(), C.end(), pii(A[X[i]], X[i]))-C.begin();
setv(1, 0, M, id, X[i]-f(id));
upd(1, 0, M, id, -1);
up(id, 1);
ans.pb(T[1]);
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'void upd(int, int, int, int, int)':
bubblesort2.cpp:28:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int m=s+e>>1; busy(id);
| ~^~
bubblesort2.cpp: In function 'void setv(int, int, int, int, int)':
bubblesort2.cpp:37:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int m=s+e>>1; busy(id);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Correct |
19 ms |
1044 KB |
Output is correct |
20 |
Correct |
22 ms |
1084 KB |
Output is correct |
21 |
Correct |
23 ms |
1084 KB |
Output is correct |
22 |
Correct |
22 ms |
1084 KB |
Output is correct |
23 |
Correct |
21 ms |
1072 KB |
Output is correct |
24 |
Correct |
24 ms |
1136 KB |
Output is correct |
25 |
Correct |
23 ms |
972 KB |
Output is correct |
26 |
Correct |
20 ms |
1076 KB |
Output is correct |
27 |
Correct |
20 ms |
1052 KB |
Output is correct |
28 |
Correct |
21 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1480 KB |
Output is correct |
2 |
Correct |
98 ms |
2904 KB |
Output is correct |
3 |
Correct |
164 ms |
5700 KB |
Output is correct |
4 |
Correct |
164 ms |
5944 KB |
Output is correct |
5 |
Correct |
167 ms |
5640 KB |
Output is correct |
6 |
Correct |
174 ms |
5668 KB |
Output is correct |
7 |
Correct |
167 ms |
5688 KB |
Output is correct |
8 |
Correct |
166 ms |
5652 KB |
Output is correct |
9 |
Correct |
166 ms |
5816 KB |
Output is correct |
10 |
Correct |
138 ms |
4536 KB |
Output is correct |
11 |
Correct |
140 ms |
4576 KB |
Output is correct |
12 |
Correct |
140 ms |
4628 KB |
Output is correct |
13 |
Correct |
135 ms |
4648 KB |
Output is correct |
14 |
Correct |
137 ms |
4552 KB |
Output is correct |
15 |
Correct |
133 ms |
4532 KB |
Output is correct |
16 |
Correct |
126 ms |
4492 KB |
Output is correct |
17 |
Correct |
128 ms |
4536 KB |
Output is correct |
18 |
Correct |
131 ms |
4564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
5 ms |
508 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
5 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
460 KB |
Output is correct |
7 |
Correct |
5 ms |
460 KB |
Output is correct |
8 |
Correct |
5 ms |
460 KB |
Output is correct |
9 |
Correct |
5 ms |
460 KB |
Output is correct |
10 |
Correct |
5 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
460 KB |
Output is correct |
12 |
Correct |
5 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
460 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
460 KB |
Output is correct |
17 |
Correct |
6 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
460 KB |
Output is correct |
19 |
Correct |
19 ms |
1044 KB |
Output is correct |
20 |
Correct |
22 ms |
1084 KB |
Output is correct |
21 |
Correct |
23 ms |
1084 KB |
Output is correct |
22 |
Correct |
22 ms |
1084 KB |
Output is correct |
23 |
Correct |
21 ms |
1072 KB |
Output is correct |
24 |
Correct |
24 ms |
1136 KB |
Output is correct |
25 |
Correct |
23 ms |
972 KB |
Output is correct |
26 |
Correct |
20 ms |
1076 KB |
Output is correct |
27 |
Correct |
20 ms |
1052 KB |
Output is correct |
28 |
Correct |
21 ms |
1012 KB |
Output is correct |
29 |
Correct |
31 ms |
1480 KB |
Output is correct |
30 |
Correct |
98 ms |
2904 KB |
Output is correct |
31 |
Correct |
164 ms |
5700 KB |
Output is correct |
32 |
Correct |
164 ms |
5944 KB |
Output is correct |
33 |
Correct |
167 ms |
5640 KB |
Output is correct |
34 |
Correct |
174 ms |
5668 KB |
Output is correct |
35 |
Correct |
167 ms |
5688 KB |
Output is correct |
36 |
Correct |
166 ms |
5652 KB |
Output is correct |
37 |
Correct |
166 ms |
5816 KB |
Output is correct |
38 |
Correct |
138 ms |
4536 KB |
Output is correct |
39 |
Correct |
140 ms |
4576 KB |
Output is correct |
40 |
Correct |
140 ms |
4628 KB |
Output is correct |
41 |
Correct |
135 ms |
4648 KB |
Output is correct |
42 |
Correct |
137 ms |
4552 KB |
Output is correct |
43 |
Correct |
133 ms |
4532 KB |
Output is correct |
44 |
Correct |
126 ms |
4492 KB |
Output is correct |
45 |
Correct |
128 ms |
4536 KB |
Output is correct |
46 |
Correct |
131 ms |
4564 KB |
Output is correct |
47 |
Correct |
708 ms |
20692 KB |
Output is correct |
48 |
Correct |
2904 ms |
54184 KB |
Output is correct |
49 |
Correct |
3109 ms |
57128 KB |
Output is correct |
50 |
Correct |
3266 ms |
57068 KB |
Output is correct |
51 |
Correct |
3277 ms |
57104 KB |
Output is correct |
52 |
Correct |
3172 ms |
57100 KB |
Output is correct |
53 |
Correct |
3208 ms |
57180 KB |
Output is correct |
54 |
Correct |
2922 ms |
57476 KB |
Output is correct |
55 |
Correct |
2983 ms |
57592 KB |
Output is correct |
56 |
Correct |
2791 ms |
57348 KB |
Output is correct |
57 |
Correct |
2871 ms |
57352 KB |
Output is correct |
58 |
Correct |
2836 ms |
57372 KB |
Output is correct |
59 |
Correct |
2751 ms |
55452 KB |
Output is correct |
60 |
Correct |
2931 ms |
55416 KB |
Output is correct |
61 |
Correct |
2743 ms |
55356 KB |
Output is correct |
62 |
Correct |
2392 ms |
54968 KB |
Output is correct |
63 |
Correct |
2450 ms |
55116 KB |
Output is correct |
64 |
Correct |
2463 ms |
54988 KB |
Output is correct |
65 |
Correct |
2273 ms |
54696 KB |
Output is correct |
66 |
Correct |
2236 ms |
54664 KB |
Output is correct |
67 |
Correct |
2282 ms |
54756 KB |
Output is correct |