Submission #160266

# Submission time Handle Problem Language Result Execution time Memory
160266 2019-10-26T16:05:17 Z combi1k1 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
1989 ms 52948 KB
#include<bits/stdc++.h>

using namespace std;

#define X       first
#define Y       second
#define pb      push_back

#define FOR(i,a,b)      for(int i = a ; i < b ; ++i)

const int   N   = 1e6 + 1;
const int   inf = 1e9 + 1;

typedef pair<int,int>   ii;
typedef vector<int>     arr;

int tr[N << 1];
int lz[N << 1];

void app(int i,int v)   {
    tr[i] += v;
    lz[i] += v;
}
void upd(int l,int r,int v) {
    l += N - 1;
    r += N;
    int L = l;
    int R = r - 1;

    for(; l < r ; l >>= 1, r >>= 1) {
        if (l & 1)  app(l++,v);
        if (r & 1)  app(--r,v);
    }
    for(; L > 1 ; L >>= 1)  tr[L >> 1] = max(tr[L],tr[L ^ 1]) + lz[L >> 1];
    for(; R > 1 ; R >>= 1)  tr[R >> 1] = max(tr[R],tr[R ^ 1]) + lz[R >> 1];
}

arr countScans(arr a,arr p,arr x)   {
    int n = a.size();
    int q = p.size();

    vector<ii>  val;

    FOR(i,0,n)  val.pb(ii(a[i],i));
    FOR(i,0,q)  val.pb(ii(x[i],p[i]));

    sort(val.begin(),val.end());
    val.erase(unique(val.begin(),val.end()),val.end());

    int m = val.size();

    auto add = [&](int P)   {
        int p = lower_bound(val.begin(),val.end(),ii(a[P],P)) - val.begin() + 1;
        upd(p,m,-1);
        upd(p,p, P + 1);
    };
    auto rem = [&](int P)   {
        int p = lower_bound(val.begin(),val.end(),ii(a[P],P)) - val.begin() + 1;
        upd(p,m, 1);
        upd(p,p,-P - 1);
    };

    vector<int> res;

    FOR(i,0,n)  add(i);
    FOR(i,0,q)  {
        rem(p[i]);  a[p[i]] = x[i];
        add(p[i]);  res.push_back(tr[1]);
    }

    return  res;
}

/*int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    arr v = countScans({1,2,3,4},{0,2},{3,1});

    for(int x : v)  cout << x << " ";
}*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 632 KB Output is correct
19 Correct 16 ms 1180 KB Output is correct
20 Correct 22 ms 1400 KB Output is correct
21 Correct 19 ms 1272 KB Output is correct
22 Correct 18 ms 1272 KB Output is correct
23 Correct 17 ms 1276 KB Output is correct
24 Correct 16 ms 1272 KB Output is correct
25 Correct 17 ms 1272 KB Output is correct
26 Correct 16 ms 1272 KB Output is correct
27 Correct 16 ms 1144 KB Output is correct
28 Correct 16 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1524 KB Output is correct
2 Correct 64 ms 3196 KB Output is correct
3 Correct 113 ms 4980 KB Output is correct
4 Correct 110 ms 5028 KB Output is correct
5 Correct 111 ms 5084 KB Output is correct
6 Correct 112 ms 4900 KB Output is correct
7 Correct 115 ms 5220 KB Output is correct
8 Correct 108 ms 4972 KB Output is correct
9 Correct 110 ms 5012 KB Output is correct
10 Correct 92 ms 4332 KB Output is correct
11 Correct 88 ms 4308 KB Output is correct
12 Correct 88 ms 4332 KB Output is correct
13 Correct 87 ms 4460 KB Output is correct
14 Correct 85 ms 4332 KB Output is correct
15 Correct 85 ms 4464 KB Output is correct
16 Correct 81 ms 4332 KB Output is correct
17 Correct 80 ms 4332 KB Output is correct
18 Correct 80 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 632 KB Output is correct
19 Correct 16 ms 1180 KB Output is correct
20 Correct 22 ms 1400 KB Output is correct
21 Correct 19 ms 1272 KB Output is correct
22 Correct 18 ms 1272 KB Output is correct
23 Correct 17 ms 1276 KB Output is correct
24 Correct 16 ms 1272 KB Output is correct
25 Correct 17 ms 1272 KB Output is correct
26 Correct 16 ms 1272 KB Output is correct
27 Correct 16 ms 1144 KB Output is correct
28 Correct 16 ms 1144 KB Output is correct
29 Correct 21 ms 1524 KB Output is correct
30 Correct 64 ms 3196 KB Output is correct
31 Correct 113 ms 4980 KB Output is correct
32 Correct 110 ms 5028 KB Output is correct
33 Correct 111 ms 5084 KB Output is correct
34 Correct 112 ms 4900 KB Output is correct
35 Correct 115 ms 5220 KB Output is correct
36 Correct 108 ms 4972 KB Output is correct
37 Correct 110 ms 5012 KB Output is correct
38 Correct 92 ms 4332 KB Output is correct
39 Correct 88 ms 4308 KB Output is correct
40 Correct 88 ms 4332 KB Output is correct
41 Correct 87 ms 4460 KB Output is correct
42 Correct 85 ms 4332 KB Output is correct
43 Correct 85 ms 4464 KB Output is correct
44 Correct 81 ms 4332 KB Output is correct
45 Correct 80 ms 4332 KB Output is correct
46 Correct 80 ms 4332 KB Output is correct
47 Correct 420 ms 16264 KB Output is correct
48 Correct 1743 ms 48720 KB Output is correct
49 Correct 1966 ms 52768 KB Output is correct
50 Correct 1989 ms 52692 KB Output is correct
51 Correct 1898 ms 52580 KB Output is correct
52 Correct 1926 ms 52576 KB Output is correct
53 Correct 1866 ms 52820 KB Output is correct
54 Correct 1620 ms 52820 KB Output is correct
55 Correct 1820 ms 52820 KB Output is correct
56 Correct 1624 ms 52760 KB Output is correct
57 Correct 1761 ms 52820 KB Output is correct
58 Correct 1645 ms 52948 KB Output is correct
59 Correct 1515 ms 49492 KB Output is correct
60 Correct 1498 ms 49492 KB Output is correct
61 Correct 1655 ms 49620 KB Output is correct
62 Correct 1469 ms 48480 KB Output is correct
63 Correct 1467 ms 48348 KB Output is correct
64 Correct 1468 ms 48484 KB Output is correct
65 Correct 1337 ms 47332 KB Output is correct
66 Correct 1370 ms 47316 KB Output is correct
67 Correct 1359 ms 47316 KB Output is correct