이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
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);
}
typedef tuple <int, int, int, int> Store;
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 <Store> v;
for (int i = 0; i < n; i++) {
int x, type, a, b;
cin >> x >> type >> a >> b;
v.pb(Store(x, type, a, b));
}
int ind = 0;
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));
}
sort(all(queries));
auto cmp = [&](Store A, Store B) {
int x1, type1, a1, b1;
tie(x1, type1, a1, b1) = A;
int x2, type2, a2, b2;
tie(x2, type2, a2, b2) = A;
if (a1 == a2) return b1 < b2;
return a1 < a2;
};
sort(all(v), cmp);
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 && get<2>(v[ind]) <= year) {
if (get<3>(v[ind]) >= year) {
pos[get<1>(v[ind])].insert(get<0>(v[ind]));
endtimes.insert(mp(get<3>(v[ind]), mp(get<0>(v[ind]), get<1>(v[ind]))));
}
ind++;
}
int flag = 1, mx = 0;
for (int j = 1; j <= k; j++) {
if (sz(pos[j]) == 0) flag = 0;
else {
auto it = lb(all(pos[j]), x);
if (it != pos[j].end() && it != pos[j].begin()) {
auto it2 = it;
it2--;
mx = max(mx, min(abs((*it)-x), abs((*it2)-x)));
}
else if (it != pos[j].end()) {
mx = max(mx, abs(*it-x));
}
else if (it != pos[j].begin()) {
it--;
mx = max(mx, abs(*it-x));
}
}
}
if (flag) {
ans[i1] = mx;
}
else {
ans[i1] = -1;
}
}
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
*/
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |