답안 #407549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407549 2021-05-19T02:34:06 Z amunduzbaev 새 집 (APIO18_new_home) C++14
0 / 100
5000 ms 86660 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return 1; } return 0; }

const int N = 3e5+5;
const int mod = 1e9+7;
const long long inf = 1e18+7;

int n, m, k, a[N];
int x[N], t[N], b[N], l[N], y[N], rr[N];
set<int> ss[N];

void solve(){
	cin>>n>>k>>m;
	for(int i=1;i<=n;i++) cin>>x[i]>>t[i]>>a[i]>>b[i];
	for(int i=1;i<=m;i++) cin>>l[i]>>y[i];
	vector<array<int, 4>> tt;
	for(int i=1;i<=m;i++) tt.pb({a[i], -1, t[i], x[i]}), tt.pb({b[i], 1, t[i], x[i]});
	for(int i=1;i<=n;i++) tt.pb({y[i], 0, l[i], i});
	memset(rr, -1, sizeof rr);
	sort(all(tt));
	
	for(int i=0;i<sz(tt);){
		int j = i;
		while(j < sz(tt) && tt[j][0] == tt[i][0]) j++;
		for(int l=i;l<j;l++){
			if(tt[l][1] == -1){
				int in = tt[l][3], t = tt[l][2];
				ss[t].insert(in);
			} if(tt[l][1] == 0) {
				int in = tt[l][2], ri = tt[l][3];
				for(int t=1;t<=k;t++){
					if(ss[t].empty()) { rr[ri] = -1; break; }
					auto it = ss[t].lb(in);
					int trr = inf;
					//cout<<t<<" "<<in<<" ";
					if(it != ss[t].end()) umin(trr, abs(*it - in));
					it = ss[t].ub(in);
					if(it != ss[t].begin()) --it, umin(trr, abs(*it - in));
					//cout<<"\n";
					umax(rr[ri], trr);
				} 
			} if(tt[l][1] == 1) {
				int in = tt[l][3], t = tt[l][2];
				ss[t].erase(in);
			}
		} i = j;
	}
	for(int i=1;i<=m;i++) cout<<rr[i]<<"\n";
}

/*

1 1 1
1000000000 1 1 1
1 1

2 1 3
1 1 1 4
1 1 2 6
1 3
1 5
1 7

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

*/

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16716 KB Output is correct
2 Correct 11 ms 16804 KB Output is correct
3 Correct 11 ms 16716 KB Output is correct
4 Correct 11 ms 16764 KB Output is correct
5 Incorrect 11 ms 16844 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16716 KB Output is correct
2 Correct 11 ms 16804 KB Output is correct
3 Correct 11 ms 16716 KB Output is correct
4 Correct 11 ms 16764 KB Output is correct
5 Incorrect 11 ms 16844 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5044 ms 86660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5062 ms 86136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16716 KB Output is correct
2 Correct 11 ms 16804 KB Output is correct
3 Correct 11 ms 16716 KB Output is correct
4 Correct 11 ms 16764 KB Output is correct
5 Incorrect 11 ms 16844 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16716 KB Output is correct
2 Correct 11 ms 16804 KB Output is correct
3 Correct 11 ms 16716 KB Output is correct
4 Correct 11 ms 16764 KB Output is correct
5 Incorrect 11 ms 16844 KB Output isn't correct
6 Halted 0 ms 0 KB -