Submission #888419

# Submission time Handle Problem Language Result Execution time Memory
888419 2023-12-17T10:32:06 Z imarn Pilot (NOI19_pilot) C++14
100 / 100
409 ms 54964 KB
#include<bits/stdc++.h>
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define vi vector<int>
#define vpii vector<pii>
#define ll long long
using namespace std;
const int N=1e6+5;
int pr[N],a[N];
pii qr[N];
ll sz[N];
ll ac[N];
bool vis[N]{0};
vector<pii>v;
int get(int r){
    return pr[r]==r?r:pr[r]=get(pr[r]);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,q;cin>>n>>q;iota(pr,pr+n+1,0);
    for(int i=1;i<=n;i++)cin>>a[i],sz[i]=1;
    for(int i=1;i<=q;i++)cin>>qr[i].f,qr[i].s=i;
    ll ans=0;sort(qr+1,qr+q+1);
    ll sn=0;
    for(int i=1;i<=n;i++){
        if(sn==0&&a[i]<=qr[1].f)sn++,vis[i]=1,sz[i]=sn;
        else if(sn>0&&a[i]<=qr[1].f)pr[i-1]=i,sn++,vis[i]=1,sz[i]=sn;
        else if(a[i]>qr[1].f)v.pb({a[i],i}),ans+=sn*(sn+1)/2,sn=0;
    }ans+=sn*(sn+1)/2;
    sort(v.begin(),v.end());
    ac[qr[1].s]=ans;int idx=0;
    for(int i=2;i<=q;i++){
        while(idx<v.size()&&qr[i].f>=v[idx].f){
            int j = v[idx].s;
            ans+=1;vis[j]=1;
            if(vis[j-1]){
                pr[j-1]=j;ans-=sz[j]*(sz[j]+1)/2;
                ans-=sz[j-1]*(sz[j-1]+1)/2;sz[j]+=sz[j-1];
                ans+=sz[j]*(sz[j]+1)/2;
            }
            if(vis[j+1]){
                int u=get(j+1);
                pr[j]=pr[u];ans-=sz[j]*(sz[j]+1)/2;
                ans-=sz[u]*(sz[u]+1)/2;sz[u]+=sz[j];
                ans+=sz[u]*(sz[u]+1)/2;
            }idx++;
        }ac[qr[i].s]=ans;
    }for(int i=1;i<=q;i++)cout<<ac[i]<<"\n";
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(idx<v.size()&&qr[i].f>=v[idx].f){
      |               ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10584 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10584 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 1 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10584 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 1 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 1 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12632 KB Output is correct
2 Correct 8 ms 13148 KB Output is correct
3 Correct 9 ms 13144 KB Output is correct
4 Correct 8 ms 13148 KB Output is correct
5 Correct 7 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 14552 KB Output is correct
2 Correct 29 ms 15308 KB Output is correct
3 Correct 29 ms 15320 KB Output is correct
4 Correct 31 ms 15696 KB Output is correct
5 Correct 28 ms 15448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 14552 KB Output is correct
2 Correct 28 ms 15476 KB Output is correct
3 Correct 31 ms 15312 KB Output is correct
4 Correct 28 ms 15568 KB Output is correct
5 Correct 30 ms 15564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 7 ms 12632 KB Output is correct
12 Correct 8 ms 13148 KB Output is correct
13 Correct 9 ms 13144 KB Output is correct
14 Correct 8 ms 13148 KB Output is correct
15 Correct 7 ms 13148 KB Output is correct
16 Correct 9 ms 13532 KB Output is correct
17 Correct 12 ms 14040 KB Output is correct
18 Correct 15 ms 14164 KB Output is correct
19 Correct 14 ms 14172 KB Output is correct
20 Correct 14 ms 13664 KB Output is correct
21 Correct 8 ms 13148 KB Output is correct
22 Correct 11 ms 13760 KB Output is correct
23 Correct 13 ms 14036 KB Output is correct
24 Correct 13 ms 14040 KB Output is correct
25 Correct 11 ms 13788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10584 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 1 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 1 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 7 ms 12632 KB Output is correct
27 Correct 8 ms 13148 KB Output is correct
28 Correct 9 ms 13144 KB Output is correct
29 Correct 8 ms 13148 KB Output is correct
30 Correct 7 ms 13148 KB Output is correct
31 Correct 27 ms 14552 KB Output is correct
32 Correct 29 ms 15308 KB Output is correct
33 Correct 29 ms 15320 KB Output is correct
34 Correct 31 ms 15696 KB Output is correct
35 Correct 28 ms 15448 KB Output is correct
36 Correct 28 ms 14552 KB Output is correct
37 Correct 28 ms 15476 KB Output is correct
38 Correct 31 ms 15312 KB Output is correct
39 Correct 28 ms 15568 KB Output is correct
40 Correct 30 ms 15564 KB Output is correct
41 Correct 9 ms 13532 KB Output is correct
42 Correct 12 ms 14040 KB Output is correct
43 Correct 15 ms 14164 KB Output is correct
44 Correct 14 ms 14172 KB Output is correct
45 Correct 14 ms 13664 KB Output is correct
46 Correct 8 ms 13148 KB Output is correct
47 Correct 11 ms 13760 KB Output is correct
48 Correct 13 ms 14036 KB Output is correct
49 Correct 13 ms 14040 KB Output is correct
50 Correct 11 ms 13788 KB Output is correct
51 Correct 36 ms 15108 KB Output is correct
52 Correct 37 ms 15172 KB Output is correct
53 Correct 36 ms 15312 KB Output is correct
54 Correct 36 ms 15056 KB Output is correct
55 Correct 36 ms 15308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10588 KB Output is correct
2 Correct 1 ms 10588 KB Output is correct
3 Correct 1 ms 10584 KB Output is correct
4 Correct 1 ms 10588 KB Output is correct
5 Correct 1 ms 10588 KB Output is correct
6 Correct 1 ms 10584 KB Output is correct
7 Correct 1 ms 10588 KB Output is correct
8 Correct 1 ms 10588 KB Output is correct
9 Correct 1 ms 10840 KB Output is correct
10 Correct 1 ms 10588 KB Output is correct
11 Correct 1 ms 10584 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 10588 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 1 ms 10588 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 1 ms 10588 KB Output is correct
18 Correct 1 ms 10588 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 1 ms 10588 KB Output is correct
21 Correct 1 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct
26 Correct 7 ms 12632 KB Output is correct
27 Correct 8 ms 13148 KB Output is correct
28 Correct 9 ms 13144 KB Output is correct
29 Correct 8 ms 13148 KB Output is correct
30 Correct 7 ms 13148 KB Output is correct
31 Correct 27 ms 14552 KB Output is correct
32 Correct 29 ms 15308 KB Output is correct
33 Correct 29 ms 15320 KB Output is correct
34 Correct 31 ms 15696 KB Output is correct
35 Correct 28 ms 15448 KB Output is correct
36 Correct 28 ms 14552 KB Output is correct
37 Correct 28 ms 15476 KB Output is correct
38 Correct 31 ms 15312 KB Output is correct
39 Correct 28 ms 15568 KB Output is correct
40 Correct 30 ms 15564 KB Output is correct
41 Correct 9 ms 13532 KB Output is correct
42 Correct 12 ms 14040 KB Output is correct
43 Correct 15 ms 14164 KB Output is correct
44 Correct 14 ms 14172 KB Output is correct
45 Correct 14 ms 13664 KB Output is correct
46 Correct 8 ms 13148 KB Output is correct
47 Correct 11 ms 13760 KB Output is correct
48 Correct 13 ms 14036 KB Output is correct
49 Correct 13 ms 14040 KB Output is correct
50 Correct 11 ms 13788 KB Output is correct
51 Correct 36 ms 15108 KB Output is correct
52 Correct 37 ms 15172 KB Output is correct
53 Correct 36 ms 15312 KB Output is correct
54 Correct 36 ms 15056 KB Output is correct
55 Correct 36 ms 15308 KB Output is correct
56 Correct 403 ms 54400 KB Output is correct
57 Correct 393 ms 54004 KB Output is correct
58 Correct 394 ms 53064 KB Output is correct
59 Correct 396 ms 53172 KB Output is correct
60 Correct 409 ms 54964 KB Output is correct