Submission #713703

# Submission time Handle Problem Language Result Execution time Memory
713703 2023-03-22T20:44:36 Z kkts Bubble Sort 2 (JOI18_bubblesort2) C++14
60 / 100
495 ms 78124 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 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 4 ms 468 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 5 ms 560 KB Output is correct
7 Correct 4 ms 444 KB Output is correct
8 Correct 5 ms 448 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 5 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 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 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 4 ms 468 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 5 ms 560 KB Output is correct
7 Correct 4 ms 444 KB Output is correct
8 Correct 5 ms 448 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 5 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 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 1236 KB Output is correct
20 Correct 17 ms 1236 KB Output is correct
21 Correct 18 ms 1340 KB Output is correct
22 Correct 18 ms 1216 KB Output is correct
23 Correct 17 ms 1236 KB Output is correct
24 Correct 18 ms 1236 KB Output is correct
25 Correct 23 ms 1244 KB Output is correct
26 Correct 17 ms 1196 KB Output is correct
27 Correct 16 ms 1216 KB Output is correct
28 Correct 16 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1744 KB Output is correct
2 Correct 75 ms 3380 KB Output is correct
3 Correct 132 ms 5552 KB Output is correct
4 Correct 176 ms 5560 KB Output is correct
5 Correct 151 ms 5532 KB Output is correct
6 Correct 133 ms 5548 KB Output is correct
7 Correct 133 ms 5528 KB Output is correct
8 Correct 123 ms 5536 KB Output is correct
9 Correct 118 ms 5468 KB Output is correct
10 Correct 112 ms 4428 KB Output is correct
11 Correct 94 ms 4472 KB Output is correct
12 Correct 96 ms 4416 KB Output is correct
13 Correct 96 ms 4396 KB Output is correct
14 Correct 113 ms 4440 KB Output is correct
15 Correct 100 ms 4368 KB Output is correct
16 Correct 96 ms 4412 KB Output is correct
17 Correct 109 ms 4444 KB Output is correct
18 Correct 96 ms 4448 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 4 ms 468 KB Output is correct
4 Correct 4 ms 572 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 5 ms 560 KB Output is correct
7 Correct 4 ms 444 KB Output is correct
8 Correct 5 ms 448 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 5 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 468 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 1236 KB Output is correct
20 Correct 17 ms 1236 KB Output is correct
21 Correct 18 ms 1340 KB Output is correct
22 Correct 18 ms 1216 KB Output is correct
23 Correct 17 ms 1236 KB Output is correct
24 Correct 18 ms 1236 KB Output is correct
25 Correct 23 ms 1244 KB Output is correct
26 Correct 17 ms 1196 KB Output is correct
27 Correct 16 ms 1216 KB Output is correct
28 Correct 16 ms 1236 KB Output is correct
29 Correct 26 ms 1744 KB Output is correct
30 Correct 75 ms 3380 KB Output is correct
31 Correct 132 ms 5552 KB Output is correct
32 Correct 176 ms 5560 KB Output is correct
33 Correct 151 ms 5532 KB Output is correct
34 Correct 133 ms 5548 KB Output is correct
35 Correct 133 ms 5528 KB Output is correct
36 Correct 123 ms 5536 KB Output is correct
37 Correct 118 ms 5468 KB Output is correct
38 Correct 112 ms 4428 KB Output is correct
39 Correct 94 ms 4472 KB Output is correct
40 Correct 96 ms 4416 KB Output is correct
41 Correct 96 ms 4396 KB Output is correct
42 Correct 113 ms 4440 KB Output is correct
43 Correct 100 ms 4368 KB Output is correct
44 Correct 96 ms 4412 KB Output is correct
45 Correct 109 ms 4444 KB Output is correct
46 Correct 96 ms 4448 KB Output is correct
47 Correct 495 ms 19044 KB Output is correct
48 Runtime error 299 ms 78124 KB Execution killed with signal 11
49 Halted 0 ms 0 KB -