#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 1e6, mxm = 1e5;
int n, q;
int h[mxn + 1], y[mxn + 1], l[mxn + 1], r[mxn + 1], ok[mxn + 1];
ll a[mxn + 1], res[mxn + 1];
set<int>bad;
ll ans = 0;
ll sm(ll x){
return(x * (x + 1) / 2);
}
void add(int id){
if(ok[id - 1] && ok[id + 1]){
r[id] = r[id + 1]; l[id] = l[id - 1]; l[r[id + 1]] = l[id - 1]; r[l[id - 1]] = r[id + 1];
ans -= sm(id - 1 - l[id - 1] + 1); ans -= sm(r[id + 1] - id);
ans += sm(r[id + 1] - l[id - 1] + 1);
}else if(ok[id - 1]){
l[id] = l[id - 1]; r[l[id - 1]] = id; ans -= sm(id - 1 - l[id - 1] + 1); ans += sm(id - l[id - 1] + 1);
}else if(ok[id + 1]){
r[id] = r[id + 1]; l[r[id + 1]] = id; ans -= sm(r[id + 1] - id); ans += sm(r[id + 1] - id + 1);
}else{
ans++;
}
ok[id] = 1;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
vt<pii>comp;
for(int i = 1; i <= n; i++){
cin >> a[i]; comp.pb(make_pair(a[i], i));
}
for(int i = 1; i <= n; i++){
l[i] = r[i] = i; ok[i] = 0;
}
vt<pii>queries;
forr(i, 0, q){
int y; cin >> y;
queries.pb({y, i});
}
sort(queries.begin(), queries.end()); sort(comp.begin(), comp.end());
int R = 0;
for(auto [y, id]: queries){
while(R < sz(comp) && comp[R].fi <= y){
add(comp[R].se); R++;
}
res[id] = ans;
}
forr(i, 0, q){
cout << res[i] << "\n";
}
return(0);
}
Compilation message
pilot.cpp: In function 'int main()':
pilot.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
64 | for(auto [y, id]: queries){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3612 KB |
Output is correct |
2 |
Correct |
16 ms |
3792 KB |
Output is correct |
3 |
Correct |
15 ms |
3536 KB |
Output is correct |
4 |
Correct |
15 ms |
3488 KB |
Output is correct |
5 |
Correct |
15 ms |
3480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
6724 KB |
Output is correct |
2 |
Correct |
35 ms |
6396 KB |
Output is correct |
3 |
Correct |
29 ms |
6304 KB |
Output is correct |
4 |
Correct |
30 ms |
6472 KB |
Output is correct |
5 |
Correct |
28 ms |
6316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
6364 KB |
Output is correct |
2 |
Correct |
32 ms |
6348 KB |
Output is correct |
3 |
Correct |
31 ms |
6296 KB |
Output is correct |
4 |
Correct |
31 ms |
6480 KB |
Output is correct |
5 |
Correct |
31 ms |
6564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
16 ms |
3612 KB |
Output is correct |
12 |
Correct |
16 ms |
3792 KB |
Output is correct |
13 |
Correct |
15 ms |
3536 KB |
Output is correct |
14 |
Correct |
15 ms |
3488 KB |
Output is correct |
15 |
Correct |
15 ms |
3480 KB |
Output is correct |
16 |
Correct |
15 ms |
3536 KB |
Output is correct |
17 |
Correct |
14 ms |
3748 KB |
Output is correct |
18 |
Correct |
15 ms |
3836 KB |
Output is correct |
19 |
Correct |
14 ms |
3532 KB |
Output is correct |
20 |
Correct |
15 ms |
3732 KB |
Output is correct |
21 |
Correct |
15 ms |
3440 KB |
Output is correct |
22 |
Correct |
14 ms |
3668 KB |
Output is correct |
23 |
Correct |
15 ms |
3700 KB |
Output is correct |
24 |
Correct |
14 ms |
3608 KB |
Output is correct |
25 |
Correct |
15 ms |
3664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
16 ms |
3612 KB |
Output is correct |
27 |
Correct |
16 ms |
3792 KB |
Output is correct |
28 |
Correct |
15 ms |
3536 KB |
Output is correct |
29 |
Correct |
15 ms |
3488 KB |
Output is correct |
30 |
Correct |
15 ms |
3480 KB |
Output is correct |
31 |
Correct |
33 ms |
6724 KB |
Output is correct |
32 |
Correct |
35 ms |
6396 KB |
Output is correct |
33 |
Correct |
29 ms |
6304 KB |
Output is correct |
34 |
Correct |
30 ms |
6472 KB |
Output is correct |
35 |
Correct |
28 ms |
6316 KB |
Output is correct |
36 |
Correct |
30 ms |
6364 KB |
Output is correct |
37 |
Correct |
32 ms |
6348 KB |
Output is correct |
38 |
Correct |
31 ms |
6296 KB |
Output is correct |
39 |
Correct |
31 ms |
6480 KB |
Output is correct |
40 |
Correct |
31 ms |
6564 KB |
Output is correct |
41 |
Correct |
15 ms |
3536 KB |
Output is correct |
42 |
Correct |
14 ms |
3748 KB |
Output is correct |
43 |
Correct |
15 ms |
3836 KB |
Output is correct |
44 |
Correct |
14 ms |
3532 KB |
Output is correct |
45 |
Correct |
15 ms |
3732 KB |
Output is correct |
46 |
Correct |
15 ms |
3440 KB |
Output is correct |
47 |
Correct |
14 ms |
3668 KB |
Output is correct |
48 |
Correct |
15 ms |
3700 KB |
Output is correct |
49 |
Correct |
14 ms |
3608 KB |
Output is correct |
50 |
Correct |
15 ms |
3664 KB |
Output is correct |
51 |
Correct |
36 ms |
6280 KB |
Output is correct |
52 |
Correct |
36 ms |
6052 KB |
Output is correct |
53 |
Correct |
39 ms |
6292 KB |
Output is correct |
54 |
Correct |
36 ms |
6008 KB |
Output is correct |
55 |
Correct |
35 ms |
6364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
16 ms |
3612 KB |
Output is correct |
27 |
Correct |
16 ms |
3792 KB |
Output is correct |
28 |
Correct |
15 ms |
3536 KB |
Output is correct |
29 |
Correct |
15 ms |
3488 KB |
Output is correct |
30 |
Correct |
15 ms |
3480 KB |
Output is correct |
31 |
Correct |
33 ms |
6724 KB |
Output is correct |
32 |
Correct |
35 ms |
6396 KB |
Output is correct |
33 |
Correct |
29 ms |
6304 KB |
Output is correct |
34 |
Correct |
30 ms |
6472 KB |
Output is correct |
35 |
Correct |
28 ms |
6316 KB |
Output is correct |
36 |
Correct |
30 ms |
6364 KB |
Output is correct |
37 |
Correct |
32 ms |
6348 KB |
Output is correct |
38 |
Correct |
31 ms |
6296 KB |
Output is correct |
39 |
Correct |
31 ms |
6480 KB |
Output is correct |
40 |
Correct |
31 ms |
6564 KB |
Output is correct |
41 |
Correct |
15 ms |
3536 KB |
Output is correct |
42 |
Correct |
14 ms |
3748 KB |
Output is correct |
43 |
Correct |
15 ms |
3836 KB |
Output is correct |
44 |
Correct |
14 ms |
3532 KB |
Output is correct |
45 |
Correct |
15 ms |
3732 KB |
Output is correct |
46 |
Correct |
15 ms |
3440 KB |
Output is correct |
47 |
Correct |
14 ms |
3668 KB |
Output is correct |
48 |
Correct |
15 ms |
3700 KB |
Output is correct |
49 |
Correct |
14 ms |
3608 KB |
Output is correct |
50 |
Correct |
15 ms |
3664 KB |
Output is correct |
51 |
Correct |
36 ms |
6280 KB |
Output is correct |
52 |
Correct |
36 ms |
6052 KB |
Output is correct |
53 |
Correct |
39 ms |
6292 KB |
Output is correct |
54 |
Correct |
36 ms |
6008 KB |
Output is correct |
55 |
Correct |
35 ms |
6364 KB |
Output is correct |
56 |
Correct |
431 ms |
50088 KB |
Output is correct |
57 |
Correct |
418 ms |
62124 KB |
Output is correct |
58 |
Correct |
390 ms |
58540 KB |
Output is correct |
59 |
Correct |
407 ms |
60088 KB |
Output is correct |
60 |
Correct |
427 ms |
63752 KB |
Output is correct |