답안 #969916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969916 2024-04-25T20:08:45 Z VMaksimoski008 Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 127384 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e6 + 5;
const double eps = 1e-9;

struct DSU {
    int n, comp;
    vector<int> par, size;

    void config(int _n) {
        n = _n + 1;
        comp = _n;
        par.resize(n+1);
        size.resize(n+1, 1);
        for(int i=1; i<=n; i++) par[i] = i;
    }

    int get(int u) {
        if(u == par[u]) return u;
        return par[u] = get(par[u]);
    }

    bool uni(int u, int v) {
        u = get(u), v = get(v);

        if(u == v) return false;
        if(size[u] < size[v]) swap(u, v);

        size[u] += size[v];
        par[v] = u;
        comp--;

        return true;
    }

    int getComp() { return comp; }
    int getSize(int u) { return size[get(u)]; }
    bool sameSet(int u, int v) { return get(u) == get(v); }
};

struct Query {
    int t, a, b, w;
    bool operator<(Query &e) {
        if(w == e.w) return (t < e.t);
        return w < e.w;
    }
};

ll C(ll x) {
    return x * (x - 1) / 2;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);
    
    int n, q, mn = 1e9;
    cin >> n >> q;

    vector<int> v(n);
    vector<Query> qus;

    for(int &x : v) cin >> x;

    for(int i=1; i<n; i++)
        qus.push_back({ 1, i-1, i, max(v[i], v[i-1]) });
    
    for(int i=0; i<q; i++) {
        int x;
        cin >> x;
        mn = min(mn, x);
        qus.push_back({ 2, i, i, x });
    }

    sort(all(qus));
    vector<ll> ans(q);
    ll res = 0;

    vector<int> mp[maxn+1];
    for(int i=0; i<n; i++) mp[v[i]].push_back(i);

    set<int> s;
    for(int &x : v) s.insert(x);
    vector<int> comp(all(s));

    int ptr = 0;
    DSU dsu; dsu.config(n);

    for(Query &qu : qus) {
        while(ptr < comp.size() && comp[ptr] <= qu.w) {
            for(int &p : mp[comp[ptr]]) res++;
            ptr++;
        }

        if(qu.t == 1) {
            if(dsu.sameSet(qu.a, qu.b)) continue;
            res -= C(dsu.getSize(qu.a));
            res -= C(dsu.getSize(qu.b));
            dsu.uni(qu.a, qu.b);
            res += C(dsu.getSize(qu.a));
        } else {
            ans[qu.a] = res;
        }
    }

    for(ll &x : ans) cout << x << '\n';
    return 0;
}

Compilation message

pilot.cpp: In function 'int32_t main()':
pilot.cpp:108:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         while(ptr < comp.size() && comp[ptr] <= qu.w) {
      |               ~~~~^~~~~~~~~~~~~
pilot.cpp:109:22: warning: unused variable 'p' [-Wunused-variable]
  109 |             for(int &p : mp[comp[ptr]]) res++;
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 16 ms 23932 KB Output is correct
13 Correct 15 ms 24152 KB Output is correct
14 Correct 15 ms 23900 KB Output is correct
15 Correct 15 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 16 ms 23932 KB Output is correct
13 Correct 15 ms 24152 KB Output is correct
14 Correct 15 ms 23900 KB Output is correct
15 Correct 15 ms 23900 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 16 ms 23900 KB Output is correct
19 Correct 15 ms 23896 KB Output is correct
20 Correct 15 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 16 ms 23932 KB Output is correct
13 Correct 15 ms 24152 KB Output is correct
14 Correct 15 ms 23900 KB Output is correct
15 Correct 15 ms 23900 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 16 ms 23900 KB Output is correct
19 Correct 15 ms 23896 KB Output is correct
20 Correct 15 ms 23900 KB Output is correct
21 Correct 16 ms 23896 KB Output is correct
22 Correct 16 ms 23956 KB Output is correct
23 Correct 16 ms 24276 KB Output is correct
24 Correct 15 ms 23896 KB Output is correct
25 Correct 15 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 31608 KB Output is correct
2 Correct 76 ms 34252 KB Output is correct
3 Correct 58 ms 31180 KB Output is correct
4 Correct 71 ms 33228 KB Output is correct
5 Correct 70 ms 31176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 37284 KB Output is correct
2 Correct 74 ms 37304 KB Output is correct
3 Correct 77 ms 37100 KB Output is correct
4 Correct 73 ms 37568 KB Output is correct
5 Correct 74 ms 37928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 37312 KB Output is correct
2 Correct 83 ms 37108 KB Output is correct
3 Correct 89 ms 37148 KB Output is correct
4 Correct 84 ms 38896 KB Output is correct
5 Correct 89 ms 37576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 58 ms 31608 KB Output is correct
12 Correct 76 ms 34252 KB Output is correct
13 Correct 58 ms 31180 KB Output is correct
14 Correct 71 ms 33228 KB Output is correct
15 Correct 70 ms 31176 KB Output is correct
16 Correct 58 ms 31176 KB Output is correct
17 Correct 88 ms 34192 KB Output is correct
18 Correct 77 ms 34244 KB Output is correct
19 Correct 57 ms 31044 KB Output is correct
20 Correct 76 ms 33884 KB Output is correct
21 Correct 57 ms 31172 KB Output is correct
22 Correct 78 ms 33628 KB Output is correct
23 Correct 62 ms 31692 KB Output is correct
24 Correct 75 ms 33484 KB Output is correct
25 Correct 60 ms 31440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 16 ms 23932 KB Output is correct
13 Correct 15 ms 24152 KB Output is correct
14 Correct 15 ms 23900 KB Output is correct
15 Correct 15 ms 23900 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 16 ms 23900 KB Output is correct
19 Correct 15 ms 23896 KB Output is correct
20 Correct 15 ms 23900 KB Output is correct
21 Correct 16 ms 23896 KB Output is correct
22 Correct 16 ms 23956 KB Output is correct
23 Correct 16 ms 24276 KB Output is correct
24 Correct 15 ms 23896 KB Output is correct
25 Correct 15 ms 23900 KB Output is correct
26 Correct 58 ms 31608 KB Output is correct
27 Correct 76 ms 34252 KB Output is correct
28 Correct 58 ms 31180 KB Output is correct
29 Correct 71 ms 33228 KB Output is correct
30 Correct 70 ms 31176 KB Output is correct
31 Correct 71 ms 37284 KB Output is correct
32 Correct 74 ms 37304 KB Output is correct
33 Correct 77 ms 37100 KB Output is correct
34 Correct 73 ms 37568 KB Output is correct
35 Correct 74 ms 37928 KB Output is correct
36 Correct 81 ms 37312 KB Output is correct
37 Correct 83 ms 37108 KB Output is correct
38 Correct 89 ms 37148 KB Output is correct
39 Correct 84 ms 38896 KB Output is correct
40 Correct 89 ms 37576 KB Output is correct
41 Correct 58 ms 31176 KB Output is correct
42 Correct 88 ms 34192 KB Output is correct
43 Correct 77 ms 34244 KB Output is correct
44 Correct 57 ms 31044 KB Output is correct
45 Correct 76 ms 33884 KB Output is correct
46 Correct 57 ms 31172 KB Output is correct
47 Correct 78 ms 33628 KB Output is correct
48 Correct 62 ms 31692 KB Output is correct
49 Correct 75 ms 33484 KB Output is correct
50 Correct 60 ms 31440 KB Output is correct
51 Correct 96 ms 34756 KB Output is correct
52 Correct 113 ms 36912 KB Output is correct
53 Correct 89 ms 35528 KB Output is correct
54 Correct 101 ms 37316 KB Output is correct
55 Correct 91 ms 34948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23900 KB Output is correct
2 Correct 14 ms 23908 KB Output is correct
3 Correct 16 ms 23900 KB Output is correct
4 Correct 15 ms 23900 KB Output is correct
5 Correct 14 ms 23900 KB Output is correct
6 Correct 15 ms 23900 KB Output is correct
7 Correct 15 ms 23876 KB Output is correct
8 Correct 15 ms 23900 KB Output is correct
9 Correct 14 ms 23728 KB Output is correct
10 Correct 14 ms 23936 KB Output is correct
11 Correct 15 ms 23900 KB Output is correct
12 Correct 16 ms 23932 KB Output is correct
13 Correct 15 ms 24152 KB Output is correct
14 Correct 15 ms 23900 KB Output is correct
15 Correct 15 ms 23900 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23960 KB Output is correct
18 Correct 16 ms 23900 KB Output is correct
19 Correct 15 ms 23896 KB Output is correct
20 Correct 15 ms 23900 KB Output is correct
21 Correct 16 ms 23896 KB Output is correct
22 Correct 16 ms 23956 KB Output is correct
23 Correct 16 ms 24276 KB Output is correct
24 Correct 15 ms 23896 KB Output is correct
25 Correct 15 ms 23900 KB Output is correct
26 Correct 58 ms 31608 KB Output is correct
27 Correct 76 ms 34252 KB Output is correct
28 Correct 58 ms 31180 KB Output is correct
29 Correct 71 ms 33228 KB Output is correct
30 Correct 70 ms 31176 KB Output is correct
31 Correct 71 ms 37284 KB Output is correct
32 Correct 74 ms 37304 KB Output is correct
33 Correct 77 ms 37100 KB Output is correct
34 Correct 73 ms 37568 KB Output is correct
35 Correct 74 ms 37928 KB Output is correct
36 Correct 81 ms 37312 KB Output is correct
37 Correct 83 ms 37108 KB Output is correct
38 Correct 89 ms 37148 KB Output is correct
39 Correct 84 ms 38896 KB Output is correct
40 Correct 89 ms 37576 KB Output is correct
41 Correct 58 ms 31176 KB Output is correct
42 Correct 88 ms 34192 KB Output is correct
43 Correct 77 ms 34244 KB Output is correct
44 Correct 57 ms 31044 KB Output is correct
45 Correct 76 ms 33884 KB Output is correct
46 Correct 57 ms 31172 KB Output is correct
47 Correct 78 ms 33628 KB Output is correct
48 Correct 62 ms 31692 KB Output is correct
49 Correct 75 ms 33484 KB Output is correct
50 Correct 60 ms 31440 KB Output is correct
51 Correct 96 ms 34756 KB Output is correct
52 Correct 113 ms 36912 KB Output is correct
53 Correct 89 ms 35528 KB Output is correct
54 Correct 101 ms 37316 KB Output is correct
55 Correct 91 ms 34948 KB Output is correct
56 Execution timed out 1020 ms 127384 KB Time limit exceeded
57 Halted 0 ms 0 KB -