#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
//#include "supertrees.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define all(x) x.begin(),x.end()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mxn=1e6,mod=998244353,lg=20,root=80,inf=1e9;
void setIO(string name) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int n,m,ct,sum=0,k;
vector<int>pos[mxn+10];
set<int>cur;
int pre[mxn+10],pa[mxn+10],sz[mxn+10];
int find(int u){
if(pa[u]==u)return u;
return pa[u]=find(pa[u]);
}
void solve(int u,int v){
int a=find(u),b=find(v);
if(a==b)return;
sum-=(pre[sz[a]]+pre[sz[b]]);
if(sz[a]>sz[b]){
pa[b]=a;
sz[a]+=sz[b];
sum+=pre[sz[a]];
return;
}
pa[a]=b;
sz[b]+=sz[a];
sum+=pre[sz[b]];
}
int32_t main(){
fastio
cin>>n>>m;
vector<int>v(n+1);
for(int i=1;i<=n;i++){
cin>>v[i];
pos[v[i]].pb(i);
}
sz[0]=1;
for(int i=1;i<=mxn;i++)pre[i]=pre[i-1]+i,sz[i]=1,pa[i]=i;
ct=0;
vector<pii>q(m);
vector<int>ans(m);
for(int i=0;i<m;i++){
cin>>q[i].f;
q[i].s=i;
}
cur.insert(0);
cur.insert(n+1);
sort(q.begin(),q.end());
for(int i=0;i<m;i++){
while(ct<=q[i].f){
for(auto j:pos[ct]){
sum++;
if((j-1)&&(v[j-1]<=ct))solve(j,j-1);
if(j+1<=n&&v[j+1]<=ct)solve(j,j+1);
}
ct++;
}
ans[q[i].s]=sum;
}
for(auto i:ans)cout<<i<<'\n';
return 0;
}
Compilation message
pilot.cpp: In function 'void setIO(std::string)':
pilot.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:33:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
13 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
12 ms |
47196 KB |
Output is correct |
14 |
Correct |
12 ms |
47192 KB |
Output is correct |
15 |
Correct |
13 ms |
47292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
13 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
12 ms |
47196 KB |
Output is correct |
14 |
Correct |
12 ms |
47192 KB |
Output is correct |
15 |
Correct |
13 ms |
47292 KB |
Output is correct |
16 |
Correct |
12 ms |
47192 KB |
Output is correct |
17 |
Correct |
13 ms |
47192 KB |
Output is correct |
18 |
Correct |
13 ms |
47192 KB |
Output is correct |
19 |
Correct |
13 ms |
47192 KB |
Output is correct |
20 |
Correct |
13 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
13 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
12 ms |
47196 KB |
Output is correct |
14 |
Correct |
12 ms |
47192 KB |
Output is correct |
15 |
Correct |
13 ms |
47292 KB |
Output is correct |
16 |
Correct |
12 ms |
47192 KB |
Output is correct |
17 |
Correct |
13 ms |
47192 KB |
Output is correct |
18 |
Correct |
13 ms |
47192 KB |
Output is correct |
19 |
Correct |
13 ms |
47192 KB |
Output is correct |
20 |
Correct |
13 ms |
47196 KB |
Output is correct |
21 |
Correct |
13 ms |
47448 KB |
Output is correct |
22 |
Correct |
13 ms |
47452 KB |
Output is correct |
23 |
Correct |
13 ms |
47452 KB |
Output is correct |
24 |
Correct |
13 ms |
47452 KB |
Output is correct |
25 |
Correct |
13 ms |
47452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
50008 KB |
Output is correct |
2 |
Correct |
48 ms |
51028 KB |
Output is correct |
3 |
Correct |
32 ms |
50008 KB |
Output is correct |
4 |
Correct |
40 ms |
50776 KB |
Output is correct |
5 |
Correct |
30 ms |
50008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
54108 KB |
Output is correct |
2 |
Correct |
43 ms |
54100 KB |
Output is correct |
3 |
Correct |
42 ms |
54096 KB |
Output is correct |
4 |
Correct |
43 ms |
54356 KB |
Output is correct |
5 |
Correct |
42 ms |
54100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
54184 KB |
Output is correct |
2 |
Correct |
48 ms |
54156 KB |
Output is correct |
3 |
Correct |
48 ms |
54212 KB |
Output is correct |
4 |
Correct |
56 ms |
54356 KB |
Output is correct |
5 |
Correct |
56 ms |
54352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
31 ms |
50008 KB |
Output is correct |
12 |
Correct |
48 ms |
51028 KB |
Output is correct |
13 |
Correct |
32 ms |
50008 KB |
Output is correct |
14 |
Correct |
40 ms |
50776 KB |
Output is correct |
15 |
Correct |
30 ms |
50008 KB |
Output is correct |
16 |
Correct |
27 ms |
50008 KB |
Output is correct |
17 |
Correct |
34 ms |
51024 KB |
Output is correct |
18 |
Correct |
33 ms |
51032 KB |
Output is correct |
19 |
Correct |
29 ms |
50008 KB |
Output is correct |
20 |
Correct |
42 ms |
51024 KB |
Output is correct |
21 |
Correct |
29 ms |
50004 KB |
Output is correct |
22 |
Correct |
35 ms |
50692 KB |
Output is correct |
23 |
Correct |
27 ms |
50264 KB |
Output is correct |
24 |
Correct |
39 ms |
50768 KB |
Output is correct |
25 |
Correct |
27 ms |
50008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
13 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
12 ms |
47196 KB |
Output is correct |
14 |
Correct |
12 ms |
47192 KB |
Output is correct |
15 |
Correct |
13 ms |
47292 KB |
Output is correct |
16 |
Correct |
12 ms |
47192 KB |
Output is correct |
17 |
Correct |
13 ms |
47192 KB |
Output is correct |
18 |
Correct |
13 ms |
47192 KB |
Output is correct |
19 |
Correct |
13 ms |
47192 KB |
Output is correct |
20 |
Correct |
13 ms |
47196 KB |
Output is correct |
21 |
Correct |
13 ms |
47448 KB |
Output is correct |
22 |
Correct |
13 ms |
47452 KB |
Output is correct |
23 |
Correct |
13 ms |
47452 KB |
Output is correct |
24 |
Correct |
13 ms |
47452 KB |
Output is correct |
25 |
Correct |
13 ms |
47452 KB |
Output is correct |
26 |
Correct |
31 ms |
50008 KB |
Output is correct |
27 |
Correct |
48 ms |
51028 KB |
Output is correct |
28 |
Correct |
32 ms |
50008 KB |
Output is correct |
29 |
Correct |
40 ms |
50776 KB |
Output is correct |
30 |
Correct |
30 ms |
50008 KB |
Output is correct |
31 |
Correct |
42 ms |
54108 KB |
Output is correct |
32 |
Correct |
43 ms |
54100 KB |
Output is correct |
33 |
Correct |
42 ms |
54096 KB |
Output is correct |
34 |
Correct |
43 ms |
54356 KB |
Output is correct |
35 |
Correct |
42 ms |
54100 KB |
Output is correct |
36 |
Correct |
45 ms |
54184 KB |
Output is correct |
37 |
Correct |
48 ms |
54156 KB |
Output is correct |
38 |
Correct |
48 ms |
54212 KB |
Output is correct |
39 |
Correct |
56 ms |
54356 KB |
Output is correct |
40 |
Correct |
56 ms |
54352 KB |
Output is correct |
41 |
Correct |
27 ms |
50008 KB |
Output is correct |
42 |
Correct |
34 ms |
51024 KB |
Output is correct |
43 |
Correct |
33 ms |
51032 KB |
Output is correct |
44 |
Correct |
29 ms |
50008 KB |
Output is correct |
45 |
Correct |
42 ms |
51024 KB |
Output is correct |
46 |
Correct |
29 ms |
50004 KB |
Output is correct |
47 |
Correct |
35 ms |
50692 KB |
Output is correct |
48 |
Correct |
27 ms |
50264 KB |
Output is correct |
49 |
Correct |
39 ms |
50768 KB |
Output is correct |
50 |
Correct |
27 ms |
50008 KB |
Output is correct |
51 |
Correct |
51 ms |
53076 KB |
Output is correct |
52 |
Correct |
64 ms |
53868 KB |
Output is correct |
53 |
Correct |
51 ms |
53072 KB |
Output is correct |
54 |
Correct |
62 ms |
53840 KB |
Output is correct |
55 |
Correct |
51 ms |
53080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47668 KB |
Output is correct |
2 |
Correct |
12 ms |
47192 KB |
Output is correct |
3 |
Correct |
13 ms |
47192 KB |
Output is correct |
4 |
Correct |
11 ms |
47196 KB |
Output is correct |
5 |
Correct |
13 ms |
47192 KB |
Output is correct |
6 |
Correct |
11 ms |
47192 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
11 ms |
47192 KB |
Output is correct |
9 |
Correct |
12 ms |
47196 KB |
Output is correct |
10 |
Correct |
12 ms |
47304 KB |
Output is correct |
11 |
Correct |
13 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
12 ms |
47196 KB |
Output is correct |
14 |
Correct |
12 ms |
47192 KB |
Output is correct |
15 |
Correct |
13 ms |
47292 KB |
Output is correct |
16 |
Correct |
12 ms |
47192 KB |
Output is correct |
17 |
Correct |
13 ms |
47192 KB |
Output is correct |
18 |
Correct |
13 ms |
47192 KB |
Output is correct |
19 |
Correct |
13 ms |
47192 KB |
Output is correct |
20 |
Correct |
13 ms |
47196 KB |
Output is correct |
21 |
Correct |
13 ms |
47448 KB |
Output is correct |
22 |
Correct |
13 ms |
47452 KB |
Output is correct |
23 |
Correct |
13 ms |
47452 KB |
Output is correct |
24 |
Correct |
13 ms |
47452 KB |
Output is correct |
25 |
Correct |
13 ms |
47452 KB |
Output is correct |
26 |
Correct |
31 ms |
50008 KB |
Output is correct |
27 |
Correct |
48 ms |
51028 KB |
Output is correct |
28 |
Correct |
32 ms |
50008 KB |
Output is correct |
29 |
Correct |
40 ms |
50776 KB |
Output is correct |
30 |
Correct |
30 ms |
50008 KB |
Output is correct |
31 |
Correct |
42 ms |
54108 KB |
Output is correct |
32 |
Correct |
43 ms |
54100 KB |
Output is correct |
33 |
Correct |
42 ms |
54096 KB |
Output is correct |
34 |
Correct |
43 ms |
54356 KB |
Output is correct |
35 |
Correct |
42 ms |
54100 KB |
Output is correct |
36 |
Correct |
45 ms |
54184 KB |
Output is correct |
37 |
Correct |
48 ms |
54156 KB |
Output is correct |
38 |
Correct |
48 ms |
54212 KB |
Output is correct |
39 |
Correct |
56 ms |
54356 KB |
Output is correct |
40 |
Correct |
56 ms |
54352 KB |
Output is correct |
41 |
Correct |
27 ms |
50008 KB |
Output is correct |
42 |
Correct |
34 ms |
51024 KB |
Output is correct |
43 |
Correct |
33 ms |
51032 KB |
Output is correct |
44 |
Correct |
29 ms |
50008 KB |
Output is correct |
45 |
Correct |
42 ms |
51024 KB |
Output is correct |
46 |
Correct |
29 ms |
50004 KB |
Output is correct |
47 |
Correct |
35 ms |
50692 KB |
Output is correct |
48 |
Correct |
27 ms |
50264 KB |
Output is correct |
49 |
Correct |
39 ms |
50768 KB |
Output is correct |
50 |
Correct |
27 ms |
50008 KB |
Output is correct |
51 |
Correct |
51 ms |
53076 KB |
Output is correct |
52 |
Correct |
64 ms |
53868 KB |
Output is correct |
53 |
Correct |
51 ms |
53072 KB |
Output is correct |
54 |
Correct |
62 ms |
53840 KB |
Output is correct |
55 |
Correct |
51 ms |
53080 KB |
Output is correct |
56 |
Correct |
637 ms |
105292 KB |
Output is correct |
57 |
Correct |
594 ms |
117916 KB |
Output is correct |
58 |
Correct |
604 ms |
113912 KB |
Output is correct |
59 |
Correct |
610 ms |
116100 KB |
Output is correct |
60 |
Correct |
657 ms |
119940 KB |
Output is correct |