Submission #1086799

# Submission time Handle Problem Language Result Execution time Memory
1086799 2024-09-11T13:42:47 Z AbdullahIshfaq Pilot (NOI19_pilot) C++14
100 / 100
411 ms 52180 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
using namespace std;
#define ll int64_t
#define MOD 1000000007
ll tests = 1 , curr = 0;
const int N = 1000001;
int parent[N],Size[N];
int get_parent(int x){
    if (x != parent[x])
        return parent[x] = get_parent(parent[x]);
    return x;
}
void union__(int u,int v){
    u = get_parent(u);
    v = get_parent(v);
    if(u == v){
        return ;
    }
    if (Size[u] < Size[v]){
        swap(u , v);
    }
    curr += Size[u] * 1ll * Size[v];
    parent[v] = u;
    Size[u] += Size[v];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n , q , z;
    cin >> n >> q;
    vector<pair<int,int>> tot;
    for(int i = 1 ;i <= n ;i++){
        cin >> z;
        tot.push_back({z , -i});
    }
    for(int i = 1 ;i <= q ;i++){
        cin >> z;
        tot.push_back({z , i});
    }
    sort(tot.begin(),tot.end());
    vector<ll> ans(q + 1 , 0);
    for(auto i : tot){
        ll b = i.second;
        if(b > 0){
            ans[b] = curr;
        }
        else{
            b = -b;
            curr++;
            parent[b] = b;
            Size[b] = 1;
            if(parent[b + 1]){
                union__(b , b + 1);
            }
            if(parent[b - 1]){
                union__(b , b - 1);
            }
        }
    }
    for(int i = 1; i<= q; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2008 KB Output is correct
2 Correct 15 ms 1916 KB Output is correct
3 Correct 14 ms 2004 KB Output is correct
4 Correct 14 ms 2004 KB Output is correct
5 Correct 14 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4368 KB Output is correct
2 Correct 30 ms 4308 KB Output is correct
3 Correct 31 ms 4292 KB Output is correct
4 Correct 35 ms 4308 KB Output is correct
5 Correct 29 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4548 KB Output is correct
2 Correct 31 ms 4292 KB Output is correct
3 Correct 32 ms 4308 KB Output is correct
4 Correct 32 ms 4252 KB Output is correct
5 Correct 31 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 15 ms 2008 KB Output is correct
12 Correct 15 ms 1916 KB Output is correct
13 Correct 14 ms 2004 KB Output is correct
14 Correct 14 ms 2004 KB Output is correct
15 Correct 14 ms 2004 KB Output is correct
16 Correct 14 ms 2008 KB Output is correct
17 Correct 15 ms 2008 KB Output is correct
18 Correct 15 ms 2004 KB Output is correct
19 Correct 14 ms 1836 KB Output is correct
20 Correct 14 ms 2004 KB Output is correct
21 Correct 13 ms 1860 KB Output is correct
22 Correct 14 ms 1844 KB Output is correct
23 Correct 15 ms 2116 KB Output is correct
24 Correct 14 ms 2004 KB Output is correct
25 Correct 14 ms 1872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 15 ms 2008 KB Output is correct
27 Correct 15 ms 1916 KB Output is correct
28 Correct 14 ms 2004 KB Output is correct
29 Correct 14 ms 2004 KB Output is correct
30 Correct 14 ms 2004 KB Output is correct
31 Correct 31 ms 4368 KB Output is correct
32 Correct 30 ms 4308 KB Output is correct
33 Correct 31 ms 4292 KB Output is correct
34 Correct 35 ms 4308 KB Output is correct
35 Correct 29 ms 4292 KB Output is correct
36 Correct 31 ms 4548 KB Output is correct
37 Correct 31 ms 4292 KB Output is correct
38 Correct 32 ms 4308 KB Output is correct
39 Correct 32 ms 4252 KB Output is correct
40 Correct 31 ms 4424 KB Output is correct
41 Correct 14 ms 2008 KB Output is correct
42 Correct 15 ms 2008 KB Output is correct
43 Correct 15 ms 2004 KB Output is correct
44 Correct 14 ms 1836 KB Output is correct
45 Correct 14 ms 2004 KB Output is correct
46 Correct 13 ms 1860 KB Output is correct
47 Correct 14 ms 1844 KB Output is correct
48 Correct 15 ms 2116 KB Output is correct
49 Correct 14 ms 2004 KB Output is correct
50 Correct 14 ms 1872 KB Output is correct
51 Correct 34 ms 4160 KB Output is correct
52 Correct 33 ms 4036 KB Output is correct
53 Correct 34 ms 4160 KB Output is correct
54 Correct 34 ms 3880 KB Output is correct
55 Correct 37 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 15 ms 2008 KB Output is correct
27 Correct 15 ms 1916 KB Output is correct
28 Correct 14 ms 2004 KB Output is correct
29 Correct 14 ms 2004 KB Output is correct
30 Correct 14 ms 2004 KB Output is correct
31 Correct 31 ms 4368 KB Output is correct
32 Correct 30 ms 4308 KB Output is correct
33 Correct 31 ms 4292 KB Output is correct
34 Correct 35 ms 4308 KB Output is correct
35 Correct 29 ms 4292 KB Output is correct
36 Correct 31 ms 4548 KB Output is correct
37 Correct 31 ms 4292 KB Output is correct
38 Correct 32 ms 4308 KB Output is correct
39 Correct 32 ms 4252 KB Output is correct
40 Correct 31 ms 4424 KB Output is correct
41 Correct 14 ms 2008 KB Output is correct
42 Correct 15 ms 2008 KB Output is correct
43 Correct 15 ms 2004 KB Output is correct
44 Correct 14 ms 1836 KB Output is correct
45 Correct 14 ms 2004 KB Output is correct
46 Correct 13 ms 1860 KB Output is correct
47 Correct 14 ms 1844 KB Output is correct
48 Correct 15 ms 2116 KB Output is correct
49 Correct 14 ms 2004 KB Output is correct
50 Correct 14 ms 1872 KB Output is correct
51 Correct 34 ms 4160 KB Output is correct
52 Correct 33 ms 4036 KB Output is correct
53 Correct 34 ms 4160 KB Output is correct
54 Correct 34 ms 3880 KB Output is correct
55 Correct 37 ms 4292 KB Output is correct
56 Correct 388 ms 38156 KB Output is correct
57 Correct 411 ms 50324 KB Output is correct
58 Correct 367 ms 47772 KB Output is correct
59 Correct 375 ms 49052 KB Output is correct
60 Correct 403 ms 52180 KB Output is correct