Submission #689779

# Submission time Handle Problem Language Result Execution time Memory
689779 2023-01-29T11:10:46 Z zeroesandones Pilot (NOI19_pilot) C++17
78 / 100
47 ms 3316 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

struct UFDS {
    vi link, sz;
    int n;

    UFDS(int N) {
        init(N);
    }

    void init(int N) {
        n = N;
        link = vi(n);
        iota(all(link), 0);
        sz = vi(n, 1);
    }

    ll find(ll x) {
        return (link[x] == x ? x : link[x] = find(link[x]));
    }

    void unite(ll a, ll b) {
        a = find(a);
        b = find(b);
        if(a == b) return;
        if(sz[a] < sz[b]) swap(a, b);

        sz[a] += sz[b];
        link[b] = a;
    }

    bool same(ll a, ll b){
        return (find(a) == find(b));
    }
};

const ll lim = 1e8;

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

void solve()
{
    ll n, q;
    cin >> n >> q;

    ll a[n];
    FOR(i, 0, n) {
        cin >> a[i];
    }


    if(n * q <= lim) {
        while(q--) {
            ll x;
            cin >> x;

            ll ans = 0;
            ll curr = 0;
            FOR(i, 0, n) {
                if(a[i] > x)
                    curr = 0;
                else
                    ++curr;
                ans += curr;
            }
            cout << ans << nl;
        }
        return;
    }

    while(q--) {
        ll x;
        cin >> x;

        ll len = upper_bound(a, a + n, x) - a;
        cout << c2(len + 1) << nl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 980 KB Output is correct
2 Correct 9 ms 1080 KB Output is correct
3 Correct 8 ms 1048 KB Output is correct
4 Correct 7 ms 1016 KB Output is correct
5 Correct 7 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2260 KB Output is correct
2 Correct 32 ms 3072 KB Output is correct
3 Correct 35 ms 3184 KB Output is correct
4 Correct 47 ms 3316 KB Output is correct
5 Correct 34 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2188 KB Output is correct
2 Correct 34 ms 3204 KB Output is correct
3 Correct 38 ms 3296 KB Output is correct
4 Correct 34 ms 3272 KB Output is correct
5 Correct 40 ms 3272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 7 ms 980 KB Output is correct
12 Correct 9 ms 1080 KB Output is correct
13 Correct 8 ms 1048 KB Output is correct
14 Correct 7 ms 1016 KB Output is correct
15 Correct 7 ms 980 KB Output is correct
16 Correct 7 ms 1040 KB Output is correct
17 Correct 8 ms 980 KB Output is correct
18 Correct 8 ms 1088 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 8 ms 980 KB Output is correct
21 Correct 7 ms 980 KB Output is correct
22 Correct 8 ms 980 KB Output is correct
23 Correct 8 ms 1096 KB Output is correct
24 Correct 7 ms 1032 KB Output is correct
25 Correct 7 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 7 ms 980 KB Output is correct
27 Correct 9 ms 1080 KB Output is correct
28 Correct 8 ms 1048 KB Output is correct
29 Correct 7 ms 1016 KB Output is correct
30 Correct 7 ms 980 KB Output is correct
31 Correct 29 ms 2260 KB Output is correct
32 Correct 32 ms 3072 KB Output is correct
33 Correct 35 ms 3184 KB Output is correct
34 Correct 47 ms 3316 KB Output is correct
35 Correct 34 ms 3020 KB Output is correct
36 Correct 34 ms 2188 KB Output is correct
37 Correct 34 ms 3204 KB Output is correct
38 Correct 38 ms 3296 KB Output is correct
39 Correct 34 ms 3272 KB Output is correct
40 Correct 40 ms 3272 KB Output is correct
41 Correct 7 ms 1040 KB Output is correct
42 Correct 8 ms 980 KB Output is correct
43 Correct 8 ms 1088 KB Output is correct
44 Correct 6 ms 980 KB Output is correct
45 Correct 8 ms 980 KB Output is correct
46 Correct 7 ms 980 KB Output is correct
47 Correct 8 ms 980 KB Output is correct
48 Correct 8 ms 1096 KB Output is correct
49 Correct 7 ms 1032 KB Output is correct
50 Correct 7 ms 980 KB Output is correct
51 Incorrect 33 ms 3224 KB Output isn't correct
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 7 ms 980 KB Output is correct
27 Correct 9 ms 1080 KB Output is correct
28 Correct 8 ms 1048 KB Output is correct
29 Correct 7 ms 1016 KB Output is correct
30 Correct 7 ms 980 KB Output is correct
31 Correct 29 ms 2260 KB Output is correct
32 Correct 32 ms 3072 KB Output is correct
33 Correct 35 ms 3184 KB Output is correct
34 Correct 47 ms 3316 KB Output is correct
35 Correct 34 ms 3020 KB Output is correct
36 Correct 34 ms 2188 KB Output is correct
37 Correct 34 ms 3204 KB Output is correct
38 Correct 38 ms 3296 KB Output is correct
39 Correct 34 ms 3272 KB Output is correct
40 Correct 40 ms 3272 KB Output is correct
41 Correct 7 ms 1040 KB Output is correct
42 Correct 8 ms 980 KB Output is correct
43 Correct 8 ms 1088 KB Output is correct
44 Correct 6 ms 980 KB Output is correct
45 Correct 8 ms 980 KB Output is correct
46 Correct 7 ms 980 KB Output is correct
47 Correct 8 ms 980 KB Output is correct
48 Correct 8 ms 1096 KB Output is correct
49 Correct 7 ms 1032 KB Output is correct
50 Correct 7 ms 980 KB Output is correct
51 Incorrect 33 ms 3224 KB Output isn't correct
52 Halted 0 ms 0 KB -