Submission #974455

# Submission time Handle Problem Language Result Execution time Memory
974455 2024-05-03T11:02:35 Z efedmrlr New Home (APIO18_new_home) C++17
0 / 100
5000 ms 34076 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 = 1e5 + 5;
const int INF = 1e9 + 500;
const int K = 405;
int n, k, q;
vector<array<int, 2> > qu;
vector<multiset<int> > st(K);
vector<vector<int> > ev(N);
vector<array<int, 3> > eve; // occ, x, 0 or 1
vector<int> pt(N, 0);
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;
            eve.pb({ev[i][j + 1] + ev[i][j] / 2, 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:49:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int j = 0; j < ev[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~
new_home.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             if(j == ev[i].size() - 1) continue;
      |                ~~^~~~~~~~~~~~~~~~~~~
new_home.cpp:65: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]
   65 |         while(ind < eve.size() && eve[ind][0] <= c[0]) {
      |               ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 373 ms 33912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 343 ms 34076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5054 ms 3164 KB Time limit exceeded
2 Halted 0 ms 0 KB -