Submission #1053487

# Submission time Handle Problem Language Result Execution time Memory
1053487 2024-08-11T12:28:43 Z anton Lottery (CEOI18_lot) C++17
0 / 100
29 ms 65536 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;
}

struct Summer{
    vector<vector<int>> ev;

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


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

    vector<int> calc(){
        vector<int> res;
        int cur_s = 0;
        for(int i = 0; i<ev.size()-1; i++){
            for(auto e: ev[i]){
                cur_s += e;
            }
            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]);
    }


    vector<int> next_oc(N, N);
    vector<Summer> sums(N+1, N+1);

    for(int i = N-1; i>=0; i--){
        int cur_a = a[i];
        sums[next_oc[cur_a]-i].add_inc(max(0, i-L+1),i);
        next_oc[cur_a] = i;
    }


    int Q;
    cin>>Q;

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

    vector<vector<int>> score(M, vector<int>(Q, 0));
    for(int len = 1; len<N; len++){
        vector<int> dists = sums[len].calc();
        sums[len].ev.clear();
        for(int i = 0; i+len<M; i++){
            for(int q=  0; q<Q; q++){
                if(dists[i]>=L-lims[q]){
                    score[i][q]++;
                    score[i+len][q]++;
                }
            }
        }
    }


    

    
    for(int q = 0; q<Q; q++){
        for(int i = 0; i<M; i++){
           cout<<score[i][q]<<" ";
        }
        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 member function 'std::vector<int> Summer::calc()':
lot.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i = 0; i<ev.size()-1; i++){
      |                        ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -