답안 #1091896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091896 2024-09-22T13:44:31 Z gyg Lottery (CEOI18_lot) C++17
100 / 100
2053 ms 8476 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define arr array
#define vct vector
#define pii pair<int, int>
#define mpii make_pair
const int MX_N = 1e4 + 5, MX_Q = 1e2 + 5;

int n, l;
arr<int, MX_N> vl;
int q;
arr<pii, MX_Q> qry; // {value, index}
arr<int, MX_Q> indx;

arr<arr<int, MX_N>, 2> sm;
arr<arr<int, MX_Q>, MX_N> ans;
void cmp() {
    for (int i = n; i >= 1; i--) {
        int prt = i % 2, opp_prt = (i + 1) % 2;
        
        for (int j = 1; j <= n; j++) sm[prt][j] = (vl[i] == vl[j]) + sm[opp_prt][j + 1];
        
        for (int j = 1; j <= n - l + 1; j++) {
            if (j == i) continue;
            int k = lower_bound(qry.begin() + 1, qry.begin() + q + 1, mpii(l - sm[prt][j], -1)) - qry.begin();
            ans[i][k]++;
        }
        for (int j = 1; j <= q; j++) ans[i][j] = ans[i][j] + ans[i][j - 1];
        
        for (int j = 1; j <= n; j++) {
            int nw_i = i + l - 1, nw_j = j + l - 1;
            if (max(nw_i, nw_j) > n) continue;
            sm[prt][j] -= (vl[nw_i] == vl[nw_j]);
        }
    }
}

signed main() {
    // freopen("lttry.in", "r", stdin);
    cin >> n >> l;
    for (int i = 1; i <= n; i++) cin >> vl[i];
    cin >> q;
    for (int i = 1; i <= q; i++) { cin >> qry[i].first; qry[i].second = i; };
    sort(qry.begin() + 1, qry.begin() + q + 1);
    for (int i = 1; i <= q; i++) indx[qry[i].second] = i;

    cmp();

    for (int i = 1; i <= q; i++) {
        for (int j = 1; j <= n - l + 1; j++) cout << ans[j][indx[i]] << " ";
        cout << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 29 ms 1112 KB Output is correct
14 Correct 15 ms 1368 KB Output is correct
15 Correct 14 ms 1368 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 19 ms 1236 KB Output is correct
18 Correct 19 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 4596 KB Output is correct
2 Correct 260 ms 4692 KB Output is correct
3 Correct 244 ms 4640 KB Output is correct
4 Correct 236 ms 4700 KB Output is correct
5 Correct 147 ms 4688 KB Output is correct
6 Correct 227 ms 4692 KB Output is correct
7 Correct 151 ms 4668 KB Output is correct
8 Correct 191 ms 4692 KB Output is correct
9 Correct 237 ms 4688 KB Output is correct
10 Correct 245 ms 4688 KB Output is correct
11 Correct 17 ms 1624 KB Output is correct
12 Correct 155 ms 4284 KB Output is correct
13 Correct 162 ms 4692 KB Output is correct
14 Correct 160 ms 4640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 4596 KB Output is correct
2 Correct 260 ms 4692 KB Output is correct
3 Correct 244 ms 4640 KB Output is correct
4 Correct 236 ms 4700 KB Output is correct
5 Correct 147 ms 4688 KB Output is correct
6 Correct 227 ms 4692 KB Output is correct
7 Correct 151 ms 4668 KB Output is correct
8 Correct 191 ms 4692 KB Output is correct
9 Correct 237 ms 4688 KB Output is correct
10 Correct 245 ms 4688 KB Output is correct
11 Correct 17 ms 1624 KB Output is correct
12 Correct 155 ms 4284 KB Output is correct
13 Correct 162 ms 4692 KB Output is correct
14 Correct 160 ms 4640 KB Output is correct
15 Correct 565 ms 4692 KB Output is correct
16 Correct 217 ms 4688 KB Output is correct
17 Correct 253 ms 4628 KB Output is correct
18 Correct 255 ms 4524 KB Output is correct
19 Correct 220 ms 4520 KB Output is correct
20 Correct 248 ms 4608 KB Output is correct
21 Correct 234 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 29 ms 1112 KB Output is correct
14 Correct 15 ms 1368 KB Output is correct
15 Correct 14 ms 1368 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 19 ms 1236 KB Output is correct
18 Correct 19 ms 1364 KB Output is correct
19 Correct 366 ms 4596 KB Output is correct
20 Correct 260 ms 4692 KB Output is correct
21 Correct 244 ms 4640 KB Output is correct
22 Correct 236 ms 4700 KB Output is correct
23 Correct 147 ms 4688 KB Output is correct
24 Correct 227 ms 4692 KB Output is correct
25 Correct 151 ms 4668 KB Output is correct
26 Correct 191 ms 4692 KB Output is correct
27 Correct 237 ms 4688 KB Output is correct
28 Correct 245 ms 4688 KB Output is correct
29 Correct 17 ms 1624 KB Output is correct
30 Correct 155 ms 4284 KB Output is correct
31 Correct 162 ms 4692 KB Output is correct
32 Correct 160 ms 4640 KB Output is correct
33 Correct 565 ms 4692 KB Output is correct
34 Correct 217 ms 4688 KB Output is correct
35 Correct 253 ms 4628 KB Output is correct
36 Correct 255 ms 4524 KB Output is correct
37 Correct 220 ms 4520 KB Output is correct
38 Correct 248 ms 4608 KB Output is correct
39 Correct 234 ms 4688 KB Output is correct
40 Correct 1311 ms 5356 KB Output is correct
41 Correct 112 ms 4760 KB Output is correct
42 Correct 468 ms 5460 KB Output is correct
43 Correct 451 ms 5200 KB Output is correct
44 Correct 445 ms 5200 KB Output is correct
45 Correct 2053 ms 8340 KB Output is correct
46 Correct 125 ms 4948 KB Output is correct
47 Correct 732 ms 8476 KB Output is correct
48 Correct 609 ms 7092 KB Output is correct
49 Correct 665 ms 7508 KB Output is correct