답안 #408034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408034 2021-05-19T05:41:30 Z amunduzbaev 새 집 (APIO18_new_home) C++14
0 / 100
5000 ms 73620 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<=n;i++) tt.pb({a[i], -1, t[i], x[i]}), tt.pb({b[i], 1, t[i], x[i]});
	for(int i=1;i<=m;i++) tt.pb({y[i], 0, l[i], i}), rr[i] = -2;
	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);
			}
		} for(int l=i;l<j;l++){
			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;
					if(it != ss[t].end()) umin(trr, abs(*it - in));
					if(it != ss[t].begin()) --it, umin(trr, abs(*it - in));
					umax(rr[ri], trr);
				} 
			}
		} for(int l=i;l<j;l++){
			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++){
		assert(rr[i] > -2);
		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 12 ms 14400 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 13 ms 14412 KB Output is correct
4 Correct 13 ms 14452 KB Output is correct
5 Incorrect 12 ms 14500 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14400 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 13 ms 14412 KB Output is correct
4 Correct 13 ms 14452 KB Output is correct
5 Incorrect 12 ms 14500 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5072 ms 73528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5068 ms 73620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14400 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 13 ms 14412 KB Output is correct
4 Correct 13 ms 14452 KB Output is correct
5 Incorrect 12 ms 14500 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14400 KB Output is correct
2 Correct 11 ms 14416 KB Output is correct
3 Correct 13 ms 14412 KB Output is correct
4 Correct 13 ms 14452 KB Output is correct
5 Incorrect 12 ms 14500 KB Output isn't correct
6 Halted 0 ms 0 KB -