답안 #974561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974561 2024-05-03T13:08:21 Z efedmrlr 새 집 (APIO18_new_home) C++17
0 / 100
5000 ms 55220 KB
#include <bits/stdc++.h>

#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 3e5 + 5;
const int INF = 1e9 + 500;
int n, k, q;
vector<array<int, 2> > qu;
vector<vector<int> > ev(N);
vector<array<int, 3> > eve; // occ, x, 0 or 1
void solve() {
    cin >> n >> k >> q;
    REP(i, n) {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        ev[t].pb(x);
    }
    qu.resize(q);
    REP(i, q) {
        int tmp;
        cin >> qu[i][0] >> tmp;
        qu[i][1] = i;
    }
    sort(all(qu));
    bool emp = 0;
    for(int i = 1; i <= k; i++) {
        sort(all(ev[i]));
        if(ev[i].empty()) {
            emp = 1;
            break;
        }
        int tm = 1;
        for(int j = 0; j < ev[i].size(); j++) {
            eve.pb({tm, ev[i][j], 1});
            if(j == ev[i].size() - 1) continue;
            tm = (ev[i][j + 1] + ev[i][j] - 1) / 2 + 1;
            eve.pb({tm, ev[i][j], 0});
        }
    }
   
    if(emp) {
        REP(i, q) cout << "-1\n";
        return;
    }
    sort(all(eve));
    multiset<int> st;
    int ind = 0;
    vector<int> res(q, 0);
    for(auto c : qu) {
        while(ind < eve.size() && eve[ind][0] <= c[0]) {
            if(eve[ind][2]) {
                st.insert(eve[ind][1]);
            }
            else {
                st.erase(st.lower_bound(eve[ind][1]));
            }
            ind++;
        }
        int mx = 0;
        mx = max(mx, abs(c[0] - (*st.begin())));
        mx = max(mx, abs((*prev(st.end())) - c[0]));
        res[c[1]] = mx;
    }


    REP(i, q) {
        cout << res[i] << "\n";
    }
}


signed main() {
    fastio();
    solve();
}

Compilation message

new_home.cpp: In function 'void solve()':
new_home.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j = 0; j < ev[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~
new_home.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             if(j == ev[i].size() - 1) continue;
      |                ~~^~~~~~~~~~~~~~~~~~~
new_home.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         while(ind < eve.size() && eve[ind][0] <= c[0]) {
      |               ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5043 ms 7260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5043 ms 7260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 26128 KB Output is correct
2 Correct 257 ms 25376 KB Output is correct
3 Correct 287 ms 55220 KB Output is correct
4 Correct 360 ms 41136 KB Output is correct
5 Execution timed out 5089 ms 37496 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 338 ms 25348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5043 ms 7260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5043 ms 7260 KB Time limit exceeded
2 Halted 0 ms 0 KB -