Submission #387632

#TimeUsernameProblemLanguageResultExecution timeMemory
387632talant117408New Home (APIO18_new_home)C++17
0 / 100
5069 ms55900 KiB
/* Code written by Talant I.D. */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; int mod; ll mode(ll a) { a %= mod; if (a < 0) a += mod; return a; } ll subt(ll a, ll b) { return mode(mode(a)-mode(b)); } ll add(ll a, ll b) { return mode(mode(a)+mode(b)); } ll mult(ll a, ll b) { return mode(mode(a)*mode(b)); } ll binpow(ll a, ll b, ll m) { ll res = 1; while (b) { if (b&1) res = ((res*a)%m+m)%m; a = ((a*a)%m+m)%m; b >>= 1; } return res; } void usaco(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const int N = 3e5+7; int ans[N]; multiset <int> pos[N]; int main() { do_not_disturb //~ usaco("marathon"); int n, q, k; cin >> n >> k >> q; vector <pair <pii, pii>> v; for (int i = 0; i < n; i++) { int x, type, a, b; cin >> x >> type >> a >> b; v.pb(mp(mp(a, b), mp(x, type))); } vector <pair <pii, int>> queries; for (int i = 0; i < q; i++) { int x, year; cin >> x >> year; queries.pb(mp(mp(year, x), i)); } auto cmp = [&](pair <pii, pii> a, pair <pii, pii> b) { if (a.first.first == b.first.first) return a.first.second < b.first.second; return a.first.first < b.first.first; }; sort(all(queries)); sort(all(v), cmp); int ind = 0; set <pair <int, pii>> endtimes; for (int i = 0; i < q; i++) { int year = queries[i].first.first, x = queries[i].first.second, i1 = queries[i].second; while (sz(endtimes) && (*endtimes.begin()).first < year) { auto it = *endtimes.begin(); pos[it.second.second].erase(pos[it.second.second].find(it.second.first)); endtimes.erase(endtimes.begin()); } while (ind < n && v[ind].first.first <= year) { if (v[ind].first.second >= year) { pos[v[ind].second.second].insert(v[ind].second.first); endtimes.insert(mp(v[ind].first.second, mp(v[ind].second.first, v[ind].second.second))); } ind++; } int mx = 0; for (int j = 1; j <= k; j++) { auto it = lb(all(pos[j]), x); int it1 = 1e9+5e8, it2 = 1e9+5e8; if (it != pos[j].end()) { it1 = abs(*it-x); } if (it != pos[j].begin()) { it--; it2 = abs(*it-x); } mx = max(mx, min(it1, it2)); } ans[i1] = (mx >= 1e9 ? -1 : mx); } for (int i = 0; i < q; i++) cout << ans[i] << endl; return 0; } /* 4 2 4 3 1 1 10 9 2 2 4 7 2 5 7 4 1 8 10 5 3 5 6 5 9 1 10 2 1 3 1 1 1 4 1 1 2 6 1 3 1 5 1 7 */

Compilation message (stderr)

new_home.cpp: In function 'void usaco(std::string)':
new_home.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   58 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...