답안 #437747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
437747 2021-06-27T02:26:13 Z definitelynotmee Lottery (CEOI18_lot) C++
100 / 100
2466 ms 8160 KB
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const int MOD = 1e9 + 7;
const int MAXN = 1e6+1;



int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, l;
    cin >> n >> l;
    vector<int> v(n,0);
    for(int i = 0; i < n; i++)
        cin >> v[i];

    int q;
    cin >> q;
    
    vector<pii> queries(q);
    vector<int> order(q);
    for(int i = 0; i < q; i++){
        cin >> queries[i].ff;
        queries[i].ss = i;
    }

    sort(queries.begin(),queries.end(),[&](pii& a, pii& b){
        if(a.ff == b.ff)
            return a.ss < b.ss;
        return a.ff < b.ff;
    });
    for(int i = 0; i < q; i++){
        order[queries[i].ss] = i;
    }
    vector<vector<int>> resp(q,vector<int>(n,0));

    function<void(int,int,int)> update = [&](int a, int b, int val){
        int ini = 0, fim = q;
        while(ini!=fim){
            int m = (ini+fim)>>1;
            if(queries[m].ff >= val)
                fim = m;
            else ini = m+1;
        }
        if(ini!=q){
            resp[ini][a]++;
            resp[ini][b]++;
        }
    };

    vector<int> diff(n-l+1,0);//vamos calcular a diferença do atual para todos os outros intervalos
    //base: caso do intervalo [0,l-1]
    
    for(int i = 0; i < l; i++){ // para cada membro do intervalo
        for(int j = i+1; j-i < n-l+1 ; j++){ // para cada um dos outros indices
            diff[j-i]+= v[i]!=v[j]; //adicionamos ao intervalo que corresponde àquela diferença
        }
    }

    for(int i = 1; i <= n-l; i++){ // atualizando resposta para o caso base
        update(0,i,diff[i]);
    }

    for(int i = 1; i < n-l; i++){ // recorrência
        for(int j = n-l; j > i; j--){ // para cada intervalo após o atual
            diff[j] = diff[j-1] - (v[j-1]!=v[i-1]) + (v[i+l-1]!=v[j+l-1]); 
            // [ (  ] )  [ (  ] )  quando passamos para o próximo intervalo podemos ver que toda a parte do meio já era comparada anteriormente, então só temos que mudar as bordas
            update(i,j,diff[j]);
        }
    }
    
    for(int i = 1; i < q; i++){
        for(int j = 0; j < n-l+1; j++){
            resp[i][j]+=resp[i-1][j];
        }
    }

    
    
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n-l+1; j++){
            cout << resp[order[i]][j] << ' ';
        }
        cout << '\n';
    }
    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 44 ms 364 KB Output is correct
14 Correct 27 ms 480 KB Output is correct
15 Correct 17 ms 416 KB Output is correct
16 Correct 36 ms 480 KB Output is correct
17 Correct 23 ms 484 KB Output is correct
18 Correct 23 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 460 KB Output is correct
2 Correct 430 ms 460 KB Output is correct
3 Correct 423 ms 460 KB Output is correct
4 Correct 427 ms 452 KB Output is correct
5 Correct 149 ms 332 KB Output is correct
6 Correct 359 ms 420 KB Output is correct
7 Correct 263 ms 332 KB Output is correct
8 Correct 414 ms 424 KB Output is correct
9 Correct 428 ms 412 KB Output is correct
10 Correct 437 ms 452 KB Output is correct
11 Correct 20 ms 332 KB Output is correct
12 Correct 241 ms 392 KB Output is correct
13 Correct 204 ms 420 KB Output is correct
14 Correct 172 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 460 KB Output is correct
2 Correct 430 ms 460 KB Output is correct
3 Correct 423 ms 460 KB Output is correct
4 Correct 427 ms 452 KB Output is correct
5 Correct 149 ms 332 KB Output is correct
6 Correct 359 ms 420 KB Output is correct
7 Correct 263 ms 332 KB Output is correct
8 Correct 414 ms 424 KB Output is correct
9 Correct 428 ms 412 KB Output is correct
10 Correct 437 ms 452 KB Output is correct
11 Correct 20 ms 332 KB Output is correct
12 Correct 241 ms 392 KB Output is correct
13 Correct 204 ms 420 KB Output is correct
14 Correct 172 ms 404 KB Output is correct
15 Correct 857 ms 460 KB Output is correct
16 Correct 386 ms 408 KB Output is correct
17 Correct 434 ms 408 KB Output is correct
18 Correct 423 ms 408 KB Output is correct
19 Correct 408 ms 408 KB Output is correct
20 Correct 423 ms 408 KB Output is correct
21 Correct 412 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 44 ms 364 KB Output is correct
14 Correct 27 ms 480 KB Output is correct
15 Correct 17 ms 416 KB Output is correct
16 Correct 36 ms 480 KB Output is correct
17 Correct 23 ms 484 KB Output is correct
18 Correct 23 ms 476 KB Output is correct
19 Correct 538 ms 460 KB Output is correct
20 Correct 430 ms 460 KB Output is correct
21 Correct 423 ms 460 KB Output is correct
22 Correct 427 ms 452 KB Output is correct
23 Correct 149 ms 332 KB Output is correct
24 Correct 359 ms 420 KB Output is correct
25 Correct 263 ms 332 KB Output is correct
26 Correct 414 ms 424 KB Output is correct
27 Correct 428 ms 412 KB Output is correct
28 Correct 437 ms 452 KB Output is correct
29 Correct 20 ms 332 KB Output is correct
30 Correct 241 ms 392 KB Output is correct
31 Correct 204 ms 420 KB Output is correct
32 Correct 172 ms 404 KB Output is correct
33 Correct 857 ms 460 KB Output is correct
34 Correct 386 ms 408 KB Output is correct
35 Correct 434 ms 408 KB Output is correct
36 Correct 423 ms 408 KB Output is correct
37 Correct 408 ms 408 KB Output is correct
38 Correct 423 ms 408 KB Output is correct
39 Correct 412 ms 424 KB Output is correct
40 Correct 1474 ms 1924 KB Output is correct
41 Correct 22 ms 1220 KB Output is correct
42 Correct 781 ms 1920 KB Output is correct
43 Correct 650 ms 1540 KB Output is correct
44 Correct 643 ms 1544 KB Output is correct
45 Correct 2466 ms 8144 KB Output is correct
46 Correct 33 ms 4548 KB Output is correct
47 Correct 1399 ms 8160 KB Output is correct
48 Correct 993 ms 6332 KB Output is correct
49 Correct 998 ms 6980 KB Output is correct