답안 #295340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295340 2020-09-09T15:42:06 Z beso123 Pilot (NOI19_pilot) C++14
100 / 100
964 ms 83548 KB
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
const int N=1000006;
int n,a[N],p[N],s[N],Size[N];
int ans=n;
void MS(){
    for(int k=1;k<=n;k++){
        p[k]=k;
        Size[k]=1;
    }
}
int FS(int v){
    if(p[v]==v) return v;
    return p[v]=FS(p[v]);
}
void US(int a,int b){
    a=FS(a);
    b=FS(b);
    if(a!=b){
       Size[a]+=Size[b];
       p[b]=a;
    }
}
bool comp_sort(pii a,pii b){
return a.x<b.x;
}
int Q;
int bo[N];
pii b[N];
int anss[N];
main(){
   scanf("%lld%lld",&n,&Q);
ans=0;
for(int k=1;k<=n;k++){
        int bb;
        scanf("%lld",&bb);
    b[k].x=bb;
    b[k].y=k;
}
sort(b+1,b+n+1,comp_sort);
vector<pii> q;
for(int k=1;k<=Q;k++){
    int x;
    scanf("%lld",&x);
    q.push_back({x,k});
}
MS();
int j=0;
sort(q.begin(),q.end(),comp_sort);
  b[n+1].x=LONG_LONG_MAX;
while(q[j].x<b[1].x && j<Q){
    j++;
}
for(int k=1;k<=n;k++){
    bo[b[k].y]=1;
    int ind=0;
  if(bo[b[k].y-1]==1){
        ans-=((Size[FS(b[k].y-1)])*(Size[FS(b[k].y-1)]+1))/2;
  }
  if(bo[b[k].y+1]==1){
        ans-=(Size[FS(b[k].y+1)]*(Size[FS(b[k].y+1)]+1))/2;
  }
  if(bo[b[k].y-1]==1){
        US(b[k].y,b[k].y-1);
  }
  if(bo[b[k].y+1]==1){
           US(b[k].y,b[k].y+1);
  }
  ans+=(Size[FS(b[k].y)]*(Size[FS(b[k].y)]+1))/2;
    if(b[k].x!=b[k+1].x){
       while(j<Q && q[j].x>=b[k].x&& q[j].x<b[k+1].x){
            anss[q[j].y]=ans;
            j++;
       }
}
}
if(j<Q)
while(j<Q && q[j].x>b[n].x){
     anss[q[j].y]=ans;
    j++;
}
for(int k=1;k<=Q;k++)
    printf("%lld\n",anss[k]);
return 0;
}

Compilation message

pilot.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      |      ^
pilot.cpp: In function 'int main()':
pilot.cpp:60:9: warning: unused variable 'ind' [-Wunused-variable]
   60 |     int ind=0;
      |         ^~~
pilot.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |    scanf("%lld%lld",&n,&Q);
      |    ~~~~~^~~~~~~~~~~~~~~~~~
pilot.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |         scanf("%lld",&bb);
      |         ~~~~~^~~~~~~~~~~~
pilot.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     scanf("%lld",&x);
      |     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 544 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 4736 KB Output is correct
2 Correct 34 ms 4856 KB Output is correct
3 Correct 32 ms 4600 KB Output is correct
4 Correct 33 ms 4472 KB Output is correct
5 Correct 31 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 8420 KB Output is correct
2 Correct 67 ms 8548 KB Output is correct
3 Correct 69 ms 8424 KB Output is correct
4 Correct 67 ms 8680 KB Output is correct
5 Correct 66 ms 8384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 8548 KB Output is correct
2 Correct 65 ms 8544 KB Output is correct
3 Correct 77 ms 8548 KB Output is correct
4 Correct 67 ms 8804 KB Output is correct
5 Correct 68 ms 8932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 33 ms 4736 KB Output is correct
12 Correct 34 ms 4856 KB Output is correct
13 Correct 32 ms 4600 KB Output is correct
14 Correct 33 ms 4472 KB Output is correct
15 Correct 31 ms 4472 KB Output is correct
16 Correct 31 ms 4472 KB Output is correct
17 Correct 34 ms 4856 KB Output is correct
18 Correct 36 ms 4856 KB Output is correct
19 Correct 31 ms 4472 KB Output is correct
20 Correct 33 ms 4728 KB Output is correct
21 Correct 31 ms 4472 KB Output is correct
22 Correct 32 ms 4608 KB Output is correct
23 Correct 37 ms 4856 KB Output is correct
24 Correct 32 ms 4608 KB Output is correct
25 Correct 32 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 544 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 33 ms 4736 KB Output is correct
27 Correct 34 ms 4856 KB Output is correct
28 Correct 32 ms 4600 KB Output is correct
29 Correct 33 ms 4472 KB Output is correct
30 Correct 31 ms 4472 KB Output is correct
31 Correct 65 ms 8420 KB Output is correct
32 Correct 67 ms 8548 KB Output is correct
33 Correct 69 ms 8424 KB Output is correct
34 Correct 67 ms 8680 KB Output is correct
35 Correct 66 ms 8384 KB Output is correct
36 Correct 78 ms 8548 KB Output is correct
37 Correct 65 ms 8544 KB Output is correct
38 Correct 77 ms 8548 KB Output is correct
39 Correct 67 ms 8804 KB Output is correct
40 Correct 68 ms 8932 KB Output is correct
41 Correct 31 ms 4472 KB Output is correct
42 Correct 34 ms 4856 KB Output is correct
43 Correct 36 ms 4856 KB Output is correct
44 Correct 31 ms 4472 KB Output is correct
45 Correct 33 ms 4728 KB Output is correct
46 Correct 31 ms 4472 KB Output is correct
47 Correct 32 ms 4608 KB Output is correct
48 Correct 37 ms 4856 KB Output is correct
49 Correct 32 ms 4608 KB Output is correct
50 Correct 32 ms 4728 KB Output is correct
51 Correct 79 ms 8588 KB Output is correct
52 Correct 77 ms 8424 KB Output is correct
53 Correct 77 ms 8552 KB Output is correct
54 Correct 77 ms 8292 KB Output is correct
55 Correct 76 ms 8548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 544 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 33 ms 4736 KB Output is correct
27 Correct 34 ms 4856 KB Output is correct
28 Correct 32 ms 4600 KB Output is correct
29 Correct 33 ms 4472 KB Output is correct
30 Correct 31 ms 4472 KB Output is correct
31 Correct 65 ms 8420 KB Output is correct
32 Correct 67 ms 8548 KB Output is correct
33 Correct 69 ms 8424 KB Output is correct
34 Correct 67 ms 8680 KB Output is correct
35 Correct 66 ms 8384 KB Output is correct
36 Correct 78 ms 8548 KB Output is correct
37 Correct 65 ms 8544 KB Output is correct
38 Correct 77 ms 8548 KB Output is correct
39 Correct 67 ms 8804 KB Output is correct
40 Correct 68 ms 8932 KB Output is correct
41 Correct 31 ms 4472 KB Output is correct
42 Correct 34 ms 4856 KB Output is correct
43 Correct 36 ms 4856 KB Output is correct
44 Correct 31 ms 4472 KB Output is correct
45 Correct 33 ms 4728 KB Output is correct
46 Correct 31 ms 4472 KB Output is correct
47 Correct 32 ms 4608 KB Output is correct
48 Correct 37 ms 4856 KB Output is correct
49 Correct 32 ms 4608 KB Output is correct
50 Correct 32 ms 4728 KB Output is correct
51 Correct 79 ms 8588 KB Output is correct
52 Correct 77 ms 8424 KB Output is correct
53 Correct 77 ms 8552 KB Output is correct
54 Correct 77 ms 8292 KB Output is correct
55 Correct 76 ms 8548 KB Output is correct
56 Correct 920 ms 81184 KB Output is correct
57 Correct 921 ms 81212 KB Output is correct
58 Correct 883 ms 76564 KB Output is correct
59 Correct 885 ms 78396 KB Output is correct
60 Correct 964 ms 83548 KB Output is correct