Submission #571518

# Submission time Handle Problem Language Result Execution time Memory
571518 2022-06-02T10:27:23 Z Cross_Ratio New Home (APIO18_new_home) C++14
0 / 100
5000 ms 109984 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
int X[300005];
int type[300005];
int A[300005];
int B[300005];
int L[300005];
int Y[300005];
int ans[300005];
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, K, Q;
    cin >> N >> K >> Q;
    int i, j;
    for(i=0;i<N;i++) cin >> X[i] >> type[i] >> A[i] >> B[i];
    vector<multiset<int>> S;
    S.resize(K);
    for(i=0;i<Q;i++) cin >> L[i] >> Y[i];
    map<int,vector<P>> In;
    map<int,vector<P>> Out;
    for(i=0;i<N;i++) {
        type[i]--;
        In[A[i]].push_back(P(type[i],X[i]));
        Out[B[i]].push_back(P(type[i],X[i]));
    }
    map<int,vector<P>> Query;
    for(i=0;i<Q;i++) {
        Query[Y[i]].push_back(P(L[i],i));
    }
    vector<int> idx;
    for(i=0;i<Q;i++) idx.push_back(Y[i]);
    for(i=0;i<N;i++) {
        idx.push_back(A[i]);
        idx.push_back(B[i]);
    }
    sort(idx.begin(),idx.end());
    idx.erase(unique(idx.begin(),idx.end()),idx.end());
    for(i=0;i<idx.size();i++) {
        for(P k : Out[idx[i]]) {
            S[k.first].erase(S[k.first].find(k.second));
        }
        for(P k : In[idx[i]]) {
            S[k.first].insert(k.second);
        }
        for(P k : Query[idx[i]]) {
            int ma = 0;
            int pos = k.first;
            for(j=0;j<K;j++) {
                int dis = 1e18;
                auto it = S[j].lower_bound(pos);
                if(it != S[j].end()) dis = min(dis, *it - pos);
                if(it != S[j].begin()) {
                    it--;
                    dis = min(dis, pos - *it);
                }
                ma = max(ma, dis);
            }
            ans[k.second] = (ma > 1e9 ? -1 : ma);
        }
    }
    for(i=0;i<Q;i++) cout << ans[i] << '\n';
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:42:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(i=0;i<idx.size();i++) {
      |             ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5082 ms 82796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5059 ms 109984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -