Submission #1053496

# Submission time Handle Problem Language Result Execution time Memory
1053496 2024-08-11T12:36:51 Z anton Lottery (CEOI18_lot) C++17
45 / 100
44 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<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]);
    }


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

    for(int i = N-1; i>=0; i--){
        int cur_a = a[i];
        for(auto e: next_oc[cur_a]){
            sums[e-i].add_inc(max(0, i-L+1),i);
        }
        next_oc[cur_a].push_back(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<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 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 23 ms 16440 KB Output is correct
14 Correct 27 ms 16484 KB Output is correct
15 Correct 19 ms 16476 KB Output is correct
16 Correct 44 ms 16548 KB Output is correct
17 Correct 36 ms 16528 KB Output is correct
18 Correct 41 ms 16472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 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 Correct 0 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 23 ms 16440 KB Output is correct
14 Correct 27 ms 16484 KB Output is correct
15 Correct 19 ms 16476 KB Output is correct
16 Correct 44 ms 16548 KB Output is correct
17 Correct 36 ms 16528 KB Output is correct
18 Correct 41 ms 16472 KB Output is correct
19 Runtime error 28 ms 65536 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -