Submission #964104

# Submission time Handle Problem Language Result Execution time Memory
964104 2024-04-16T10:27:22 Z Trisanu_Das Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1808 ms 54732 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using vi=vector<int>;
#define mp make_pair
#define lb lower_bound
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N=2e6+5;
vi a;
int seg[N], lzy[N];
vector<pair<int,int>> v;
 
void upd(int i, int j, int vv, int p=0, int l=1, int r=sz(v)){
    if(i>r or j<l) return;
    if(i<=l and r<=j){ seg[p]+=vv,lzy[p]+=vv; return; }
    int mid = (l+r)/2; int rp = p+2*(mid-l+1);
    if(i<=mid) upd(i,j,vv,p+1,l,mid);
    if(j>mid) upd(i,j,vv,rp,mid+1,r);
    seg[p] = max(seg[p+1],seg[rp])+lzy[p];
}
 
void add(int i, int x){
    int j = lb(all(v),mp(a[i],i))-begin(v);
    int j2 = lb(all(v),mp(a[i],-1))-begin(v);
    upd(j,j,i*x), upd(j2,sz(v),-x);
}
 
vi countScans(vi A, vi x, vi y){
    int n = sz(A), q = sz(x); vi ans; a.resize(n+1);
    for(int i = 1; i <= n; i++) a[i] = A[i - 1], v.pb({a[i],i});
    for(int i = 0; i < q; i++) v.pb({y[i], ++x[i]});
    sort(all(v)); v.erase(unique(all(v)),end(v));
    for(int i = 1; i <= n; i++) add(i,1);
    for(int i = 0; i < q; i++) 
      add(x[i], -1), a[x[i]] = y[i], add(x[i], 1),ans.pb(seg[0]);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2500 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 4 ms 2692 KB Output is correct
4 Correct 4 ms 2652 KB Output is correct
5 Correct 5 ms 2692 KB Output is correct
6 Correct 4 ms 2540 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 5 ms 2504 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 4 ms 2556 KB Output is correct
15 Correct 5 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 5 ms 2504 KB Output is correct
18 Correct 4 ms 2504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2500 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 4 ms 2692 KB Output is correct
4 Correct 4 ms 2652 KB Output is correct
5 Correct 5 ms 2692 KB Output is correct
6 Correct 4 ms 2540 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 5 ms 2504 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 4 ms 2556 KB Output is correct
15 Correct 5 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 5 ms 2504 KB Output is correct
18 Correct 4 ms 2504 KB Output is correct
19 Correct 13 ms 3164 KB Output is correct
20 Correct 15 ms 3296 KB Output is correct
21 Correct 14 ms 3160 KB Output is correct
22 Correct 18 ms 3164 KB Output is correct
23 Correct 13 ms 3164 KB Output is correct
24 Correct 14 ms 3176 KB Output is correct
25 Correct 15 ms 3248 KB Output is correct
26 Correct 14 ms 3272 KB Output is correct
27 Correct 13 ms 3140 KB Output is correct
28 Correct 13 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5336 KB Output is correct
2 Correct 57 ms 6604 KB Output is correct
3 Correct 105 ms 7880 KB Output is correct
4 Correct 107 ms 8116 KB Output is correct
5 Correct 102 ms 9924 KB Output is correct
6 Correct 95 ms 7984 KB Output is correct
7 Correct 102 ms 7944 KB Output is correct
8 Correct 103 ms 9892 KB Output is correct
9 Correct 94 ms 9880 KB Output is correct
10 Correct 82 ms 7768 KB Output is correct
11 Correct 84 ms 7740 KB Output is correct
12 Correct 84 ms 7928 KB Output is correct
13 Correct 88 ms 7892 KB Output is correct
14 Correct 86 ms 7864 KB Output is correct
15 Correct 79 ms 7896 KB Output is correct
16 Correct 71 ms 7732 KB Output is correct
17 Correct 71 ms 7744 KB Output is correct
18 Correct 71 ms 7712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2500 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 4 ms 2692 KB Output is correct
4 Correct 4 ms 2652 KB Output is correct
5 Correct 5 ms 2692 KB Output is correct
6 Correct 4 ms 2540 KB Output is correct
7 Correct 4 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 5 ms 2648 KB Output is correct
10 Correct 5 ms 2504 KB Output is correct
11 Correct 3 ms 2652 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 4 ms 2652 KB Output is correct
14 Correct 4 ms 2556 KB Output is correct
15 Correct 5 ms 2648 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 5 ms 2504 KB Output is correct
18 Correct 4 ms 2504 KB Output is correct
19 Correct 13 ms 3164 KB Output is correct
20 Correct 15 ms 3296 KB Output is correct
21 Correct 14 ms 3160 KB Output is correct
22 Correct 18 ms 3164 KB Output is correct
23 Correct 13 ms 3164 KB Output is correct
24 Correct 14 ms 3176 KB Output is correct
25 Correct 15 ms 3248 KB Output is correct
26 Correct 14 ms 3272 KB Output is correct
27 Correct 13 ms 3140 KB Output is correct
28 Correct 13 ms 3164 KB Output is correct
29 Correct 20 ms 5336 KB Output is correct
30 Correct 57 ms 6604 KB Output is correct
31 Correct 105 ms 7880 KB Output is correct
32 Correct 107 ms 8116 KB Output is correct
33 Correct 102 ms 9924 KB Output is correct
34 Correct 95 ms 7984 KB Output is correct
35 Correct 102 ms 7944 KB Output is correct
36 Correct 103 ms 9892 KB Output is correct
37 Correct 94 ms 9880 KB Output is correct
38 Correct 82 ms 7768 KB Output is correct
39 Correct 84 ms 7740 KB Output is correct
40 Correct 84 ms 7928 KB Output is correct
41 Correct 88 ms 7892 KB Output is correct
42 Correct 86 ms 7864 KB Output is correct
43 Correct 79 ms 7896 KB Output is correct
44 Correct 71 ms 7732 KB Output is correct
45 Correct 71 ms 7744 KB Output is correct
46 Correct 71 ms 7712 KB Output is correct
47 Correct 352 ms 20448 KB Output is correct
48 Correct 1628 ms 50932 KB Output is correct
49 Correct 1795 ms 54368 KB Output is correct
50 Correct 1775 ms 54464 KB Output is correct
51 Correct 1790 ms 54472 KB Output is correct
52 Correct 1808 ms 54324 KB Output is correct
53 Correct 1762 ms 54468 KB Output is correct
54 Correct 1642 ms 54584 KB Output is correct
55 Correct 1706 ms 54580 KB Output is correct
56 Correct 1602 ms 54732 KB Output is correct
57 Correct 1729 ms 54464 KB Output is correct
58 Correct 1658 ms 54528 KB Output is correct
59 Correct 1387 ms 51184 KB Output is correct
60 Correct 1414 ms 51180 KB Output is correct
61 Correct 1436 ms 51248 KB Output is correct
62 Correct 1283 ms 50076 KB Output is correct
63 Correct 1277 ms 50172 KB Output is correct
64 Correct 1379 ms 50188 KB Output is correct
65 Correct 1236 ms 50444 KB Output is correct
66 Correct 1252 ms 50328 KB Output is correct
67 Correct 1216 ms 50440 KB Output is correct