Submission #979152

# Submission time Handle Problem Language Result Execution time Memory
979152 2024-05-10T10:03:58 Z canadavid1 Radio Towers (IOI22_towers) C++17
14 / 100
606 ms 3376 KB
#include "towers.h"

#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
struct SegmentTree
{
private:
    std::vector<int> data;
    struct SegTreeReference
    {
    private:
        const int pos;
        SegmentTree& t;
    public:
        SegTreeReference(int pos,SegmentTree& t) : pos(pos), t(t) {}
        int operator=(int val)
        {
            t.assign(pos,val);
            return val;
        }
        operator int() const {return t.data[t.data.size()/2+pos];}
    };
public:
    SegmentTree() : data(0) {}
    SegmentTree(int num) : data(num*2,0) {}
    SegmentTree(const std::vector<int>& vec) : data(vec.size()*2)
    {
        
        for(int i = 0; i < vec.size(); i++) data[vec.size()+i] = vec[i];
        for(int i = vec.size()-1; i > 0; i--)
            data[i] = data[2*i]+data[2*i+1];
    }
    void assign(int pos, int val)
    {
        data[pos] = val;
        pos >>= 1;
        for(;pos>0;pos>>=1)
            data[pos] = data[2*pos]+data[2*pos+1];
        
    }
    SegTreeReference operator[](int pos)
    {
        return SegTreeReference(pos,*this);
    }
    int query(int l, int r)
    {
        l += data.size()/2;
        r += data.size()/2;
        int o = 0;
        while(l < r)
        {
            if(l&1) o = o+data[l++];
            if(r&1) o = o+data[--r];
            l>>=1;
            r>>=1;
        }
        return o;
    }
    
};

std::vector<int> H;
std::vector<int> nH;
std::vector<int> m;
SegmentTree st;
void init(int N, std::vector<int> _H) {
    H = std::move(_H);
    for(auto i : H)
    {
        if(nH.size() && nH.back()==i)
        {
            m.push_back(nH.size()-1);
        }
        else
        {
            m.push_back(nH.size());
            nH.push_back(i);
        }
    }
    std::vector<int> minima(H.size());
    for(int i = 1; i < nH.size()-1;i++)
        minima[i] = nH[i-1] > nH[i] && nH[i] < nH[i+1];
        // annoying if range is 2I1(1112I1)
    // WLOG take the leftmost in an equal range
    st = decltype(st)(minima);
}

int max_towers(int L, int R, int D) {
    L = m[L];
    R = m[R];
    if(L==R) return 1;
    auto a = st.query(L+1,R);
    if(L+1 < nH.size() && nH[L]<nH[L+1]) a++;
    if(R > 0 && nH[R]<nH[R-1]) a++;
    return a;
}


/*
    WLOG all leased towers are local minima or endpoints
    DONE s1: "concave": lease extrema if possible
    DONE s2: N <= 1000, Q=1: choose towers from smallest to largest
    DONE s23: Q = 1
    s4: D = 1
        take any which is a local minima
    s46: D fixed -> scheduling problem (each tower excludes a certain area)
        constrained: won't have ([)] - matched parens
            whichever is taller is the outer paren
        tree of ranges
    s5: L,R is entire range

    WLOG use smallest tower
    use next smallest that works
        need to quickly check if it works (logn time)
        or not (subtask 2)
    repeat
*/

Compilation message

towers.cpp: In constructor 'SegmentTree::SegmentTree(const std::vector<int>&)':
towers.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i = 0; i < vec.size(); i++) data[vec.size()+i] = vec[i];
      |                        ~~^~~~~~~~~~~~
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i = 1; i < nH.size()-1;i++)
      |                    ~~^~~~~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:95:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     if(L+1 < nH.size() && nH[L]<nH[L+1]) a++;
      |        ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 2260 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 461 ms 3236 KB Output is correct
2 Correct 535 ms 3240 KB Output is correct
3 Correct 585 ms 3240 KB Output is correct
4 Correct 538 ms 3240 KB Output is correct
5 Correct 567 ms 3276 KB Output is correct
6 Correct 595 ms 3240 KB Output is correct
7 Correct 563 ms 3276 KB Output is correct
8 Correct 606 ms 3240 KB Output is correct
9 Correct 578 ms 3236 KB Output is correct
10 Correct 565 ms 3276 KB Output is correct
11 Correct 557 ms 3276 KB Output is correct
12 Correct 595 ms 3240 KB Output is correct
13 Correct 560 ms 3276 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 10 ms 3236 KB Output is correct
18 Correct 10 ms 3376 KB Output is correct
19 Correct 10 ms 3240 KB Output is correct
20 Correct 9 ms 3240 KB Output is correct
21 Correct 13 ms 3236 KB Output is correct
22 Correct 11 ms 3240 KB Output is correct
23 Correct 10 ms 3240 KB Output is correct
24 Correct 10 ms 3232 KB Output is correct
25 Correct 13 ms 3236 KB Output is correct
26 Correct 10 ms 3244 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 500 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 155 ms 1460 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '16'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 262 ms 2260 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -