답안 #462286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
462286 2021-08-10T10:02:16 Z Killer2501 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2996 ms 153208 KB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back

const int N = 1e6+5;
const ll mod = 998244353;
const int base = 300;

ll m, n, t, k, d[N], a[N], b[N], c[N], ans, tong, st[N*4], lazy[N*4], fe[N], sz;
vector<pll> adj[N];
vector<ll> kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
ll lwr(ll x)
{
    return lower_bound(kq.begin(), kq.end(), x) - kq.begin() + 1;
}
string s;
void add(ll id, ll x)
{
    for(; id <= sz; id += id & -id)fe[id] += x;
}
ll get(ll id)
{
    ll total = 0;
    for(; id; id -= id & -id)total += fe[id];
    return total;
}
set<ll> val[N];
void down(ll id)
{
    if(!lazy[id])return;
    st[id*2] += lazy[id];
    st[id*2+1] += lazy[id];
    lazy[id*2] += lazy[id];
    lazy[id*2+1] += lazy[id];
    lazy[id] = 0;
}
void update(ll id, ll l, ll r, ll u, ll v, ll x)
{
    if(u <= l && r <= v)
    {
        if(u == v)st[id] = x;
        else
        {
            st[id] += x;
            lazy[id] += x;
        }
        return;
    }
    if(u > v || u > r || l > v)return;
    ll mid = (l + r) / 2;
    down(id);
    update(id*2, l, mid, u, v, x);
    update(id*2+1, mid+1, r, u, v, x);
    st[id] = max(st[id*2], st[id*2+1]);
}
void cal(ll x)
{
    if(val[x].empty())update(1, 1, sz, x, x, -mod);
    else
    {
        k = (*val[x].rbegin()) - get(x);
        update(1, 1, sz, x, x, k);
    }
}
vector<ll> countScans(vector<ll> A, vector<ll> X, vector<ll> V)
{
    //cin >> n >> m;
    n = A.size();
    m = X.size();
    for(int i = 1; i <= n; i ++)
    {
        a[i] = A[i-1];
        //cin >> a[i];
        kq.pb(a[i]);
    }
    for(int i = 1; i <= m; i ++)
    {
        b[i] = X[i-1] + 1;
        c[i] = V[i-1];
        //cin >> b[i] >> c[i];
        kq.pb(c[i]);
    }
    sort(kq.begin(), kq.end());
    kq.erase(unique(kq.begin(), kq.end()), kq.end());
    sz = kq.size();
    for(int i = 1; i <= n; i ++)
    {
        a[i] = lwr(a[i]);
        add(a[i], 1);
        val[a[i]].insert(i);
    }
    for(int i = 1; i <= m; i ++)c[i] = lwr(c[i]);
    for(int i = 1; i <= n; i ++)
    {
        k = (*val[a[i]].rbegin()) - get(a[i]);
        update(1, 1, sz, a[i], a[i], k);
    }
    vector<ll> res;
    for(int i = 1; i <= m; i ++)
    {
        val[a[b[i]]].erase(b[i]);
        val[c[i]].insert(b[i]);
        add(a[b[i]], -1);
        add(c[i], 1);
        update(1, 1, sz, a[b[i]]+1, sz, 1);
        update(1, 1, sz, c[i]+1, sz, -1);
        cal(a[b[i]]);
        cal(c[i]);
        a[b[i]] = c[i];
        //cout << st[1] << '\n';
        res.pb(st[1]);
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 70852 KB Output is correct
2 Correct 42 ms 70884 KB Output is correct
3 Correct 46 ms 71004 KB Output is correct
4 Correct 45 ms 71004 KB Output is correct
5 Correct 45 ms 70984 KB Output is correct
6 Correct 49 ms 71044 KB Output is correct
7 Correct 43 ms 71040 KB Output is correct
8 Correct 46 ms 70980 KB Output is correct
9 Correct 44 ms 71048 KB Output is correct
10 Correct 44 ms 70968 KB Output is correct
11 Correct 44 ms 70980 KB Output is correct
12 Correct 43 ms 71116 KB Output is correct
13 Correct 44 ms 71020 KB Output is correct
14 Correct 44 ms 70980 KB Output is correct
15 Correct 47 ms 71012 KB Output is correct
16 Correct 46 ms 71004 KB Output is correct
17 Correct 44 ms 70980 KB Output is correct
18 Correct 49 ms 71052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 70852 KB Output is correct
2 Correct 42 ms 70884 KB Output is correct
3 Correct 46 ms 71004 KB Output is correct
4 Correct 45 ms 71004 KB Output is correct
5 Correct 45 ms 70984 KB Output is correct
6 Correct 49 ms 71044 KB Output is correct
7 Correct 43 ms 71040 KB Output is correct
8 Correct 46 ms 70980 KB Output is correct
9 Correct 44 ms 71048 KB Output is correct
10 Correct 44 ms 70968 KB Output is correct
11 Correct 44 ms 70980 KB Output is correct
12 Correct 43 ms 71116 KB Output is correct
13 Correct 44 ms 71020 KB Output is correct
14 Correct 44 ms 70980 KB Output is correct
15 Correct 47 ms 71012 KB Output is correct
16 Correct 46 ms 71004 KB Output is correct
17 Correct 44 ms 70980 KB Output is correct
18 Correct 49 ms 71052 KB Output is correct
19 Correct 58 ms 71916 KB Output is correct
20 Correct 60 ms 72004 KB Output is correct
21 Correct 60 ms 72076 KB Output is correct
22 Correct 62 ms 72068 KB Output is correct
23 Correct 62 ms 72004 KB Output is correct
24 Correct 60 ms 72060 KB Output is correct
25 Correct 59 ms 72044 KB Output is correct
26 Correct 68 ms 72020 KB Output is correct
27 Correct 68 ms 72040 KB Output is correct
28 Correct 62 ms 71988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 72512 KB Output is correct
2 Correct 96 ms 74496 KB Output is correct
3 Correct 155 ms 76272 KB Output is correct
4 Correct 144 ms 76300 KB Output is correct
5 Correct 147 ms 76324 KB Output is correct
6 Correct 146 ms 76304 KB Output is correct
7 Correct 135 ms 76236 KB Output is correct
8 Correct 139 ms 76288 KB Output is correct
9 Correct 146 ms 76220 KB Output is correct
10 Correct 126 ms 76324 KB Output is correct
11 Correct 141 ms 76376 KB Output is correct
12 Correct 119 ms 76404 KB Output is correct
13 Correct 116 ms 76332 KB Output is correct
14 Correct 124 ms 76380 KB Output is correct
15 Correct 115 ms 76264 KB Output is correct
16 Correct 118 ms 76384 KB Output is correct
17 Correct 114 ms 76376 KB Output is correct
18 Correct 115 ms 76384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 70852 KB Output is correct
2 Correct 42 ms 70884 KB Output is correct
3 Correct 46 ms 71004 KB Output is correct
4 Correct 45 ms 71004 KB Output is correct
5 Correct 45 ms 70984 KB Output is correct
6 Correct 49 ms 71044 KB Output is correct
7 Correct 43 ms 71040 KB Output is correct
8 Correct 46 ms 70980 KB Output is correct
9 Correct 44 ms 71048 KB Output is correct
10 Correct 44 ms 70968 KB Output is correct
11 Correct 44 ms 70980 KB Output is correct
12 Correct 43 ms 71116 KB Output is correct
13 Correct 44 ms 71020 KB Output is correct
14 Correct 44 ms 70980 KB Output is correct
15 Correct 47 ms 71012 KB Output is correct
16 Correct 46 ms 71004 KB Output is correct
17 Correct 44 ms 70980 KB Output is correct
18 Correct 49 ms 71052 KB Output is correct
19 Correct 58 ms 71916 KB Output is correct
20 Correct 60 ms 72004 KB Output is correct
21 Correct 60 ms 72076 KB Output is correct
22 Correct 62 ms 72068 KB Output is correct
23 Correct 62 ms 72004 KB Output is correct
24 Correct 60 ms 72060 KB Output is correct
25 Correct 59 ms 72044 KB Output is correct
26 Correct 68 ms 72020 KB Output is correct
27 Correct 68 ms 72040 KB Output is correct
28 Correct 62 ms 71988 KB Output is correct
29 Correct 59 ms 72512 KB Output is correct
30 Correct 96 ms 74496 KB Output is correct
31 Correct 155 ms 76272 KB Output is correct
32 Correct 144 ms 76300 KB Output is correct
33 Correct 147 ms 76324 KB Output is correct
34 Correct 146 ms 76304 KB Output is correct
35 Correct 135 ms 76236 KB Output is correct
36 Correct 139 ms 76288 KB Output is correct
37 Correct 146 ms 76220 KB Output is correct
38 Correct 126 ms 76324 KB Output is correct
39 Correct 141 ms 76376 KB Output is correct
40 Correct 119 ms 76404 KB Output is correct
41 Correct 116 ms 76332 KB Output is correct
42 Correct 124 ms 76380 KB Output is correct
43 Correct 115 ms 76264 KB Output is correct
44 Correct 118 ms 76384 KB Output is correct
45 Correct 114 ms 76376 KB Output is correct
46 Correct 115 ms 76384 KB Output is correct
47 Correct 763 ms 99196 KB Output is correct
48 Correct 2754 ms 146716 KB Output is correct
49 Correct 2996 ms 153020 KB Output is correct
50 Correct 2953 ms 153076 KB Output is correct
51 Correct 2845 ms 153040 KB Output is correct
52 Correct 2957 ms 152996 KB Output is correct
53 Correct 2864 ms 152928 KB Output is correct
54 Correct 2609 ms 153196 KB Output is correct
55 Correct 2813 ms 153208 KB Output is correct
56 Correct 2705 ms 153176 KB Output is correct
57 Correct 2946 ms 153144 KB Output is correct
58 Correct 2959 ms 153152 KB Output is correct
59 Correct 2588 ms 151268 KB Output is correct
60 Correct 2473 ms 151364 KB Output is correct
61 Correct 2496 ms 151364 KB Output is correct
62 Correct 2401 ms 150992 KB Output is correct
63 Correct 2269 ms 151100 KB Output is correct
64 Correct 2352 ms 150984 KB Output is correct
65 Correct 2096 ms 150576 KB Output is correct
66 Correct 2143 ms 150588 KB Output is correct
67 Correct 2166 ms 150572 KB Output is correct