Submission #713704

# Submission time Handle Problem Language Result Execution time Memory
713704 2023-03-22T20:45:21 Z kkts Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2305 ms 58868 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int lz[4 * N], t[4 * N];
void push(int u, int l, int r) {
    t[u] += lz[u];
    if(l != r) lz[2 * u] += lz[u], lz[2 * u + 1] += lz[u];
    lz[u] = 0;
}
void upd(int u, int st, int en, int l, int r, int v) {
    if(lz[u]) push(u, l, r);
    if(l > en || r < st) return;
    if(st <= l && r <= en) {
        lz[u] = v;
        push(u, l, r);
        return;
    }
    int mid = (l + r) / 2;
    upd(2 * u, st, en, l, mid, v); upd(2 * u + 1, st, en, mid + 1, r, v);
    t[u] = max(t[2 * u], t[2 * u + 1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
    vector<pair<int,int>> v;
    for(int i = 0; i < A.size(); i++) {
        v.push_back({A[i], i});
    }
    for(int i = 0; i < X.size(); i++) {
        v.push_back({V[i], X[i]});
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int n = v.size();
    for(int i = 1; i <= 4 * n; i++) t[i] = -N;
    for(int i = 0; i < A.size(); i++) {
        int x = lower_bound(v.begin(), v.end(), make_pair(A[i], i)) - v.begin() + 1;
        upd(1, x, x, 1, n, +N + i);
        upd(1, x + 1, n,1, n, -1);
    }
    vector<int> ans(X.size());
    for(int i = 0; i < X.size(); i++) {
        int x = lower_bound(v.begin(), v.end(), make_pair(A[X[i]], X[i])) - v.begin() + 1;
        upd(1, x, x, 1, n, -X[i] - N);
        upd(1, x + 1, n, 1, n, 1);

        A[X[i]] = V[i];
        x = lower_bound(v.begin(), v.end(), make_pair(A[X[i]], X[i])) - v.begin() + 1;
        upd(1, x, x, 1, n, +N + X[i]);
        upd(1, x + 1, n, 1, n, -1); // cur_ID - act_ID unda iyos max

        ans[i] = t[1];
    }
    return ans;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < A.size(); i++) {
      |                    ~~^~~~~~~~~~
bubblesort2.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < X.size(); i++) {
      |                    ~~^~~~~~~~~~
bubblesort2.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 0; i < A.size(); i++) {
      |                    ~~^~~~~~~~~~
bubblesort2.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0; i < X.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 5 ms 524 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 420 KB Output is correct
9 Correct 6 ms 516 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 508 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 5 ms 524 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 420 KB Output is correct
9 Correct 6 ms 516 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 508 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 980 KB Output is correct
20 Correct 18 ms 1108 KB Output is correct
21 Correct 17 ms 1108 KB Output is correct
22 Correct 18 ms 1040 KB Output is correct
23 Correct 16 ms 1120 KB Output is correct
24 Correct 18 ms 1124 KB Output is correct
25 Correct 15 ms 980 KB Output is correct
26 Correct 15 ms 980 KB Output is correct
27 Correct 15 ms 980 KB Output is correct
28 Correct 17 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1636 KB Output is correct
2 Correct 78 ms 3052 KB Output is correct
3 Correct 143 ms 4960 KB Output is correct
4 Correct 127 ms 4980 KB Output is correct
5 Correct 124 ms 4928 KB Output is correct
6 Correct 142 ms 4896 KB Output is correct
7 Correct 123 ms 5008 KB Output is correct
8 Correct 134 ms 4956 KB Output is correct
9 Correct 139 ms 4932 KB Output is correct
10 Correct 102 ms 3820 KB Output is correct
11 Correct 94 ms 3776 KB Output is correct
12 Correct 99 ms 3704 KB Output is correct
13 Correct 107 ms 3776 KB Output is correct
14 Correct 120 ms 3716 KB Output is correct
15 Correct 97 ms 3836 KB Output is correct
16 Correct 93 ms 3836 KB Output is correct
17 Correct 98 ms 3772 KB Output is correct
18 Correct 96 ms 3728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 5 ms 524 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 420 KB Output is correct
9 Correct 6 ms 516 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 4 ms 512 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 508 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 980 KB Output is correct
20 Correct 18 ms 1108 KB Output is correct
21 Correct 17 ms 1108 KB Output is correct
22 Correct 18 ms 1040 KB Output is correct
23 Correct 16 ms 1120 KB Output is correct
24 Correct 18 ms 1124 KB Output is correct
25 Correct 15 ms 980 KB Output is correct
26 Correct 15 ms 980 KB Output is correct
27 Correct 15 ms 980 KB Output is correct
28 Correct 17 ms 980 KB Output is correct
29 Correct 23 ms 1636 KB Output is correct
30 Correct 78 ms 3052 KB Output is correct
31 Correct 143 ms 4960 KB Output is correct
32 Correct 127 ms 4980 KB Output is correct
33 Correct 124 ms 4928 KB Output is correct
34 Correct 142 ms 4896 KB Output is correct
35 Correct 123 ms 5008 KB Output is correct
36 Correct 134 ms 4956 KB Output is correct
37 Correct 139 ms 4932 KB Output is correct
38 Correct 102 ms 3820 KB Output is correct
39 Correct 94 ms 3776 KB Output is correct
40 Correct 99 ms 3704 KB Output is correct
41 Correct 107 ms 3776 KB Output is correct
42 Correct 120 ms 3716 KB Output is correct
43 Correct 97 ms 3836 KB Output is correct
44 Correct 93 ms 3836 KB Output is correct
45 Correct 98 ms 3772 KB Output is correct
46 Correct 96 ms 3728 KB Output is correct
47 Correct 454 ms 15344 KB Output is correct
48 Correct 2105 ms 42640 KB Output is correct
49 Correct 2234 ms 58560 KB Output is correct
50 Correct 2305 ms 58564 KB Output is correct
51 Correct 2154 ms 58568 KB Output is correct
52 Correct 2102 ms 58572 KB Output is correct
53 Correct 2137 ms 58568 KB Output is correct
54 Correct 1869 ms 58728 KB Output is correct
55 Correct 2098 ms 58868 KB Output is correct
56 Correct 1961 ms 58684 KB Output is correct
57 Correct 2093 ms 58744 KB Output is correct
58 Correct 1980 ms 58648 KB Output is correct
59 Correct 1726 ms 55564 KB Output is correct
60 Correct 1815 ms 55488 KB Output is correct
61 Correct 1708 ms 55544 KB Output is correct
62 Correct 1665 ms 54436 KB Output is correct
63 Correct 1568 ms 54300 KB Output is correct
64 Correct 1713 ms 54252 KB Output is correct
65 Correct 1602 ms 53212 KB Output is correct
66 Correct 1772 ms 53188 KB Output is correct
67 Correct 1498 ms 53212 KB Output is correct