Submission #329199

# Submission time Handle Problem Language Result Execution time Memory
329199 2020-11-19T17:50:27 Z Mahdi_Shokoufi Pilot (NOI19_pilot) C++17
89 / 100
1000 ms 63340 KB
//In The Name of Allah
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 10;

int a[N]; ll res[N];
vector < int > pos[N];
set < pii > seg;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i ++)
        cin >> a[i], pos[a[i]].pb(i);
    ll tot = n * (n + 1) / 2;
    seg.insert(mp(n, 1));
    for (int i = N - 10; i > 0; i --){
        res[i] = tot;
        for (int x : pos[i]){
            auto itr = seg.lower_bound(mp(x, -inf));
            ll l = itr -> Y, r = itr -> X;
            tot -= (r - l + 1) * (r - l + 2) / 2;
            tot += (x - l) * (x - l + 1) / 2;
            tot += (r - x) * (r - x + 1) / 2;
            seg.erase(itr);
            if (l < x)
                seg.insert(mp(x - 1, l));
            if (x < r)
                seg.insert(mp(r, x + 1));
        }
    }
    for (int i = 0; i < q; i ++){
        int x;
        cin >> x;
        cout << res[x] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 25 ms 31596 KB Output is correct
12 Correct 26 ms 31524 KB Output is correct
13 Correct 26 ms 31596 KB Output is correct
14 Correct 26 ms 31596 KB Output is correct
15 Correct 25 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 25 ms 31596 KB Output is correct
12 Correct 26 ms 31524 KB Output is correct
13 Correct 26 ms 31596 KB Output is correct
14 Correct 26 ms 31596 KB Output is correct
15 Correct 25 ms 31596 KB Output is correct
16 Correct 25 ms 31596 KB Output is correct
17 Correct 25 ms 31724 KB Output is correct
18 Correct 25 ms 31596 KB Output is correct
19 Correct 26 ms 31724 KB Output is correct
20 Correct 26 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 25 ms 31596 KB Output is correct
12 Correct 26 ms 31524 KB Output is correct
13 Correct 26 ms 31596 KB Output is correct
14 Correct 26 ms 31596 KB Output is correct
15 Correct 25 ms 31596 KB Output is correct
16 Correct 25 ms 31596 KB Output is correct
17 Correct 25 ms 31724 KB Output is correct
18 Correct 25 ms 31596 KB Output is correct
19 Correct 26 ms 31724 KB Output is correct
20 Correct 26 ms 31596 KB Output is correct
21 Correct 25 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 28 ms 31724 KB Output is correct
24 Correct 27 ms 31724 KB Output is correct
25 Correct 25 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 35052 KB Output is correct
2 Correct 109 ms 36076 KB Output is correct
3 Correct 89 ms 35052 KB Output is correct
4 Correct 102 ms 35940 KB Output is correct
5 Correct 85 ms 34924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 35948 KB Output is correct
2 Correct 68 ms 36076 KB Output is correct
3 Correct 68 ms 35948 KB Output is correct
4 Correct 68 ms 36076 KB Output is correct
5 Correct 67 ms 35948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 35948 KB Output is correct
2 Correct 75 ms 35948 KB Output is correct
3 Correct 76 ms 35820 KB Output is correct
4 Correct 76 ms 36076 KB Output is correct
5 Correct 82 ms 36076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 87 ms 35052 KB Output is correct
12 Correct 109 ms 36076 KB Output is correct
13 Correct 89 ms 35052 KB Output is correct
14 Correct 102 ms 35940 KB Output is correct
15 Correct 85 ms 34924 KB Output is correct
16 Correct 109 ms 34924 KB Output is correct
17 Correct 110 ms 36076 KB Output is correct
18 Correct 112 ms 36204 KB Output is correct
19 Correct 89 ms 34884 KB Output is correct
20 Correct 108 ms 36076 KB Output is correct
21 Correct 85 ms 34924 KB Output is correct
22 Correct 103 ms 35820 KB Output is correct
23 Correct 92 ms 35180 KB Output is correct
24 Correct 102 ms 35820 KB Output is correct
25 Correct 87 ms 35052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 25 ms 31596 KB Output is correct
12 Correct 26 ms 31524 KB Output is correct
13 Correct 26 ms 31596 KB Output is correct
14 Correct 26 ms 31596 KB Output is correct
15 Correct 25 ms 31596 KB Output is correct
16 Correct 25 ms 31596 KB Output is correct
17 Correct 25 ms 31724 KB Output is correct
18 Correct 25 ms 31596 KB Output is correct
19 Correct 26 ms 31724 KB Output is correct
20 Correct 26 ms 31596 KB Output is correct
21 Correct 25 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 28 ms 31724 KB Output is correct
24 Correct 27 ms 31724 KB Output is correct
25 Correct 25 ms 31724 KB Output is correct
26 Correct 87 ms 35052 KB Output is correct
27 Correct 109 ms 36076 KB Output is correct
28 Correct 89 ms 35052 KB Output is correct
29 Correct 102 ms 35940 KB Output is correct
30 Correct 85 ms 34924 KB Output is correct
31 Correct 65 ms 35948 KB Output is correct
32 Correct 68 ms 36076 KB Output is correct
33 Correct 68 ms 35948 KB Output is correct
34 Correct 68 ms 36076 KB Output is correct
35 Correct 67 ms 35948 KB Output is correct
36 Correct 78 ms 35948 KB Output is correct
37 Correct 75 ms 35948 KB Output is correct
38 Correct 76 ms 35820 KB Output is correct
39 Correct 76 ms 36076 KB Output is correct
40 Correct 82 ms 36076 KB Output is correct
41 Correct 109 ms 34924 KB Output is correct
42 Correct 110 ms 36076 KB Output is correct
43 Correct 112 ms 36204 KB Output is correct
44 Correct 89 ms 34884 KB Output is correct
45 Correct 108 ms 36076 KB Output is correct
46 Correct 85 ms 34924 KB Output is correct
47 Correct 103 ms 35820 KB Output is correct
48 Correct 92 ms 35180 KB Output is correct
49 Correct 102 ms 35820 KB Output is correct
50 Correct 87 ms 35052 KB Output is correct
51 Correct 114 ms 35948 KB Output is correct
52 Correct 136 ms 36588 KB Output is correct
53 Correct 113 ms 35948 KB Output is correct
54 Correct 133 ms 36588 KB Output is correct
55 Correct 124 ms 35968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 31596 KB Output is correct
2 Correct 26 ms 31596 KB Output is correct
3 Correct 26 ms 31596 KB Output is correct
4 Correct 26 ms 31596 KB Output is correct
5 Correct 26 ms 31596 KB Output is correct
6 Correct 26 ms 31596 KB Output is correct
7 Correct 26 ms 31596 KB Output is correct
8 Correct 26 ms 31596 KB Output is correct
9 Correct 26 ms 31596 KB Output is correct
10 Correct 26 ms 31596 KB Output is correct
11 Correct 25 ms 31596 KB Output is correct
12 Correct 26 ms 31524 KB Output is correct
13 Correct 26 ms 31596 KB Output is correct
14 Correct 26 ms 31596 KB Output is correct
15 Correct 25 ms 31596 KB Output is correct
16 Correct 25 ms 31596 KB Output is correct
17 Correct 25 ms 31724 KB Output is correct
18 Correct 25 ms 31596 KB Output is correct
19 Correct 26 ms 31724 KB Output is correct
20 Correct 26 ms 31596 KB Output is correct
21 Correct 25 ms 31724 KB Output is correct
22 Correct 25 ms 31724 KB Output is correct
23 Correct 28 ms 31724 KB Output is correct
24 Correct 27 ms 31724 KB Output is correct
25 Correct 25 ms 31724 KB Output is correct
26 Correct 87 ms 35052 KB Output is correct
27 Correct 109 ms 36076 KB Output is correct
28 Correct 89 ms 35052 KB Output is correct
29 Correct 102 ms 35940 KB Output is correct
30 Correct 85 ms 34924 KB Output is correct
31 Correct 65 ms 35948 KB Output is correct
32 Correct 68 ms 36076 KB Output is correct
33 Correct 68 ms 35948 KB Output is correct
34 Correct 68 ms 36076 KB Output is correct
35 Correct 67 ms 35948 KB Output is correct
36 Correct 78 ms 35948 KB Output is correct
37 Correct 75 ms 35948 KB Output is correct
38 Correct 76 ms 35820 KB Output is correct
39 Correct 76 ms 36076 KB Output is correct
40 Correct 82 ms 36076 KB Output is correct
41 Correct 109 ms 34924 KB Output is correct
42 Correct 110 ms 36076 KB Output is correct
43 Correct 112 ms 36204 KB Output is correct
44 Correct 89 ms 34884 KB Output is correct
45 Correct 108 ms 36076 KB Output is correct
46 Correct 85 ms 34924 KB Output is correct
47 Correct 103 ms 35820 KB Output is correct
48 Correct 92 ms 35180 KB Output is correct
49 Correct 102 ms 35820 KB Output is correct
50 Correct 87 ms 35052 KB Output is correct
51 Correct 114 ms 35948 KB Output is correct
52 Correct 136 ms 36588 KB Output is correct
53 Correct 113 ms 35948 KB Output is correct
54 Correct 133 ms 36588 KB Output is correct
55 Correct 124 ms 35968 KB Output is correct
56 Execution timed out 1101 ms 63340 KB Time limit exceeded
57 Halted 0 ms 0 KB -