답안 #571523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571523 2022-06-02T10:31:08 Z Cross_Ratio 새 집 (APIO18_new_home) C++14
0 / 100
5000 ms 114328 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<map<int,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][k.second]--;
            if(S[k.first][k.second]==0) {
                S[k.first].erase(k.second);
            }
        }
        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(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++) {
      |             ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5061 ms 87300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5076 ms 114328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -