# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1062381 |
2024-08-17T05:27:17 Z |
CodeLakVN |
Pilot (NOI19_pilot) |
C++17 |
|
332 ms |
98132 KB |
#include <bits/stdc++.h>
#define no "NO"
#define yes "YES"
#define F first
#define S second
#define vec vector
#define task "PILOT"
#define ll long long
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())
using namespace std;
template<typename U, typename V> bool maximize(U &a, V b) {
if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool minimize(U &a, V b) {
if (a > b) { a = b; return 1; } return 0;
}
const int N = (int)1e6 + 9;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int n, numQuery;
int a[N], query[N];
namespace sub3 {
bool valid() {
return max(n, numQuery) <= 200;
}
void solve() {
FOR(i, 1, numQuery) {
int ans = 0;
FOR(s, 1, n) {
if (a[s] > query[i]) continue;
FOR(e, s, n) {
if (a[e] <= query[i]) ans++;
else break;
}
}
cout << ans << "\n";
}
}
}
namespace sub4 {
bool valid() {
return 1LL * n * numQuery <= (ll)1e8;
}
void solve() {
FOR(i, 1, numQuery) {
int ans = 0;
FOR(s, 1, n) {
if (a[s] > query[i]) continue;
int e = s;
while (e <=n && a[e] <= query[i]) e++;
e--;
int cnt = (e - s + 1);
ans += cnt * (cnt + 1) / 2;
s = e;
}
cout << ans << "\n";
}
}
}
namespace subFull {
vector<int> pos[N];
bool vis[N];
ll preLen[2 * N], sufLen[2 * N];
ll ans[N];
void solve() {
int maxVal = *max_element(query + 1, query + numQuery + 1);
FOR(i, 1, n) pos[a[i]].push_back(i);
memset(vis, 0, sizeof(vis));
FOR(i, 1, maxVal) {
ans[i] = ans[i - 1];
for (int x : pos[i]) {
ans[i]++;
if (vis[x - 1]) ans[i] += preLen[x - 1], sufLen[x - 1 - preLen[x - 1] + 1]++;
if (vis[x + 1]) ans[i] += sufLen[x + 1], preLen[x + 1 + sufLen[x + 1] - 1]++;
if (vis[x - 1] && vis[x + 1]) {
ans[i] += 1LL * preLen[x - 1] * sufLen[x + 1];
sufLen[x - 1 - preLen[x - 1] + 1] += sufLen[x + 1];
preLen[x + 1 + sufLen[x + 1] - 1] += preLen[x - 1];
}
preLen[x] = preLen[x - 1] + 1;
sufLen[x] = sufLen[x + 1] + 1;
vis[x] = 1;
}
}
FOR(i, 1, numQuery) {
cout << ans[query[i]] << "\n";
}
}
}
void main_code() {
cin >> n >> numQuery;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, numQuery) cin >> query[i];
subFull::solve();
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
const bool MULTITEST = 0;
int num_test = 1; if (MULTITEST) cin >> num_test;
while (num_test--) { main_code(); cout << "\n"; }
}
/* Lak lu theo dieu nhac */
Compilation message
pilot.cpp: In function 'int main()':
pilot.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
124 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36820 KB |
Output is correct |
13 |
Correct |
6 ms |
36308 KB |
Output is correct |
14 |
Correct |
6 ms |
36956 KB |
Output is correct |
15 |
Correct |
5 ms |
35540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36820 KB |
Output is correct |
13 |
Correct |
6 ms |
36308 KB |
Output is correct |
14 |
Correct |
6 ms |
36956 KB |
Output is correct |
15 |
Correct |
5 ms |
35540 KB |
Output is correct |
16 |
Correct |
7 ms |
36956 KB |
Output is correct |
17 |
Correct |
7 ms |
36956 KB |
Output is correct |
18 |
Correct |
8 ms |
36700 KB |
Output is correct |
19 |
Correct |
7 ms |
36956 KB |
Output is correct |
20 |
Correct |
7 ms |
36700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36820 KB |
Output is correct |
13 |
Correct |
6 ms |
36308 KB |
Output is correct |
14 |
Correct |
6 ms |
36956 KB |
Output is correct |
15 |
Correct |
5 ms |
35540 KB |
Output is correct |
16 |
Correct |
7 ms |
36956 KB |
Output is correct |
17 |
Correct |
7 ms |
36956 KB |
Output is correct |
18 |
Correct |
8 ms |
36700 KB |
Output is correct |
19 |
Correct |
7 ms |
36956 KB |
Output is correct |
20 |
Correct |
7 ms |
36700 KB |
Output is correct |
21 |
Correct |
8 ms |
36952 KB |
Output is correct |
22 |
Correct |
9 ms |
36956 KB |
Output is correct |
23 |
Correct |
9 ms |
36876 KB |
Output is correct |
24 |
Correct |
8 ms |
36956 KB |
Output is correct |
25 |
Correct |
7 ms |
36952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
40796 KB |
Output is correct |
2 |
Correct |
22 ms |
44124 KB |
Output is correct |
3 |
Correct |
19 ms |
40796 KB |
Output is correct |
4 |
Correct |
23 ms |
41564 KB |
Output is correct |
5 |
Correct |
25 ms |
40792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
45404 KB |
Output is correct |
2 |
Correct |
28 ms |
45392 KB |
Output is correct |
3 |
Correct |
27 ms |
45396 KB |
Output is correct |
4 |
Correct |
27 ms |
45652 KB |
Output is correct |
5 |
Correct |
28 ms |
45404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
45656 KB |
Output is correct |
2 |
Correct |
31 ms |
45656 KB |
Output is correct |
3 |
Correct |
30 ms |
45392 KB |
Output is correct |
4 |
Correct |
31 ms |
47956 KB |
Output is correct |
5 |
Correct |
31 ms |
45648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
20 ms |
40796 KB |
Output is correct |
12 |
Correct |
22 ms |
44124 KB |
Output is correct |
13 |
Correct |
19 ms |
40796 KB |
Output is correct |
14 |
Correct |
23 ms |
41564 KB |
Output is correct |
15 |
Correct |
25 ms |
40792 KB |
Output is correct |
16 |
Correct |
16 ms |
35160 KB |
Output is correct |
17 |
Correct |
19 ms |
40528 KB |
Output is correct |
18 |
Correct |
20 ms |
38492 KB |
Output is correct |
19 |
Correct |
15 ms |
32860 KB |
Output is correct |
20 |
Correct |
20 ms |
38492 KB |
Output is correct |
21 |
Correct |
16 ms |
35164 KB |
Output is correct |
22 |
Correct |
18 ms |
38340 KB |
Output is correct |
23 |
Correct |
17 ms |
37536 KB |
Output is correct |
24 |
Correct |
20 ms |
36184 KB |
Output is correct |
25 |
Correct |
18 ms |
35664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36820 KB |
Output is correct |
13 |
Correct |
6 ms |
36308 KB |
Output is correct |
14 |
Correct |
6 ms |
36956 KB |
Output is correct |
15 |
Correct |
5 ms |
35540 KB |
Output is correct |
16 |
Correct |
7 ms |
36956 KB |
Output is correct |
17 |
Correct |
7 ms |
36956 KB |
Output is correct |
18 |
Correct |
8 ms |
36700 KB |
Output is correct |
19 |
Correct |
7 ms |
36956 KB |
Output is correct |
20 |
Correct |
7 ms |
36700 KB |
Output is correct |
21 |
Correct |
8 ms |
36952 KB |
Output is correct |
22 |
Correct |
9 ms |
36956 KB |
Output is correct |
23 |
Correct |
9 ms |
36876 KB |
Output is correct |
24 |
Correct |
8 ms |
36956 KB |
Output is correct |
25 |
Correct |
7 ms |
36952 KB |
Output is correct |
26 |
Correct |
20 ms |
40796 KB |
Output is correct |
27 |
Correct |
22 ms |
44124 KB |
Output is correct |
28 |
Correct |
19 ms |
40796 KB |
Output is correct |
29 |
Correct |
23 ms |
41564 KB |
Output is correct |
30 |
Correct |
25 ms |
40792 KB |
Output is correct |
31 |
Correct |
26 ms |
45404 KB |
Output is correct |
32 |
Correct |
28 ms |
45392 KB |
Output is correct |
33 |
Correct |
27 ms |
45396 KB |
Output is correct |
34 |
Correct |
27 ms |
45652 KB |
Output is correct |
35 |
Correct |
28 ms |
45404 KB |
Output is correct |
36 |
Correct |
30 ms |
45656 KB |
Output is correct |
37 |
Correct |
31 ms |
45656 KB |
Output is correct |
38 |
Correct |
30 ms |
45392 KB |
Output is correct |
39 |
Correct |
31 ms |
47956 KB |
Output is correct |
40 |
Correct |
31 ms |
45648 KB |
Output is correct |
41 |
Correct |
16 ms |
35160 KB |
Output is correct |
42 |
Correct |
19 ms |
40528 KB |
Output is correct |
43 |
Correct |
20 ms |
38492 KB |
Output is correct |
44 |
Correct |
15 ms |
32860 KB |
Output is correct |
45 |
Correct |
20 ms |
38492 KB |
Output is correct |
46 |
Correct |
16 ms |
35164 KB |
Output is correct |
47 |
Correct |
18 ms |
38340 KB |
Output is correct |
48 |
Correct |
17 ms |
37536 KB |
Output is correct |
49 |
Correct |
20 ms |
36184 KB |
Output is correct |
50 |
Correct |
18 ms |
35664 KB |
Output is correct |
51 |
Correct |
32 ms |
44272 KB |
Output is correct |
52 |
Correct |
33 ms |
45148 KB |
Output is correct |
53 |
Correct |
36 ms |
46480 KB |
Output is correct |
54 |
Correct |
34 ms |
45140 KB |
Output is correct |
55 |
Correct |
34 ms |
46420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29020 KB |
Output is correct |
2 |
Correct |
7 ms |
33488 KB |
Output is correct |
3 |
Correct |
5 ms |
33372 KB |
Output is correct |
4 |
Correct |
6 ms |
29104 KB |
Output is correct |
5 |
Correct |
5 ms |
33236 KB |
Output is correct |
6 |
Correct |
4 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
35420 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
5 ms |
35420 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
36956 KB |
Output is correct |
12 |
Correct |
8 ms |
36820 KB |
Output is correct |
13 |
Correct |
6 ms |
36308 KB |
Output is correct |
14 |
Correct |
6 ms |
36956 KB |
Output is correct |
15 |
Correct |
5 ms |
35540 KB |
Output is correct |
16 |
Correct |
7 ms |
36956 KB |
Output is correct |
17 |
Correct |
7 ms |
36956 KB |
Output is correct |
18 |
Correct |
8 ms |
36700 KB |
Output is correct |
19 |
Correct |
7 ms |
36956 KB |
Output is correct |
20 |
Correct |
7 ms |
36700 KB |
Output is correct |
21 |
Correct |
8 ms |
36952 KB |
Output is correct |
22 |
Correct |
9 ms |
36956 KB |
Output is correct |
23 |
Correct |
9 ms |
36876 KB |
Output is correct |
24 |
Correct |
8 ms |
36956 KB |
Output is correct |
25 |
Correct |
7 ms |
36952 KB |
Output is correct |
26 |
Correct |
20 ms |
40796 KB |
Output is correct |
27 |
Correct |
22 ms |
44124 KB |
Output is correct |
28 |
Correct |
19 ms |
40796 KB |
Output is correct |
29 |
Correct |
23 ms |
41564 KB |
Output is correct |
30 |
Correct |
25 ms |
40792 KB |
Output is correct |
31 |
Correct |
26 ms |
45404 KB |
Output is correct |
32 |
Correct |
28 ms |
45392 KB |
Output is correct |
33 |
Correct |
27 ms |
45396 KB |
Output is correct |
34 |
Correct |
27 ms |
45652 KB |
Output is correct |
35 |
Correct |
28 ms |
45404 KB |
Output is correct |
36 |
Correct |
30 ms |
45656 KB |
Output is correct |
37 |
Correct |
31 ms |
45656 KB |
Output is correct |
38 |
Correct |
30 ms |
45392 KB |
Output is correct |
39 |
Correct |
31 ms |
47956 KB |
Output is correct |
40 |
Correct |
31 ms |
45648 KB |
Output is correct |
41 |
Correct |
16 ms |
35160 KB |
Output is correct |
42 |
Correct |
19 ms |
40528 KB |
Output is correct |
43 |
Correct |
20 ms |
38492 KB |
Output is correct |
44 |
Correct |
15 ms |
32860 KB |
Output is correct |
45 |
Correct |
20 ms |
38492 KB |
Output is correct |
46 |
Correct |
16 ms |
35164 KB |
Output is correct |
47 |
Correct |
18 ms |
38340 KB |
Output is correct |
48 |
Correct |
17 ms |
37536 KB |
Output is correct |
49 |
Correct |
20 ms |
36184 KB |
Output is correct |
50 |
Correct |
18 ms |
35664 KB |
Output is correct |
51 |
Correct |
32 ms |
44272 KB |
Output is correct |
52 |
Correct |
33 ms |
45148 KB |
Output is correct |
53 |
Correct |
36 ms |
46480 KB |
Output is correct |
54 |
Correct |
34 ms |
45140 KB |
Output is correct |
55 |
Correct |
34 ms |
46420 KB |
Output is correct |
56 |
Correct |
331 ms |
96084 KB |
Output is correct |
57 |
Correct |
318 ms |
97620 KB |
Output is correct |
58 |
Correct |
300 ms |
93516 KB |
Output is correct |
59 |
Correct |
327 ms |
95316 KB |
Output is correct |
60 |
Correct |
332 ms |
98132 KB |
Output is correct |