답안 #392080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392080 2021-04-20T12:27:49 Z muhammad_hokimiyon Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
72 ms 2748 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000500;

int G;
int a[maxn];
int t[4 * maxn];
int lz[4 * maxn];

void push(int x)
{
    lz[x + x] += lz[x];
    lz[x + x + 1] += lz[x];
    t[x + x] += lz[x];
    t[x + x + 1] += lz[x];
    lz[x] = 0;
}

void upd(int x, int l, int r, int p, int val)
{
    if(l == r){
        t[x] += val;
        return;
    }
    push(x);
    int m = (l + r) / 2;
    if(p <= m)upd(x + x, l, m, p, val);
    else upd(x + x + 1, m + 1, r, p, val);
    t[x] = max(t[x + x], t[x + x + 1]);
}

void upd(int x, int l, int r, int tl, int tr, int val)
{
    if(tl > tr)return;
    if(l == tl && r == tr){
        t[x] += val;
        lz[x] += val;
        return;
    }
    int m = (l + r) / 2;
    push(x);
    upd(x + x, l, m, tl, min(tr, m), val);
    upd(x + x + 1, m + 1, r, max(tl, m + 1), tr, val);
    t[x] = max(t[x + x], t[x + x + 1]);
}

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	int Q=X.size();
	vector<int> answer;
	int n = (int)A.size();
	vector<pair<int, int>> g;
	for(int i = 0; i < Q; i++){
        g.push_back({V[i], -(i + 1)});
	}
	for(int i = 0; i < n; i++){
        g.push_back({A[i], i});
	}
	map<int, int> m;
	sort(g.begin(), g.end());
	for(int i = 0; i < (int)g.size(); i++){
        if(g[i].second >= 0){
            A[g[i].second] = ++G;
        }else{
            V[-g[i].second - 1] = ++G;
        }
	}
	for(int i = 0; i < n; i++){
        upd(1, 1, G, A[i], G, -1);
        upd(1, 1, G, A[i], i);
	}
    for(int i = 0; i < Q; i++){
        upd(1, 1, G, A[X[i]], -X[i]);
        upd(1, 1, G, A[X[i]], G, 1);
        A[X[i]] = V[i];
        upd(1, 1, G, A[X[i]], X[i]);
        upd(1, 1, G, A[X[i]], G, -1);
        answer.push_back(max(0, t[1] + 1));
    }
    return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 484 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 484 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 5 ms 460 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 484 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 484 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 5 ms 460 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 16 ms 896 KB Output is correct
20 Correct 18 ms 972 KB Output is correct
21 Correct 17 ms 972 KB Output is correct
22 Correct 18 ms 972 KB Output is correct
23 Correct 18 ms 972 KB Output is correct
24 Correct 17 ms 972 KB Output is correct
25 Correct 17 ms 972 KB Output is correct
26 Correct 19 ms 1000 KB Output is correct
27 Correct 17 ms 932 KB Output is correct
28 Correct 17 ms 904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1352 KB Output is correct
2 Incorrect 72 ms 2748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 484 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 484 KB Output is correct
8 Correct 4 ms 460 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 5 ms 460 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 16 ms 896 KB Output is correct
20 Correct 18 ms 972 KB Output is correct
21 Correct 17 ms 972 KB Output is correct
22 Correct 18 ms 972 KB Output is correct
23 Correct 18 ms 972 KB Output is correct
24 Correct 17 ms 972 KB Output is correct
25 Correct 17 ms 972 KB Output is correct
26 Correct 19 ms 1000 KB Output is correct
27 Correct 17 ms 932 KB Output is correct
28 Correct 17 ms 904 KB Output is correct
29 Correct 24 ms 1352 KB Output is correct
30 Incorrect 72 ms 2748 KB Output isn't correct
31 Halted 0 ms 0 KB -