Submission #425465

# Submission time Handle Problem Language Result Execution time Memory
425465 2021-06-13T04:07:35 Z errorgorn Pilot (NOI19_pilot) C++17
100 / 100
876 ms 61048 KB
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> ii;
vector<ii> v;
vector<ii> qv;
int n,q,t;
long long k;
int arr[1000005];
long long qrr[1000005];
bool fly[1000005];
int p[1000005],r[1000005],s[1000005];
int parent(int i){return (i==p[i])?i:p[i]=parent(p[i]);}
long long siz(int i){
    long long ans=s[parent(i)];
    return (ans*(ans+1))/2;
}
void unions(int i,int j){
    i=parent(i);
    j=parent(j);
    if (r[i]<r[j]){
        p[i]=j;
        s[j]+=s[i];
    }
    else{
        p[j]=i;
        s[i]+=s[j];
        if (r[i]==r[j]) r[i]++;
    }
}
void f(int i){
    if (fly[i-1] && fly[i+1]){
        k-=siz(i-1);
        k-=siz(i+1);
        unions(i-1,i);
        unions(i,i+1);
        k+=siz(i);
    }
    else if (fly[i-1]){
        k-=siz(i-1);
        unions(i-1,i);
        k+=siz(i);
    }
    else if (fly[i+1]){
        k-=siz(i+1);
        unions(i,i+1);
        k+=siz(i);
    }
    else{
        k+=1;
    }
    fly[i]=true;
}
int main(){
    //freopen("meow","r",stdin);
    scanf("%d%d",&n,&q);
    for (int x=1;x<=n;x++){
        scanf("%d",&arr[x]);
        v.push_back(ii (arr[x],x));
        p[x]=x;
        s[x]=1;
    }
    sort(v.begin(),v.end());
    /*for (vector<ii>::iterator it=v.begin();it!=v.end();it++){
        printf("%d-%d ",(*it).first,(*it).second);
    }*/
    for (int x=0;x<q;x++){
        scanf("%d",&t);
        qv.push_back(ii (t,x));
    }
    sort(qv.begin(),qv.end());
    int h,index;
    vector<ii>::iterator it=v.begin();
    for (vector<ii>::iterator query=qv.begin();query!=qv.end();query++){
        h=(*query).first,index=(*query).second;
        while (it!=v.end() && (*it).first<=h){
            f((*it).second);
            it++;
            //printf("%d %d\n",k,(*it).second);
        }
        qrr[index]=k;
    }
    for (int x=0;x<q;x++){
        printf("%lld\n",qrr[x]);
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
pilot.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d",&arr[x]);
      |         ~~~~~^~~~~~~~~~~~~~
pilot.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3356 KB Output is correct
2 Correct 29 ms 3416 KB Output is correct
3 Correct 27 ms 3264 KB Output is correct
4 Correct 26 ms 3264 KB Output is correct
5 Correct 27 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 5800 KB Output is correct
2 Correct 56 ms 5932 KB Output is correct
3 Correct 54 ms 5904 KB Output is correct
4 Correct 55 ms 5944 KB Output is correct
5 Correct 52 ms 5792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 5996 KB Output is correct
2 Correct 66 ms 6028 KB Output is correct
3 Correct 54 ms 6008 KB Output is correct
4 Correct 53 ms 6116 KB Output is correct
5 Correct 57 ms 6200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 28 ms 3356 KB Output is correct
12 Correct 29 ms 3416 KB Output is correct
13 Correct 27 ms 3264 KB Output is correct
14 Correct 26 ms 3264 KB Output is correct
15 Correct 27 ms 3172 KB Output is correct
16 Correct 26 ms 3348 KB Output is correct
17 Correct 25 ms 3392 KB Output is correct
18 Correct 25 ms 3468 KB Output is correct
19 Correct 23 ms 3136 KB Output is correct
20 Correct 26 ms 3364 KB Output is correct
21 Correct 28 ms 3140 KB Output is correct
22 Correct 25 ms 3256 KB Output is correct
23 Correct 26 ms 3384 KB Output is correct
24 Correct 23 ms 3232 KB Output is correct
25 Correct 25 ms 3248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 28 ms 3356 KB Output is correct
27 Correct 29 ms 3416 KB Output is correct
28 Correct 27 ms 3264 KB Output is correct
29 Correct 26 ms 3264 KB Output is correct
30 Correct 27 ms 3172 KB Output is correct
31 Correct 52 ms 5800 KB Output is correct
32 Correct 56 ms 5932 KB Output is correct
33 Correct 54 ms 5904 KB Output is correct
34 Correct 55 ms 5944 KB Output is correct
35 Correct 52 ms 5792 KB Output is correct
36 Correct 57 ms 5996 KB Output is correct
37 Correct 66 ms 6028 KB Output is correct
38 Correct 54 ms 6008 KB Output is correct
39 Correct 53 ms 6116 KB Output is correct
40 Correct 57 ms 6200 KB Output is correct
41 Correct 26 ms 3348 KB Output is correct
42 Correct 25 ms 3392 KB Output is correct
43 Correct 25 ms 3468 KB Output is correct
44 Correct 23 ms 3136 KB Output is correct
45 Correct 26 ms 3364 KB Output is correct
46 Correct 28 ms 3140 KB Output is correct
47 Correct 25 ms 3256 KB Output is correct
48 Correct 26 ms 3384 KB Output is correct
49 Correct 23 ms 3232 KB Output is correct
50 Correct 25 ms 3248 KB Output is correct
51 Correct 66 ms 6380 KB Output is correct
52 Correct 77 ms 6200 KB Output is correct
53 Correct 65 ms 6260 KB Output is correct
54 Correct 66 ms 6036 KB Output is correct
55 Correct 64 ms 6196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 292 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 28 ms 3356 KB Output is correct
27 Correct 29 ms 3416 KB Output is correct
28 Correct 27 ms 3264 KB Output is correct
29 Correct 26 ms 3264 KB Output is correct
30 Correct 27 ms 3172 KB Output is correct
31 Correct 52 ms 5800 KB Output is correct
32 Correct 56 ms 5932 KB Output is correct
33 Correct 54 ms 5904 KB Output is correct
34 Correct 55 ms 5944 KB Output is correct
35 Correct 52 ms 5792 KB Output is correct
36 Correct 57 ms 5996 KB Output is correct
37 Correct 66 ms 6028 KB Output is correct
38 Correct 54 ms 6008 KB Output is correct
39 Correct 53 ms 6116 KB Output is correct
40 Correct 57 ms 6200 KB Output is correct
41 Correct 26 ms 3348 KB Output is correct
42 Correct 25 ms 3392 KB Output is correct
43 Correct 25 ms 3468 KB Output is correct
44 Correct 23 ms 3136 KB Output is correct
45 Correct 26 ms 3364 KB Output is correct
46 Correct 28 ms 3140 KB Output is correct
47 Correct 25 ms 3256 KB Output is correct
48 Correct 26 ms 3384 KB Output is correct
49 Correct 23 ms 3232 KB Output is correct
50 Correct 25 ms 3248 KB Output is correct
51 Correct 66 ms 6380 KB Output is correct
52 Correct 77 ms 6200 KB Output is correct
53 Correct 65 ms 6260 KB Output is correct
54 Correct 66 ms 6036 KB Output is correct
55 Correct 64 ms 6196 KB Output is correct
56 Correct 823 ms 59388 KB Output is correct
57 Correct 827 ms 59152 KB Output is correct
58 Correct 760 ms 55924 KB Output is correct
59 Correct 770 ms 57256 KB Output is correct
60 Correct 876 ms 61048 KB Output is correct