Submission #387630

#TimeUsernameProblemLanguageResultExecution timeMemory
387630talant117408New Home (APIO18_new_home)C++17
5 / 100
5089 ms33188 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; for (int j = 1; j <= k; j++) pos[j].clear(); for (int j = 0; j < n; j++) { if (v[j].first.first <= year && year <= v[j].first.second) { pos[v[j].second.second].insert(v[j].second.first); } } 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)); } cout << (mx >= 1e9 ? -1 : mx) << endl; queries.pb(mp(mp(year, x), i)); } sort(all(queries)); sort(all(v)); 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...