# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
225664 |
2020-04-21T06:44:10 Z |
Fasho |
Pilot (NOI19_pilot) |
C++14 |
|
737 ms |
83192 KB |
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;
ll n,m,ar[N],sum,t,ans[N],sz[N],dad[N],l=0;
lli p[N],pl[N];
ll find(ll x)
{
if(dad[x]==x)
return x;
return dad[x]=find(dad[x]);
}
void unite(int x,int y)
{
int dx=find(x);
int dy=find(y);
if(dx==dy)
return;
sz[dx]+=sz[dy];
dad[dy]=dx;
}
void f(int x,int z)
{
if(find(x)==find(z))
return;
int y=find(z);
y=sz[y];
sum+=sz[find(x)]*y;
// cout<<x<<sp<<y<<sp<<sz[find(x)]<<sp<<sz[find(y)]<<endl;
unite(x,z);
}
void add(int ind)
{
while(p[l+1].fi<=pl[ind].fi && l<n)
{
l++;
int x=p[l].se;
sum++;
// cout<<"[d]"<<sp<<ind<<endl;
if(ar[x-1]<=ar[x] && x-1!=0)
f(x,x-1);
if(ar[x+1]<=ar[x] && x+1!=n+1)
f(x,x+1);
}
}
int main()
{
fast;
cin>>n>>m;
fo(i,1,n)
dad[i]=i,sz[i]=1;
fo(i,1,n)
cin>>p[i].fi,p[i].se=i,ar[i]=p[i].fi;
// cout<<endl;
// fo(i,1,n)
// cout<<ar[i]<<sp;
// cout<<endl<<endl;
fo(i,1,m)
cin>>pl[i].fi,pl[i].se=i;
sort(p+1,p+n+1);
sort(pl+1,pl+m+1);
fo(i,1,m)
{
add(i);
ans[pl[i].se]=sum;
}
fo(i,1,m)
cout<<ans[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
4736 KB |
Output is correct |
2 |
Correct |
30 ms |
4864 KB |
Output is correct |
3 |
Correct |
32 ms |
4640 KB |
Output is correct |
4 |
Correct |
29 ms |
4480 KB |
Output is correct |
5 |
Correct |
29 ms |
4480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
8312 KB |
Output is correct |
2 |
Correct |
50 ms |
8444 KB |
Output is correct |
3 |
Correct |
48 ms |
8312 KB |
Output is correct |
4 |
Correct |
49 ms |
8568 KB |
Output is correct |
5 |
Correct |
49 ms |
8312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
8440 KB |
Output is correct |
2 |
Correct |
56 ms |
8568 KB |
Output is correct |
3 |
Correct |
51 ms |
8440 KB |
Output is correct |
4 |
Correct |
50 ms |
8696 KB |
Output is correct |
5 |
Correct |
53 ms |
8696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
30 ms |
4736 KB |
Output is correct |
12 |
Correct |
30 ms |
4864 KB |
Output is correct |
13 |
Correct |
32 ms |
4640 KB |
Output is correct |
14 |
Correct |
29 ms |
4480 KB |
Output is correct |
15 |
Correct |
29 ms |
4480 KB |
Output is correct |
16 |
Correct |
26 ms |
4608 KB |
Output is correct |
17 |
Correct |
29 ms |
4864 KB |
Output is correct |
18 |
Correct |
27 ms |
4992 KB |
Output is correct |
19 |
Correct |
26 ms |
4480 KB |
Output is correct |
20 |
Correct |
27 ms |
4736 KB |
Output is correct |
21 |
Correct |
28 ms |
4480 KB |
Output is correct |
22 |
Correct |
26 ms |
4608 KB |
Output is correct |
23 |
Correct |
29 ms |
4992 KB |
Output is correct |
24 |
Correct |
25 ms |
4608 KB |
Output is correct |
25 |
Correct |
30 ms |
4736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
30 ms |
4736 KB |
Output is correct |
27 |
Correct |
30 ms |
4864 KB |
Output is correct |
28 |
Correct |
32 ms |
4640 KB |
Output is correct |
29 |
Correct |
29 ms |
4480 KB |
Output is correct |
30 |
Correct |
29 ms |
4480 KB |
Output is correct |
31 |
Correct |
47 ms |
8312 KB |
Output is correct |
32 |
Correct |
50 ms |
8444 KB |
Output is correct |
33 |
Correct |
48 ms |
8312 KB |
Output is correct |
34 |
Correct |
49 ms |
8568 KB |
Output is correct |
35 |
Correct |
49 ms |
8312 KB |
Output is correct |
36 |
Correct |
54 ms |
8440 KB |
Output is correct |
37 |
Correct |
56 ms |
8568 KB |
Output is correct |
38 |
Correct |
51 ms |
8440 KB |
Output is correct |
39 |
Correct |
50 ms |
8696 KB |
Output is correct |
40 |
Correct |
53 ms |
8696 KB |
Output is correct |
41 |
Correct |
26 ms |
4608 KB |
Output is correct |
42 |
Correct |
29 ms |
4864 KB |
Output is correct |
43 |
Correct |
27 ms |
4992 KB |
Output is correct |
44 |
Correct |
26 ms |
4480 KB |
Output is correct |
45 |
Correct |
27 ms |
4736 KB |
Output is correct |
46 |
Correct |
28 ms |
4480 KB |
Output is correct |
47 |
Correct |
26 ms |
4608 KB |
Output is correct |
48 |
Correct |
29 ms |
4992 KB |
Output is correct |
49 |
Correct |
25 ms |
4608 KB |
Output is correct |
50 |
Correct |
30 ms |
4736 KB |
Output is correct |
51 |
Correct |
60 ms |
8440 KB |
Output is correct |
52 |
Correct |
62 ms |
8440 KB |
Output is correct |
53 |
Correct |
59 ms |
8440 KB |
Output is correct |
54 |
Correct |
59 ms |
8172 KB |
Output is correct |
55 |
Correct |
58 ms |
8440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
30 ms |
4736 KB |
Output is correct |
27 |
Correct |
30 ms |
4864 KB |
Output is correct |
28 |
Correct |
32 ms |
4640 KB |
Output is correct |
29 |
Correct |
29 ms |
4480 KB |
Output is correct |
30 |
Correct |
29 ms |
4480 KB |
Output is correct |
31 |
Correct |
47 ms |
8312 KB |
Output is correct |
32 |
Correct |
50 ms |
8444 KB |
Output is correct |
33 |
Correct |
48 ms |
8312 KB |
Output is correct |
34 |
Correct |
49 ms |
8568 KB |
Output is correct |
35 |
Correct |
49 ms |
8312 KB |
Output is correct |
36 |
Correct |
54 ms |
8440 KB |
Output is correct |
37 |
Correct |
56 ms |
8568 KB |
Output is correct |
38 |
Correct |
51 ms |
8440 KB |
Output is correct |
39 |
Correct |
50 ms |
8696 KB |
Output is correct |
40 |
Correct |
53 ms |
8696 KB |
Output is correct |
41 |
Correct |
26 ms |
4608 KB |
Output is correct |
42 |
Correct |
29 ms |
4864 KB |
Output is correct |
43 |
Correct |
27 ms |
4992 KB |
Output is correct |
44 |
Correct |
26 ms |
4480 KB |
Output is correct |
45 |
Correct |
27 ms |
4736 KB |
Output is correct |
46 |
Correct |
28 ms |
4480 KB |
Output is correct |
47 |
Correct |
26 ms |
4608 KB |
Output is correct |
48 |
Correct |
29 ms |
4992 KB |
Output is correct |
49 |
Correct |
25 ms |
4608 KB |
Output is correct |
50 |
Correct |
30 ms |
4736 KB |
Output is correct |
51 |
Correct |
60 ms |
8440 KB |
Output is correct |
52 |
Correct |
62 ms |
8440 KB |
Output is correct |
53 |
Correct |
59 ms |
8440 KB |
Output is correct |
54 |
Correct |
59 ms |
8172 KB |
Output is correct |
55 |
Correct |
58 ms |
8440 KB |
Output is correct |
56 |
Correct |
684 ms |
80924 KB |
Output is correct |
57 |
Correct |
691 ms |
80888 KB |
Output is correct |
58 |
Correct |
624 ms |
76280 KB |
Output is correct |
59 |
Correct |
653 ms |
78200 KB |
Output is correct |
60 |
Correct |
737 ms |
83192 KB |
Output is correct |