답안 #1053531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053531 2024-08-11T12:55:17 Z anton Lottery (CEOI18_lot) C++17
100 / 100
1651 ms 12924 KB
#include<bits/stdc++.h>

using namespace std;
#define pii pair<int, int>
int L, N;
int M;

int get_pos(vector<int>& v, int i){
    int res =0;
    for(int step =(1<<20); step>=1; step/=2){
        if(res + step < v.size() && v[res+step]<=i){
            res += step;
        }
    }
    return res;
}
int get_pos(vector<pii>& v, int i){
    int res =0;
    for(int step =(1<<20); step>=1; step/=2){
        if(res + step < v.size() && v[res+step].first<i){
            res += step;
        }
    }
    return res;
}

struct Summer{
    vector<int> ev;

    Summer(int n){
        ev.resize(n+1);
    }


    void add_inc(int l, int r){
        ev[l]++;
        ev[r+1]--;
    }

    vector<int> calc(){
        vector<int> res;
        int cur_s = 0;
        for(int i = 0; i<ev.size()-1; i++){
            
            cur_s += ev[i];
            
            res.push_back(cur_s);
        }
        return res;
    }
};

signed main(){
    cin>>N>>L;
    M = N-L+1;
    vector<int> a(N);
    vector<int> vals;

    for(int i= 0; i<N; i++){
        cin>>a[i];
        vals.push_back(a[i]);
    }

    sort(vals.begin(), vals.end());

    for(int i = 0; i<N; i++){
        a[i] = get_pos(vals, a[i]);
    }

    int Q;
    cin>>Q;

    vector<pii> lims(Q);
    for(int i = 0; i<Q; i++){
        cin>>lims[i].first;
        lims[i].second = i;
    }

    lims.push_back({-1, -1});
    sort(lims.begin(), lims.end());
    lims.push_back({1e9, -1});


    vector<vector<int>> score_d(M, vector<int>(Q+2, 0));

    for(int len = 1; len<N; len++){

        Summer sum(N+1);
        for(int i = N-1; i>=0; i--){
            int cur_a = a[i];
            if(i+len <N && a[i+len]==a[i]){
                sum.add_inc(max(0, i-L+1),i);
            }
        }

        vector<int> dists = sum.calc();
        sum.ev.clear();
        for(int i = 0; i+len<M; i++){
            int q_pos =get_pos(lims, L-dists[i]);
            score_d[i][q_pos]++;
            score_d[i+len][q_pos]++;
        }
    }


    vector<vector<int>> ans(M, vector<int>(Q));
    
    for(int i = 0; i<M; i++){
        int r= 0;
        for(int q = 0; q<lims.size(); q++){
            if(lims[q].second!=-1){
            ans[i][lims[q].second] = r;
           }
           r += score_d[i][q];
           
        }
    }

    for(int i = 0; i<Q; i++){
        for(int j = 0; j<M; j++){
            cout<<ans[j][i]<<" ";
        }
        cout<<endl;
    }


}

Compilation message

lot.cpp: In function 'int get_pos(std::vector<int>&, int)':
lot.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         if(res + step < v.size() && v[res+step]<=i){
      |            ~~~~~~~~~~~^~~~~~~~~~
lot.cpp: In function 'int get_pos(std::vector<std::pair<int, int> >&, int)':
lot.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         if(res + step < v.size() && v[res+step].first<i){
      |            ~~~~~~~~~~~^~~~~~~~~~
lot.cpp: In member function 'std::vector<int> Summer::calc()':
lot.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int i = 0; i<ev.size()-1; i++){
      |                        ~^~~~~~~~~~~~
lot.cpp: In function 'int main()':
lot.cpp:90:17: warning: unused variable 'cur_a' [-Wunused-variable]
   90 |             int cur_a = a[i];
      |                 ^~~~~
lot.cpp:110:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for(int q = 0; q<lims.size(); q++){
      |                        ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 1 ms 428 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 1 ms 428 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 37 ms 604 KB Output is correct
14 Correct 25 ms 856 KB Output is correct
15 Correct 24 ms 604 KB Output is correct
16 Correct 30 ms 944 KB Output is correct
17 Correct 27 ms 684 KB Output is correct
18 Correct 28 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1186 ms 1456 KB Output is correct
2 Correct 1185 ms 1616 KB Output is correct
3 Correct 1016 ms 1620 KB Output is correct
4 Correct 963 ms 1364 KB Output is correct
5 Correct 518 ms 924 KB Output is correct
6 Correct 927 ms 1420 KB Output is correct
7 Correct 524 ms 1052 KB Output is correct
8 Correct 740 ms 1308 KB Output is correct
9 Correct 974 ms 1436 KB Output is correct
10 Correct 993 ms 1448 KB Output is correct
11 Correct 51 ms 604 KB Output is correct
12 Correct 616 ms 1108 KB Output is correct
13 Correct 608 ms 976 KB Output is correct
14 Correct 569 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1186 ms 1456 KB Output is correct
2 Correct 1185 ms 1616 KB Output is correct
3 Correct 1016 ms 1620 KB Output is correct
4 Correct 963 ms 1364 KB Output is correct
5 Correct 518 ms 924 KB Output is correct
6 Correct 927 ms 1420 KB Output is correct
7 Correct 524 ms 1052 KB Output is correct
8 Correct 740 ms 1308 KB Output is correct
9 Correct 974 ms 1436 KB Output is correct
10 Correct 993 ms 1448 KB Output is correct
11 Correct 51 ms 604 KB Output is correct
12 Correct 616 ms 1108 KB Output is correct
13 Correct 608 ms 976 KB Output is correct
14 Correct 569 ms 1108 KB Output is correct
15 Correct 993 ms 1436 KB Output is correct
16 Correct 885 ms 1364 KB Output is correct
17 Correct 1050 ms 1456 KB Output is correct
18 Correct 985 ms 1616 KB Output is correct
19 Correct 1014 ms 1368 KB Output is correct
20 Correct 1051 ms 1616 KB Output is correct
21 Correct 1008 ms 1468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 1 ms 428 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 37 ms 604 KB Output is correct
14 Correct 25 ms 856 KB Output is correct
15 Correct 24 ms 604 KB Output is correct
16 Correct 30 ms 944 KB Output is correct
17 Correct 27 ms 684 KB Output is correct
18 Correct 28 ms 860 KB Output is correct
19 Correct 1186 ms 1456 KB Output is correct
20 Correct 1185 ms 1616 KB Output is correct
21 Correct 1016 ms 1620 KB Output is correct
22 Correct 963 ms 1364 KB Output is correct
23 Correct 518 ms 924 KB Output is correct
24 Correct 927 ms 1420 KB Output is correct
25 Correct 524 ms 1052 KB Output is correct
26 Correct 740 ms 1308 KB Output is correct
27 Correct 974 ms 1436 KB Output is correct
28 Correct 993 ms 1448 KB Output is correct
29 Correct 51 ms 604 KB Output is correct
30 Correct 616 ms 1108 KB Output is correct
31 Correct 608 ms 976 KB Output is correct
32 Correct 569 ms 1108 KB Output is correct
33 Correct 993 ms 1436 KB Output is correct
34 Correct 885 ms 1364 KB Output is correct
35 Correct 1050 ms 1456 KB Output is correct
36 Correct 985 ms 1616 KB Output is correct
37 Correct 1014 ms 1368 KB Output is correct
38 Correct 1051 ms 1616 KB Output is correct
39 Correct 1008 ms 1468 KB Output is correct
40 Correct 1310 ms 3468 KB Output is correct
41 Correct 433 ms 764 KB Output is correct
42 Correct 1184 ms 3424 KB Output is correct
43 Correct 1115 ms 3180 KB Output is correct
44 Correct 1086 ms 3196 KB Output is correct
45 Correct 1651 ms 12924 KB Output is correct
46 Correct 456 ms 1572 KB Output is correct
47 Correct 1187 ms 12896 KB Output is correct
48 Correct 1159 ms 12176 KB Output is correct
49 Correct 1132 ms 11396 KB Output is correct