답안 #146219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146219 2019-08-22T20:51:41 Z nicolaalexandra Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2681 ms 61412 KB
#include <fstream>
#include <algorithm>
#include <vector>
#define DIM 1000010
#define INF 1000010
using namespace std;
 
pair <int,int> aint[4*DIM];
void lazy (int nod, int st, int dr){
    if (!aint[nod].second)
        return;
    aint[nod].first += aint[nod].second;
    if (st != dr){ /// nu e frunza
        aint[nod<<1].second += aint[nod].second;
        aint[(nod<<1)|1].second += aint[nod].second;
    }
    aint[nod].second = 0;
}
void update (int nod, int st, int dr, int x, int y, int val){
    lazy (nod,st,dr);
    if (st > dr || y < st || x > dr)
        return;
    if (x <= st && dr <= y){
        aint[nod].second += val;
        lazy (nod,st,dr);
        return;
    }
    int mid = (st+dr)>>1;
    update (nod<<1,st,mid,x,y,val);
    update ((nod<<1)|1,mid+1,dr,x,y,val);
    aint[nod].first = max (aint[nod<<1].first,aint[(nod<<1)|1].first);
}
inline int cautare_binara (long long v[], int n, long long val){
    int st = 1, dr = n;
    while (st <= dr){
        int mid = (st+dr)>>1;
        if (v[mid] < val)
            st = mid+1;
        else dr = mid-1;
    }
    return st;
}
vector <int> countScans (vector <int> a, vector <int> x, vector <int> v){
    int k = 0, n = a.size(), q = v.size();
    long long w[DIM*2],qry[DIM*2];
    vector <long long> A;
    for (int i=0;i<n;i++){
        A.push_back((long long)(1LL*a[i]*(n+1)+i)); /// fac asta ca sa obtin elemente distincte pe care dupa le normalizez
        w[++k] = A[i];
    }
    for (int i=0;i<q;i++){
        qry[i] = (long long)(1LL*v[i]*(n+1)+x[i]);
        w[++k] = qry[i];
    }
    sort (w+1,w+k+1);
    update (1,1,k,1,k,-INF); /// initializez cu -INF, apoi adaug INF+i
    /// starea initiala
    for (int i=0;i<n;i++){
        int val = cautare_binara(w,k,A[i]);
        update (1,1,k,val,val,INF+i); /// am i puncte mai mici decat el in stanga lui
        update (1,1,k,1,val,1);
    }
    vector <int> sol;
    for (int i=0;i<q;i++){
        int poz = cautare_binara (w,k,A[x[i]]);
        update (1,1,k,1,poz,-1);
        update (1,1,k,poz,poz,-INF-x[i]);
        A[x[i]] = qry[i];
 
        poz = cautare_binara (w,k,qry[i]);
        update (1,1,k,poz,poz,INF+x[i]);
        update (1,1,k,1,poz,1);
 
        sol.push_back(aint[1].first+aint[1].second - n);
    }
    return sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 8 ms 632 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 7 ms 664 KB Output is correct
8 Correct 7 ms 504 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 7 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 632 KB Output is correct
15 Correct 7 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 7 ms 636 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 8 ms 632 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 7 ms 664 KB Output is correct
8 Correct 7 ms 504 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 7 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 632 KB Output is correct
15 Correct 7 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 7 ms 636 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 21 ms 1272 KB Output is correct
20 Correct 24 ms 1316 KB Output is correct
21 Correct 23 ms 1272 KB Output is correct
22 Correct 23 ms 1272 KB Output is correct
23 Correct 23 ms 1272 KB Output is correct
24 Correct 22 ms 1272 KB Output is correct
25 Correct 22 ms 1272 KB Output is correct
26 Correct 22 ms 1272 KB Output is correct
27 Correct 21 ms 1272 KB Output is correct
28 Correct 21 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1652 KB Output is correct
2 Correct 91 ms 3220 KB Output is correct
3 Correct 174 ms 5596 KB Output is correct
4 Correct 167 ms 5564 KB Output is correct
5 Correct 167 ms 5600 KB Output is correct
6 Correct 162 ms 5616 KB Output is correct
7 Correct 165 ms 5688 KB Output is correct
8 Correct 165 ms 5564 KB Output is correct
9 Correct 162 ms 5616 KB Output is correct
10 Correct 138 ms 5524 KB Output is correct
11 Correct 139 ms 5616 KB Output is correct
12 Correct 138 ms 5540 KB Output is correct
13 Correct 137 ms 5544 KB Output is correct
14 Correct 136 ms 5544 KB Output is correct
15 Correct 133 ms 5572 KB Output is correct
16 Correct 128 ms 5636 KB Output is correct
17 Correct 129 ms 5616 KB Output is correct
18 Correct 130 ms 5616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 7 ms 508 KB Output is correct
4 Correct 8 ms 632 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 7 ms 664 KB Output is correct
8 Correct 7 ms 504 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 7 ms 632 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 632 KB Output is correct
15 Correct 7 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 7 ms 636 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 21 ms 1272 KB Output is correct
20 Correct 24 ms 1316 KB Output is correct
21 Correct 23 ms 1272 KB Output is correct
22 Correct 23 ms 1272 KB Output is correct
23 Correct 23 ms 1272 KB Output is correct
24 Correct 22 ms 1272 KB Output is correct
25 Correct 22 ms 1272 KB Output is correct
26 Correct 22 ms 1272 KB Output is correct
27 Correct 21 ms 1272 KB Output is correct
28 Correct 21 ms 1272 KB Output is correct
29 Correct 30 ms 1652 KB Output is correct
30 Correct 91 ms 3220 KB Output is correct
31 Correct 174 ms 5596 KB Output is correct
32 Correct 167 ms 5564 KB Output is correct
33 Correct 167 ms 5600 KB Output is correct
34 Correct 162 ms 5616 KB Output is correct
35 Correct 165 ms 5688 KB Output is correct
36 Correct 165 ms 5564 KB Output is correct
37 Correct 162 ms 5616 KB Output is correct
38 Correct 138 ms 5524 KB Output is correct
39 Correct 139 ms 5616 KB Output is correct
40 Correct 138 ms 5540 KB Output is correct
41 Correct 137 ms 5544 KB Output is correct
42 Correct 136 ms 5544 KB Output is correct
43 Correct 133 ms 5572 KB Output is correct
44 Correct 128 ms 5636 KB Output is correct
45 Correct 129 ms 5616 KB Output is correct
46 Correct 130 ms 5616 KB Output is correct
47 Correct 631 ms 21924 KB Output is correct
48 Correct 2637 ms 57952 KB Output is correct
49 Correct 2622 ms 61192 KB Output is correct
50 Correct 2626 ms 61140 KB Output is correct
51 Correct 2660 ms 61124 KB Output is correct
52 Correct 2661 ms 61008 KB Output is correct
53 Correct 2681 ms 61212 KB Output is correct
54 Correct 2445 ms 61268 KB Output is correct
55 Correct 2676 ms 61300 KB Output is correct
56 Correct 2449 ms 61412 KB Output is correct
57 Correct 2610 ms 61408 KB Output is correct
58 Correct 2438 ms 61308 KB Output is correct
59 Correct 2290 ms 59972 KB Output is correct
60 Correct 2233 ms 60004 KB Output is correct
61 Correct 2267 ms 59996 KB Output is correct
62 Correct 2276 ms 59796 KB Output is correct
63 Correct 2241 ms 59784 KB Output is correct
64 Correct 2275 ms 59816 KB Output is correct
65 Correct 2000 ms 59756 KB Output is correct
66 Correct 2005 ms 59788 KB Output is correct
67 Correct 2021 ms 59864 KB Output is correct