Submission #572408

# Submission time Handle Problem Language Result Execution time Memory
572408 2022-06-04T10:40:42 Z MODDI Pilot (NOI19_pilot) C++14
100 / 100
723 ms 89792 KB
#include <bits/stdc++.h>
#define int ll
using namespace std;
 
#define ll long long
#define f first
#define s second
#define pii pair<int, int>
 
#define MX(a,b) a=max(a,b)
#define MN(a,b) a=min(a,b)
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
 
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define pb push_back
 
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
 
const int maxn = 1e6+5;
 
int par[maxn];
int sz[maxn];
bool on[maxn];
 
ll re = 0;
int find(int x) {return x == par[x]?x:par[x] = find(par[x]);}
void mrg(int a, int b) {
    a = find(a); b = find(b);
    if (a == b) return;
    re -= sz[a] * (sz[a]+1) / 2;
    re -= sz[b] * (sz[b]+1) / 2;
    sz[a] += sz[b];
    re += sz[a] * (sz[a]+1) / 2;
    par[b] = a;
}
vector<int> yay[maxn];
ll ans[maxn];
signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    bug(1,2);
 
    int n,q; cin>>n>>q;
    REP(i,n) par[i] = i, sz[i] = 1;
    REP(i,n) {
        int a; cin>>a; yay[a].pb(i);
    }
    REP1(i, 1000000) {
        for (int x : yay[i]) {
            ++re;
            on[x] = 1;
            if (x && on[x-1]) mrg(x, x-1);
            if (x!=n-1 && on[x+1]) mrg(x, x+1);
        }
        ans[i] = re;
    }
 
    REP(i,q) {
        int x; cin>>x;
        cout<<ans[x]<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 17 ms 31572 KB Output is correct
13 Correct 17 ms 31612 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 17 ms 31600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 17 ms 31572 KB Output is correct
13 Correct 17 ms 31612 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 17 ms 31600 KB Output is correct
16 Correct 17 ms 31596 KB Output is correct
17 Correct 16 ms 31572 KB Output is correct
18 Correct 17 ms 31572 KB Output is correct
19 Correct 17 ms 31572 KB Output is correct
20 Correct 16 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 17 ms 31572 KB Output is correct
13 Correct 17 ms 31612 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 17 ms 31600 KB Output is correct
16 Correct 17 ms 31596 KB Output is correct
17 Correct 16 ms 31572 KB Output is correct
18 Correct 17 ms 31572 KB Output is correct
19 Correct 17 ms 31572 KB Output is correct
20 Correct 16 ms 31572 KB Output is correct
21 Correct 16 ms 31572 KB Output is correct
22 Correct 17 ms 31624 KB Output is correct
23 Correct 17 ms 31572 KB Output is correct
24 Correct 16 ms 31688 KB Output is correct
25 Correct 18 ms 31580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 35280 KB Output is correct
2 Correct 69 ms 36100 KB Output is correct
3 Correct 50 ms 35100 KB Output is correct
4 Correct 50 ms 35744 KB Output is correct
5 Correct 42 ms 35080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 37008 KB Output is correct
2 Correct 46 ms 37124 KB Output is correct
3 Correct 57 ms 36952 KB Output is correct
4 Correct 50 ms 37196 KB Output is correct
5 Correct 50 ms 36880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 37160 KB Output is correct
2 Correct 51 ms 36948 KB Output is correct
3 Correct 65 ms 36892 KB Output is correct
4 Correct 57 ms 37324 KB Output is correct
5 Correct 54 ms 37104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 41 ms 35280 KB Output is correct
12 Correct 69 ms 36100 KB Output is correct
13 Correct 50 ms 35100 KB Output is correct
14 Correct 50 ms 35744 KB Output is correct
15 Correct 42 ms 35080 KB Output is correct
16 Correct 39 ms 35016 KB Output is correct
17 Correct 55 ms 36084 KB Output is correct
18 Correct 51 ms 36124 KB Output is correct
19 Correct 42 ms 35080 KB Output is correct
20 Correct 51 ms 36044 KB Output is correct
21 Correct 37 ms 35092 KB Output is correct
22 Correct 51 ms 35916 KB Output is correct
23 Correct 39 ms 35276 KB Output is correct
24 Correct 47 ms 35820 KB Output is correct
25 Correct 37 ms 35216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 17 ms 31572 KB Output is correct
13 Correct 17 ms 31612 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 17 ms 31600 KB Output is correct
16 Correct 17 ms 31596 KB Output is correct
17 Correct 16 ms 31572 KB Output is correct
18 Correct 17 ms 31572 KB Output is correct
19 Correct 17 ms 31572 KB Output is correct
20 Correct 16 ms 31572 KB Output is correct
21 Correct 16 ms 31572 KB Output is correct
22 Correct 17 ms 31624 KB Output is correct
23 Correct 17 ms 31572 KB Output is correct
24 Correct 16 ms 31688 KB Output is correct
25 Correct 18 ms 31580 KB Output is correct
26 Correct 41 ms 35280 KB Output is correct
27 Correct 69 ms 36100 KB Output is correct
28 Correct 50 ms 35100 KB Output is correct
29 Correct 50 ms 35744 KB Output is correct
30 Correct 42 ms 35080 KB Output is correct
31 Correct 47 ms 37008 KB Output is correct
32 Correct 46 ms 37124 KB Output is correct
33 Correct 57 ms 36952 KB Output is correct
34 Correct 50 ms 37196 KB Output is correct
35 Correct 50 ms 36880 KB Output is correct
36 Correct 54 ms 37160 KB Output is correct
37 Correct 51 ms 36948 KB Output is correct
38 Correct 65 ms 36892 KB Output is correct
39 Correct 57 ms 37324 KB Output is correct
40 Correct 54 ms 37104 KB Output is correct
41 Correct 39 ms 35016 KB Output is correct
42 Correct 55 ms 36084 KB Output is correct
43 Correct 51 ms 36124 KB Output is correct
44 Correct 42 ms 35080 KB Output is correct
45 Correct 51 ms 36044 KB Output is correct
46 Correct 37 ms 35092 KB Output is correct
47 Correct 51 ms 35916 KB Output is correct
48 Correct 39 ms 35276 KB Output is correct
49 Correct 47 ms 35820 KB Output is correct
50 Correct 37 ms 35216 KB Output is correct
51 Correct 68 ms 35992 KB Output is correct
52 Correct 77 ms 36616 KB Output is correct
53 Correct 72 ms 36056 KB Output is correct
54 Correct 69 ms 36600 KB Output is correct
55 Correct 55 ms 36068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31572 KB Output is correct
2 Correct 17 ms 31572 KB Output is correct
3 Correct 16 ms 31584 KB Output is correct
4 Correct 18 ms 31632 KB Output is correct
5 Correct 17 ms 31572 KB Output is correct
6 Correct 16 ms 31588 KB Output is correct
7 Correct 17 ms 31536 KB Output is correct
8 Correct 20 ms 31564 KB Output is correct
9 Correct 19 ms 31572 KB Output is correct
10 Correct 18 ms 31572 KB Output is correct
11 Correct 17 ms 31572 KB Output is correct
12 Correct 17 ms 31572 KB Output is correct
13 Correct 17 ms 31612 KB Output is correct
14 Correct 17 ms 31572 KB Output is correct
15 Correct 17 ms 31600 KB Output is correct
16 Correct 17 ms 31596 KB Output is correct
17 Correct 16 ms 31572 KB Output is correct
18 Correct 17 ms 31572 KB Output is correct
19 Correct 17 ms 31572 KB Output is correct
20 Correct 16 ms 31572 KB Output is correct
21 Correct 16 ms 31572 KB Output is correct
22 Correct 17 ms 31624 KB Output is correct
23 Correct 17 ms 31572 KB Output is correct
24 Correct 16 ms 31688 KB Output is correct
25 Correct 18 ms 31580 KB Output is correct
26 Correct 41 ms 35280 KB Output is correct
27 Correct 69 ms 36100 KB Output is correct
28 Correct 50 ms 35100 KB Output is correct
29 Correct 50 ms 35744 KB Output is correct
30 Correct 42 ms 35080 KB Output is correct
31 Correct 47 ms 37008 KB Output is correct
32 Correct 46 ms 37124 KB Output is correct
33 Correct 57 ms 36952 KB Output is correct
34 Correct 50 ms 37196 KB Output is correct
35 Correct 50 ms 36880 KB Output is correct
36 Correct 54 ms 37160 KB Output is correct
37 Correct 51 ms 36948 KB Output is correct
38 Correct 65 ms 36892 KB Output is correct
39 Correct 57 ms 37324 KB Output is correct
40 Correct 54 ms 37104 KB Output is correct
41 Correct 39 ms 35016 KB Output is correct
42 Correct 55 ms 36084 KB Output is correct
43 Correct 51 ms 36124 KB Output is correct
44 Correct 42 ms 35080 KB Output is correct
45 Correct 51 ms 36044 KB Output is correct
46 Correct 37 ms 35092 KB Output is correct
47 Correct 51 ms 35916 KB Output is correct
48 Correct 39 ms 35276 KB Output is correct
49 Correct 47 ms 35820 KB Output is correct
50 Correct 37 ms 35216 KB Output is correct
51 Correct 68 ms 35992 KB Output is correct
52 Correct 77 ms 36616 KB Output is correct
53 Correct 72 ms 36056 KB Output is correct
54 Correct 69 ms 36600 KB Output is correct
55 Correct 55 ms 36068 KB Output is correct
56 Correct 663 ms 78316 KB Output is correct
57 Correct 714 ms 88940 KB Output is correct
58 Correct 627 ms 84996 KB Output is correct
59 Correct 667 ms 86760 KB Output is correct
60 Correct 723 ms 89792 KB Output is correct