Submission #571565

#TimeUsernameProblemLanguageResultExecution timeMemory
571565Cross_RatioNew Home (APIO18_new_home)C++14
22 / 100
3462 ms197812 KiB
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> P; typedef tuple<int,int,int> T; int X[300005]; int type[300005]; int A[300005]; int B[300005]; int L[300005]; int Y[300005]; int ans[300005]; int state_a[300005]; int state_b[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]; for(i=0;i<N;i++) type[i]--; for(i=0;i<Q;i++) cin >> L[i] >> Y[i]; if(N<=60000&&Q<=60000&&K<=400) { vector<map<int,int>> S; S.resize(K); map<int,vector<P>> In; map<int,vector<P>> Out; for(i=0;i<N;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 : In[idx[i]]) { S[k.first][k.second]++; //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->first - pos); if(it != S[j].begin()) { it--; dis = min(dis, pos - it->first); } ma = max(ma, dis); } ans[k.second] = (ma > 1e9 ? -1 : ma); } for(P k : Out[idx[i]]) { S[k.first][k.second]--; if(S[k.first][k.second]==0) { S[k.first].erase(k.second); } } } for(i=0;i<Q;i++) cout << ans[i] << '\n'; return 0; } vector<vector<int>> V; V.resize(K); for(i=0;i<N;i++) V[type[i]].push_back(X[i]); for(i=0;i<K;i++) sort(V[i].begin(),V[i].end()); bool emp = false; for(i=0;i<K;i++) { if(V[i].size()==0) emp = true; } if(emp) { for(i=0;i<Q;i++) cout << "-1\n"; return 0; } map<int,int> Minus, Plus; for(i=0;i<K;i++) { state_a[i] = -1; state_b[i] = V[i][0]; Minus[state_b[i]]++; } map<int,vector<T>> Query; vector<int> idx; for(i=0;i<K;i++) { for(j=0;j<V[i].size();j++) { Query[V[i][j]].push_back(T(i, 1, -V[i][j])); idx.push_back(V[i][j]); } for(j=0;j+1<V[i].size();j++) { int mid = (V[i][j] + V[i][j+1] + 1) / 2; if(mid == V[i][j+1]) continue; Query[mid].push_back(T(i, -1, V[i][j+1])); idx.push_back(mid); } } map<int,vector<int>> Qu; for(i=0;i<Q;i++) { Qu[L[i]].push_back(i); idx.push_back(L[i]); } sort(idx.begin(),idx.end()); idx.erase(unique(idx.begin(),idx.end()),idx.end()); for(i=0;i<idx.size();i++) { for(T k : Query[idx[i]]) { int id = get<0>(k); int a = get<1>(k); int b = get<2>(k); if(state_a[id]==1) { Plus[state_b[id]]--; if(Plus[state_b[id]]==0) Plus.erase(state_b[id]); } else { Minus[state_b[id]]--; if(Minus[state_b[id]]==0) Minus.erase(state_b[id]); } state_a[id] = a; state_b[id] = b; if(state_a[id]==1) { Plus[b]++; } else { Minus[b]++; } } for(int m : Qu[idx[i]]) { int m1 = -1e18; int m2 = -1e18; if(!Plus.empty()) m1 = Plus.rbegin()->first; if(!Minus.empty()) m2 = Minus.rbegin()->first; ans[m] = max(idx[i] + m1, -idx[i] + m2); } } for(i=0;i<Q;i++) cout << ans[i] << '\n'; }

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:47: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]
   47 |     for(i=0;i<idx.size();i++) {
      |             ~^~~~~~~~~~~
new_home.cpp:98:18: 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]
   98 |         for(j=0;j<V[i].size();j++) {
      |                 ~^~~~~~~~~~~~
new_home.cpp:102:20: 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]
  102 |         for(j=0;j+1<V[i].size();j++) {
      |                 ~~~^~~~~~~~~~~~
new_home.cpp:116: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]
  116 |     for(i=0;i<idx.size();i++) {
      |             ~^~~~~~~~~~~
#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...