#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#define str string
#define append push_back
#define int long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl "\n"
#define all(ls) ls.begin(),ls.end()
#define sorted(ls) sort(ls.begin(),ls.end());
#define reversed(ls) reverse(ls.begin(),ls.end());
#define print(n) for(auto i:n)cout<<i<<' ';cout<<endl;
#define input(n,ls,m) vector<n>ls(m);for(int i=0;i<m;i++)cin>>ls[i];
#define ff first
#define ss second
int const N=3e5+10;
int const LG=21;
int mod=1e9+7;
int mod1=998244353;
int sum_(vector<int>ls){int s=0;for(auto i:ls)s+=i;return s;}
int min(int a,int b){if (a>b){return b;}return a;}
int max(int a,int b){if (a<b){return b;}return a;}
//......................................tHe ReaL cOdE beGinS HerE......................................//
void solve(){
int n,Q;
cin>>n>>Q;
int ls[n+1];
ls[0]=0;
for(int i=1;i<=n;i++){
cin>>ls[i];
}
vector<int> q;
vector<pair<int,int>>m;
for(int i=0;i<Q;i++){
int a;
cin>>a;
q.append(a);
m.append({a,i});
}
sorted(m);
sorted(q);
set<pair<int,int>>s;
set<int>t;
s.clear();
int ans=0;
int last=0;
for(int i=1;i<=n;i++){
if(ls[i]>q[0]) s.insert({ls[i],i});
else {ans+=i-last;continue;}
last=i;
t.insert(i);
}
// print(t);
m[0].ff=ans;
swap(m[0].ff,m[0].ss);
for(int i=1;i<Q;i++){
int a=q[i];
int cnt=0;
while(s.size() and (*s.begin()).ff<=a){
int x=(*s.begin()).ff,ind=(*s.begin()).ss;
cnt++;
int l,r;
if(ind==*t.begin()) l=1;
else l=(*(--t.find(ind)))+1;
if(ind==*t.rbegin()) r=n;
else r=(*(++t.find(ind)))-1;
ans+=1+(ind-l)*(r-ind)+(r-ind)+(ind-l);
t.erase(t.find(ind));
s.erase(s.begin());
}
m[i].ff=ans;
swap(m[i].ff,m[i].ss);
}
sorted(m);
for(auto [i,j]:m) cout<<j<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--)
solve();
}
Compilation message
pilot.cpp: In function 'void solve()':
pilot.cpp:87:17: warning: unused variable 'x' [-Wunused-variable]
87 | int x=(*s.begin()).ff,ind=(*s.begin()).ss;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1760 KB |
Output is correct |
2 |
Correct |
6 ms |
1844 KB |
Output is correct |
3 |
Correct |
6 ms |
1628 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
6 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
15624 KB |
Output is correct |
2 |
Correct |
68 ms |
15552 KB |
Output is correct |
3 |
Correct |
71 ms |
15288 KB |
Output is correct |
4 |
Correct |
74 ms |
16052 KB |
Output is correct |
5 |
Correct |
66 ms |
15288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
15928 KB |
Output is correct |
2 |
Correct |
72 ms |
15584 KB |
Output is correct |
3 |
Correct |
71 ms |
15424 KB |
Output is correct |
4 |
Correct |
74 ms |
16396 KB |
Output is correct |
5 |
Correct |
70 ms |
16024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
1760 KB |
Output is correct |
12 |
Correct |
6 ms |
1844 KB |
Output is correct |
13 |
Correct |
6 ms |
1628 KB |
Output is correct |
14 |
Correct |
6 ms |
1628 KB |
Output is correct |
15 |
Correct |
6 ms |
1628 KB |
Output is correct |
16 |
Correct |
22 ms |
4700 KB |
Output is correct |
17 |
Correct |
40 ms |
8784 KB |
Output is correct |
18 |
Correct |
48 ms |
11344 KB |
Output is correct |
19 |
Correct |
49 ms |
10540 KB |
Output is correct |
20 |
Correct |
27 ms |
7004 KB |
Output is correct |
21 |
Correct |
6 ms |
1540 KB |
Output is correct |
22 |
Correct |
25 ms |
6480 KB |
Output is correct |
23 |
Correct |
42 ms |
9508 KB |
Output is correct |
24 |
Correct |
39 ms |
9892 KB |
Output is correct |
25 |
Correct |
29 ms |
6700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
6 ms |
1760 KB |
Output is correct |
27 |
Correct |
6 ms |
1844 KB |
Output is correct |
28 |
Correct |
6 ms |
1628 KB |
Output is correct |
29 |
Correct |
6 ms |
1628 KB |
Output is correct |
30 |
Correct |
6 ms |
1628 KB |
Output is correct |
31 |
Correct |
67 ms |
15624 KB |
Output is correct |
32 |
Correct |
68 ms |
15552 KB |
Output is correct |
33 |
Correct |
71 ms |
15288 KB |
Output is correct |
34 |
Correct |
74 ms |
16052 KB |
Output is correct |
35 |
Correct |
66 ms |
15288 KB |
Output is correct |
36 |
Correct |
72 ms |
15928 KB |
Output is correct |
37 |
Correct |
72 ms |
15584 KB |
Output is correct |
38 |
Correct |
71 ms |
15424 KB |
Output is correct |
39 |
Correct |
74 ms |
16396 KB |
Output is correct |
40 |
Correct |
70 ms |
16024 KB |
Output is correct |
41 |
Correct |
22 ms |
4700 KB |
Output is correct |
42 |
Correct |
40 ms |
8784 KB |
Output is correct |
43 |
Correct |
48 ms |
11344 KB |
Output is correct |
44 |
Correct |
49 ms |
10540 KB |
Output is correct |
45 |
Correct |
27 ms |
7004 KB |
Output is correct |
46 |
Correct |
6 ms |
1540 KB |
Output is correct |
47 |
Correct |
25 ms |
6480 KB |
Output is correct |
48 |
Correct |
42 ms |
9508 KB |
Output is correct |
49 |
Correct |
39 ms |
9892 KB |
Output is correct |
50 |
Correct |
29 ms |
6700 KB |
Output is correct |
51 |
Correct |
123 ms |
15800 KB |
Output is correct |
52 |
Correct |
121 ms |
15548 KB |
Output is correct |
53 |
Correct |
123 ms |
16056 KB |
Output is correct |
54 |
Correct |
121 ms |
15552 KB |
Output is correct |
55 |
Correct |
126 ms |
16052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
496 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
6 ms |
1760 KB |
Output is correct |
27 |
Correct |
6 ms |
1844 KB |
Output is correct |
28 |
Correct |
6 ms |
1628 KB |
Output is correct |
29 |
Correct |
6 ms |
1628 KB |
Output is correct |
30 |
Correct |
6 ms |
1628 KB |
Output is correct |
31 |
Correct |
67 ms |
15624 KB |
Output is correct |
32 |
Correct |
68 ms |
15552 KB |
Output is correct |
33 |
Correct |
71 ms |
15288 KB |
Output is correct |
34 |
Correct |
74 ms |
16052 KB |
Output is correct |
35 |
Correct |
66 ms |
15288 KB |
Output is correct |
36 |
Correct |
72 ms |
15928 KB |
Output is correct |
37 |
Correct |
72 ms |
15584 KB |
Output is correct |
38 |
Correct |
71 ms |
15424 KB |
Output is correct |
39 |
Correct |
74 ms |
16396 KB |
Output is correct |
40 |
Correct |
70 ms |
16024 KB |
Output is correct |
41 |
Correct |
22 ms |
4700 KB |
Output is correct |
42 |
Correct |
40 ms |
8784 KB |
Output is correct |
43 |
Correct |
48 ms |
11344 KB |
Output is correct |
44 |
Correct |
49 ms |
10540 KB |
Output is correct |
45 |
Correct |
27 ms |
7004 KB |
Output is correct |
46 |
Correct |
6 ms |
1540 KB |
Output is correct |
47 |
Correct |
25 ms |
6480 KB |
Output is correct |
48 |
Correct |
42 ms |
9508 KB |
Output is correct |
49 |
Correct |
39 ms |
9892 KB |
Output is correct |
50 |
Correct |
29 ms |
6700 KB |
Output is correct |
51 |
Correct |
123 ms |
15800 KB |
Output is correct |
52 |
Correct |
121 ms |
15548 KB |
Output is correct |
53 |
Correct |
123 ms |
16056 KB |
Output is correct |
54 |
Correct |
121 ms |
15552 KB |
Output is correct |
55 |
Correct |
126 ms |
16052 KB |
Output is correct |
56 |
Execution timed out |
1048 ms |
137060 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |