답안 #1086790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086790 2024-09-11T13:29:57 Z AbdullahIshfaq Pilot (NOI19_pilot) C++14
28 / 100
127 ms 8916 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll tests = 1 , curr = 0;
const int N = 1000001;
int parent[N],Size[N];
int get_parent(int u){
    return ((u != parent[u]) ? parent[u] = get_parent(parent[u]) : u);
}
void union__(int u,int v){
    if((u = get_parent(u)) == (v = get_parent(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 , 0);
    for(int i = 0 ;i < n + q ;i ++){
        ll a = tot[i].first , b = tot[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] << endl;
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:40:12: warning: unused variable 'a' [-Wunused-variable]
   40 |         ll a = tot[i].first , b = tot[i].second;
      |            ^
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 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 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 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 1 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 Runtime error 1 ms 600 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 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 1 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 Runtime error 1 ms 600 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2516 KB Output is correct
2 Correct 15 ms 2644 KB Output is correct
3 Correct 17 ms 2520 KB Output is correct
4 Correct 14 ms 2648 KB Output is correct
5 Correct 15 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 127 ms 8396 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 5572 KB Output is correct
2 Runtime error 122 ms 8916 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 15 ms 2516 KB Output is correct
12 Correct 15 ms 2644 KB Output is correct
13 Correct 17 ms 2520 KB Output is correct
14 Correct 14 ms 2648 KB Output is correct
15 Correct 15 ms 2516 KB Output is correct
16 Correct 14 ms 2520 KB Output is correct
17 Correct 16 ms 2772 KB Output is correct
18 Correct 15 ms 2820 KB Output is correct
19 Correct 18 ms 2520 KB Output is correct
20 Correct 15 ms 2776 KB Output is correct
21 Correct 14 ms 2516 KB Output is correct
22 Correct 14 ms 2616 KB Output is correct
23 Correct 16 ms 2520 KB Output is correct
24 Correct 14 ms 2640 KB Output is correct
25 Correct 16 ms 2656 KB Output is correct
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 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 1 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 Runtime error 1 ms 600 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 604 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 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 1 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 Runtime error 1 ms 600 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -