Submission #741156

#TimeUsernameProblemLanguageResultExecution timeMemory
741156speedyArdaNew Home (APIO18_new_home)C++14
12 / 100
5097 ms66204 KiB
#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e5+5;
int type[MAXN];
vector< multiset<int> > locations(MAXN);
vector< pair< pair<int, int>, pair<int, int> > > stores;
vector< pair<int, pair<int, int> > > queries;
vector<int> ans(MAXN);
int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    for(int i = 0; i < n; i++)
    {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        stores.push_back({{a, 0}, {x, t}});
        stores.push_back({{b + 1, 1}, {x, t}});
    }
    for(int i = 0; i < q; i++)
    {
        int l, y;
        cin >> l >> y;
        queries.push_back({y, {i, l}});
    }
    sort(queries.begin(), queries.end());
    sort(stores.begin(), stores.end());

    int curr = 0, use = 0;
    multiset<int> elems;
    for(int i = 0; i < q; i++)
    {
        while(curr < stores.size() && stores[curr].first.first <= queries[i].first)
        {
            if(stores[curr].first.second == 0)
            {
                type[stores[curr].second.second]++;
                if(type[stores[curr].second.second] == 1)
                    use++;
                locations[stores[curr].second.second].insert(stores[curr].second.first);
                //elems.insert(stores[curr].second.first);
            } else 
            {
                type[stores[curr].second.second]--;
                if(type[stores[curr].second.second] == 0)
                    use--;
                locations[stores[curr].second.second].erase(locations[stores[curr].second.second].find(stores[curr].second.first));  
                //elems.erase(elems.find(stores[curr].second.first));
            }
            curr++;
        }

        if(use != k)
        {
            ans[queries[i].second.first] = -1;
        } else 
        {
            int res = 0;
            for(int idx = 1; idx <= k; idx++)
            {
                if(locations[idx].size() == 0)
                    break;
                auto it = locations[idx].upper_bound(queries[i].second.second);
                int temp = 1e9; 
                if(it != locations[idx].end())
                {
                    temp = min(temp, abs(queries[i].second.second - (*it)));
                    //cout << queries[i].second.second << "\n";
                }
                if(it != locations[idx].begin()) {
                    it--;
                    
                    temp = min(temp, abs(queries[i].second.second - (*it)));
                }
                res = max(res, temp);
            }
            ans[queries[i].second.first] = res;
        }
    }


    for(int i = 0; i < q; i++)
        cout << ans[i] << "\n";
    
}

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while(curr < stores.size() && stores[curr].first.first <= queries[i].first)
      |               ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...