# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
828477 |
2023-08-17T10:16:27 Z |
joelgun14 |
Lottery (CEOI18_lot) |
C++17 |
|
514 ms |
12100 KB |
// header file
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// pragma
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// macros
#define endl "\n"
#define ll long long
#define mp make_pair
#define ins insert
#define lb lower_bound
#define pb push_back
#define ub upper_bound
#define lll __int128
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int n, l;
cin >> n >> l;
int a[n + 1];
for(int i = 1; i <= n; ++i)
cin >> a[i];
int que;
cin >> que;
pair<int, int> q[que];
for(int i = 0; i < que; ++i)
cin >> q[i].fi, q[i].se = i;
sort(q, q + que);
int allow[l + 1];
memset(allow, -1, sizeof(allow));
for(int i = 0; i < que; ++i) {
if(allow[q[i].fi] == -1)
allow[q[i].fi] = i;
}
for(int i = l - 1; i >= 0; --i) {
if(allow[i] == -1)
allow[i] = allow[i + 1];
}
// given compare substring shift by x
// size l - 1
int cnt[que][n + 1];
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= n; ++i) {
// try for every length i
// geser
int idx1 = 1, idx2 = 1 + i, diff = 0;
if(idx2 + l - 1 > n)
break;
for(int j = 0; j < l; ++j) {
if(a[idx1 + j] != a[idx2 + j])
++diff;
}
// simpan batas di query i
// find lowest yg bs ditambahkan
++cnt[allow[diff]][idx1];
++cnt[allow[diff]][idx2];
//cout << idx1 << " " << idx2 << " " << diff << endl;
for(;idx2 + l <= n;) {
// coba geser
if(a[idx1 + l] != a[idx2 + l])
++diff;
if(a[idx1] != a[idx2])
--diff;
++idx1, ++idx2;
++cnt[allow[diff]][idx1];
++cnt[allow[diff]][idx2];
//cout << idx1 << " " << idx2 << " " << diff << endl;
}
}
for(int i = 1; i < que; ++i) {
for(int j = 1; j <= n; ++j)
cnt[i][j] += cnt[i - 1][j];
}
int ans[que][n + 1];
for(int i = 0; i < que; ++i) {
for(int j = 1; j <= n; ++j) {
ans[q[i].se][j] = cnt[i][j];
}
}
for(int i = 0; i < que; ++i) {
for(int j = 1; j <= n - l + 1; ++j)
cout << ans[i][j] << " ";
cout << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
6 ms |
368 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
436 KB |
Output is correct |
2 |
Correct |
429 ms |
436 KB |
Output is correct |
3 |
Correct |
113 ms |
448 KB |
Output is correct |
4 |
Correct |
84 ms |
520 KB |
Output is correct |
5 |
Correct |
23 ms |
468 KB |
Output is correct |
6 |
Correct |
73 ms |
516 KB |
Output is correct |
7 |
Correct |
22 ms |
468 KB |
Output is correct |
8 |
Correct |
40 ms |
492 KB |
Output is correct |
9 |
Correct |
81 ms |
512 KB |
Output is correct |
10 |
Correct |
83 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
328 KB |
Output is correct |
12 |
Correct |
46 ms |
496 KB |
Output is correct |
13 |
Correct |
33 ms |
532 KB |
Output is correct |
14 |
Correct |
33 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
436 KB |
Output is correct |
2 |
Correct |
429 ms |
436 KB |
Output is correct |
3 |
Correct |
113 ms |
448 KB |
Output is correct |
4 |
Correct |
84 ms |
520 KB |
Output is correct |
5 |
Correct |
23 ms |
468 KB |
Output is correct |
6 |
Correct |
73 ms |
516 KB |
Output is correct |
7 |
Correct |
22 ms |
468 KB |
Output is correct |
8 |
Correct |
40 ms |
492 KB |
Output is correct |
9 |
Correct |
81 ms |
512 KB |
Output is correct |
10 |
Correct |
83 ms |
508 KB |
Output is correct |
11 |
Correct |
5 ms |
328 KB |
Output is correct |
12 |
Correct |
46 ms |
496 KB |
Output is correct |
13 |
Correct |
33 ms |
532 KB |
Output is correct |
14 |
Correct |
33 ms |
528 KB |
Output is correct |
15 |
Correct |
136 ms |
440 KB |
Output is correct |
16 |
Correct |
68 ms |
520 KB |
Output is correct |
17 |
Correct |
92 ms |
512 KB |
Output is correct |
18 |
Correct |
87 ms |
508 KB |
Output is correct |
19 |
Correct |
82 ms |
520 KB |
Output is correct |
20 |
Correct |
81 ms |
516 KB |
Output is correct |
21 |
Correct |
80 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
6 ms |
368 KB |
Output is correct |
14 |
Correct |
4 ms |
724 KB |
Output is correct |
15 |
Correct |
3 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
4 ms |
716 KB |
Output is correct |
19 |
Correct |
310 ms |
436 KB |
Output is correct |
20 |
Correct |
429 ms |
436 KB |
Output is correct |
21 |
Correct |
113 ms |
448 KB |
Output is correct |
22 |
Correct |
84 ms |
520 KB |
Output is correct |
23 |
Correct |
23 ms |
468 KB |
Output is correct |
24 |
Correct |
73 ms |
516 KB |
Output is correct |
25 |
Correct |
22 ms |
468 KB |
Output is correct |
26 |
Correct |
40 ms |
492 KB |
Output is correct |
27 |
Correct |
81 ms |
512 KB |
Output is correct |
28 |
Correct |
83 ms |
508 KB |
Output is correct |
29 |
Correct |
5 ms |
328 KB |
Output is correct |
30 |
Correct |
46 ms |
496 KB |
Output is correct |
31 |
Correct |
33 ms |
532 KB |
Output is correct |
32 |
Correct |
33 ms |
528 KB |
Output is correct |
33 |
Correct |
136 ms |
440 KB |
Output is correct |
34 |
Correct |
68 ms |
520 KB |
Output is correct |
35 |
Correct |
92 ms |
512 KB |
Output is correct |
36 |
Correct |
87 ms |
508 KB |
Output is correct |
37 |
Correct |
82 ms |
520 KB |
Output is correct |
38 |
Correct |
81 ms |
516 KB |
Output is correct |
39 |
Correct |
80 ms |
516 KB |
Output is correct |
40 |
Correct |
462 ms |
2736 KB |
Output is correct |
41 |
Correct |
5 ms |
2080 KB |
Output is correct |
42 |
Correct |
106 ms |
2656 KB |
Output is correct |
43 |
Correct |
112 ms |
2420 KB |
Output is correct |
44 |
Correct |
84 ms |
2412 KB |
Output is correct |
45 |
Correct |
514 ms |
11908 KB |
Output is correct |
46 |
Correct |
13 ms |
8532 KB |
Output is correct |
47 |
Correct |
143 ms |
12100 KB |
Output is correct |
48 |
Correct |
135 ms |
10380 KB |
Output is correct |
49 |
Correct |
125 ms |
10924 KB |
Output is correct |