Submission #314113

# Submission time Handle Problem Language Result Execution time Memory
314113 2020-10-18T12:31:37 Z kimbj0709 Pilot (NOI19_pilot) C++14
100 / 100
734 ms 83756 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 1000050
#define f first
#define s second
int currsum = 0;
vector<int> ufds(maxn);
vector<int> s(maxn,1);
int find(int k){
  if(ufds[k]!=k){
    ufds[k] = find(ufds[k]);
  }
  return ufds[k];
}
void merge(int a,int b){
  int temp1 = find(a);
  int temp2 = find(b);
  currsum -= (s[temp1]*(s[temp1]+1))/2;
  currsum -= (s[temp2]*(s[temp2]+1))/2;
  int tt = s[temp1]+s[temp2];
  currsum += (tt*(tt+1))/2;
  ufds[temp1] = temp2;
  s[temp2] = tt;
  s[temp1] = tt;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int n,q;
  vector<pair<int,int> > height,query;
  vector<int> visited(maxn,0);
  int input;
  cin >> n >> q;
  for(int i=0;i<ufds.size();i++){
    ufds[i] = i;
  }
  for(int i=1;i<=n;i++){
    cin >> input;
    height.push_back({input,i});
  }
  vector<int> ans(q);
  for(int i=0;i<q;i++){
    cin >> input;
    query.push_back({input,i});
  }
  sort(height.begin(),height.end());
  sort(query.begin(),query.end());
  int currpos = 0;
  for(int i=0;i<query.size();i++){
    while(currpos<height.size()&&height[currpos].f<=query[i].f){
      currsum++;
      visited[height[currpos].s] = 1;
      if(visited[height[currpos].s-1]==1){
        merge(height[currpos].s,height[currpos].s-1);
      }
      if(visited[height[currpos].s+1]==1){
        merge(height[currpos].s,height[currpos].s+1);
      }
      currpos++;
    }
    ans[query[i].s] = currsum;
  }
  for(auto k:ans){
    cout << k << "\n";
  }
}

Compilation message

pilot.cpp: In function 'int32_t main()':
pilot.cpp:35:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i=0;i<ufds.size();i++){
      |               ~^~~~~~~~~~~~
pilot.cpp:50:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int i=0;i<query.size();i++){
      |               ~^~~~~~~~~~~~~
pilot.cpp:51:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     while(currpos<height.size()&&height[currpos].f<=query[i].f){
      |           ~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 15 ms 23840 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 15 ms 23840 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 15 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23936 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 15 ms 23840 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 15 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23936 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
21 Correct 15 ms 23936 KB Output is correct
22 Correct 16 ms 23936 KB Output is correct
23 Correct 16 ms 23936 KB Output is correct
24 Correct 16 ms 23936 KB Output is correct
25 Correct 16 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 26608 KB Output is correct
2 Correct 40 ms 26608 KB Output is correct
3 Correct 39 ms 26608 KB Output is correct
4 Correct 38 ms 26608 KB Output is correct
5 Correct 41 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 30188 KB Output is correct
2 Correct 62 ms 30316 KB Output is correct
3 Correct 62 ms 30196 KB Output is correct
4 Correct 63 ms 30316 KB Output is correct
5 Correct 60 ms 30196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 30444 KB Output is correct
2 Correct 62 ms 30484 KB Output is correct
3 Correct 61 ms 30316 KB Output is correct
4 Correct 61 ms 30452 KB Output is correct
5 Correct 64 ms 30444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 40 ms 26608 KB Output is correct
12 Correct 40 ms 26608 KB Output is correct
13 Correct 39 ms 26608 KB Output is correct
14 Correct 38 ms 26608 KB Output is correct
15 Correct 41 ms 26616 KB Output is correct
16 Correct 37 ms 26520 KB Output is correct
17 Correct 37 ms 26744 KB Output is correct
18 Correct 39 ms 26736 KB Output is correct
19 Correct 34 ms 26636 KB Output is correct
20 Correct 37 ms 26608 KB Output is correct
21 Correct 40 ms 26616 KB Output is correct
22 Correct 36 ms 26608 KB Output is correct
23 Correct 37 ms 26616 KB Output is correct
24 Correct 35 ms 26616 KB Output is correct
25 Correct 37 ms 26596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 15 ms 23840 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 15 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23936 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
21 Correct 15 ms 23936 KB Output is correct
22 Correct 16 ms 23936 KB Output is correct
23 Correct 16 ms 23936 KB Output is correct
24 Correct 16 ms 23936 KB Output is correct
25 Correct 16 ms 23928 KB Output is correct
26 Correct 40 ms 26608 KB Output is correct
27 Correct 40 ms 26608 KB Output is correct
28 Correct 39 ms 26608 KB Output is correct
29 Correct 38 ms 26608 KB Output is correct
30 Correct 41 ms 26616 KB Output is correct
31 Correct 61 ms 30188 KB Output is correct
32 Correct 62 ms 30316 KB Output is correct
33 Correct 62 ms 30196 KB Output is correct
34 Correct 63 ms 30316 KB Output is correct
35 Correct 60 ms 30196 KB Output is correct
36 Correct 65 ms 30444 KB Output is correct
37 Correct 62 ms 30484 KB Output is correct
38 Correct 61 ms 30316 KB Output is correct
39 Correct 61 ms 30452 KB Output is correct
40 Correct 64 ms 30444 KB Output is correct
41 Correct 37 ms 26520 KB Output is correct
42 Correct 37 ms 26744 KB Output is correct
43 Correct 39 ms 26736 KB Output is correct
44 Correct 34 ms 26636 KB Output is correct
45 Correct 37 ms 26608 KB Output is correct
46 Correct 40 ms 26616 KB Output is correct
47 Correct 36 ms 26608 KB Output is correct
48 Correct 37 ms 26616 KB Output is correct
49 Correct 35 ms 26616 KB Output is correct
50 Correct 37 ms 26596 KB Output is correct
51 Correct 73 ms 30316 KB Output is correct
52 Correct 70 ms 30444 KB Output is correct
53 Correct 71 ms 30316 KB Output is correct
54 Correct 72 ms 30444 KB Output is correct
55 Correct 72 ms 30316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23936 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 15 ms 23808 KB Output is correct
10 Correct 16 ms 23936 KB Output is correct
11 Correct 15 ms 23840 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 16 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 15 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23936 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
21 Correct 15 ms 23936 KB Output is correct
22 Correct 16 ms 23936 KB Output is correct
23 Correct 16 ms 23936 KB Output is correct
24 Correct 16 ms 23936 KB Output is correct
25 Correct 16 ms 23928 KB Output is correct
26 Correct 40 ms 26608 KB Output is correct
27 Correct 40 ms 26608 KB Output is correct
28 Correct 39 ms 26608 KB Output is correct
29 Correct 38 ms 26608 KB Output is correct
30 Correct 41 ms 26616 KB Output is correct
31 Correct 61 ms 30188 KB Output is correct
32 Correct 62 ms 30316 KB Output is correct
33 Correct 62 ms 30196 KB Output is correct
34 Correct 63 ms 30316 KB Output is correct
35 Correct 60 ms 30196 KB Output is correct
36 Correct 65 ms 30444 KB Output is correct
37 Correct 62 ms 30484 KB Output is correct
38 Correct 61 ms 30316 KB Output is correct
39 Correct 61 ms 30452 KB Output is correct
40 Correct 64 ms 30444 KB Output is correct
41 Correct 37 ms 26520 KB Output is correct
42 Correct 37 ms 26744 KB Output is correct
43 Correct 39 ms 26736 KB Output is correct
44 Correct 34 ms 26636 KB Output is correct
45 Correct 37 ms 26608 KB Output is correct
46 Correct 40 ms 26616 KB Output is correct
47 Correct 36 ms 26608 KB Output is correct
48 Correct 37 ms 26616 KB Output is correct
49 Correct 35 ms 26616 KB Output is correct
50 Correct 37 ms 26596 KB Output is correct
51 Correct 73 ms 30316 KB Output is correct
52 Correct 70 ms 30444 KB Output is correct
53 Correct 71 ms 30316 KB Output is correct
54 Correct 72 ms 30444 KB Output is correct
55 Correct 72 ms 30316 KB Output is correct
56 Correct 714 ms 82596 KB Output is correct
57 Correct 712 ms 81604 KB Output is correct
58 Correct 666 ms 79556 KB Output is correct
59 Correct 684 ms 80328 KB Output is correct
60 Correct 734 ms 83756 KB Output is correct