답안 #543776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543776 2022-03-31T11:17:55 Z amunduzbaev 새 집 (APIO18_new_home) C++17
0 / 100
1911 ms 1048576 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define pq priority_queue

const int N = 3e5 + 5;
const int M = N * 30;
const int MX = 1e8 + 5;

struct node{
	pq<int> in[2], del[2];
	int f[2];
	
	node (){
		f[0] = f[1] = 0;
	}
};

node def;

struct ST{
	vector<node> tree;
	int last;
	ST(){
		tree.push_back(def);
		last = 0;
	}
	
	void make_l(int x){
		//~ tree.push_back(def);
		if(tree[x].f[0]) return;
		tree.push_back(def);
		tree[x].f[0] = ++last; // tree[x].f[1] = ++last;
		//~ assert(last < M);
	}
	void make_r(int x){
		//~ tree.push_back(def);
		if(tree[x].f[1]) return;
		tree.push_back(def);
		tree[x].f[1] = ++last; // tree[x].f[1] = ++last;
		//~ assert(last < M);
	}
	
	void add(int l, int r, int s, int t, int lx = 0, int rx = MX, int x = 0){
		if(lx > r || rx < l) return;
		if(lx >= l && rx <= r){
			if(t == 1){
				tree[x].in[0].push(s + (lx - l));
			} else {
				tree[x].in[1].push(s - (lx - l));
			} return;
		} int m = (lx + rx) >> 1;
		//~ make(x);
		if(lx <= r && m >= l){
			make_l(x);
			add(l, r, s, t, lx, m, tree[x].f[0]);
		} if(m + 1 <= r && rx >= l){
			make_r(x);
			add(l, r, s, t, m+1, rx, tree[x].f[1]);
		}
		//~ add(l, r, s, t, lx, m, tree[x].f[0]), add(l, r, s, t, m+1, rx, tree[x].f[1]);
	}
	
	void bal(pq<int>& a, pq<int>& b){
		while(!a.empty() && !b.empty() && a.top() == b.top()){
			a.pop();
			b.pop();
		}
	}
	
	void del(int l, int r, int s, int t, int lx = 0, int rx = MX, int x = 0){
		if(lx > r || rx < l) return;
		if(lx >= l && rx <= r){
			if(t == 1){
				tree[x].del[0].push(s + (lx - l));
			} else {
				tree[x].del[1].push(s - (lx - l));
			} return;
		} int m = (lx + rx) >> 1;
		if(lx <= r && m >= l){
			make_l(x);
			del(l, r, s, t, lx, m, tree[x].f[0]);
		} if(m + 1 <= r && rx >= l){
			make_r(x);
			del(l, r, s, t, m+1, rx, tree[x].f[1]);
		}
	}
	
	int get(int i, int lx = 0, int rx = MX, int x = 0){
		int res = 0;
		bal(tree[x].in[0], tree[x].del[0]);
		bal(tree[x].in[1], tree[x].del[1]);
		if(!tree[x].in[0].empty()) res = max(res, tree[x].in[0].top() + (i - lx));
		if(!tree[x].in[1].empty()) res = max(res, tree[x].in[1].top() - (i - lx));
		if(lx == rx) return res;
		int m = (lx + rx) >> 1;
		if(i <= m) return max((tree[x].f[0] ? get(i, lx, m, tree[x].f[0]) : 0), res);
		else return max((tree[x].f[1] ? get(i, m+1, rx, tree[x].f[1]) : 0), res);
	}
}tree;

int x[N], t[N], a[N], b[N]; //, l[N], y[N];
vector<int> stor[N];

/*

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

*/

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, k, q; cin>>n>>k>>q;
	for(int i=0;i<n;i++){
		cin>>x[i]>>t[i]>>a[i]>>b[i];
		stor[--t[i]].push_back(i);
	}
	
	bool is = 1;
	for(int i=0;i<k;i++){
		if(stor[i].empty()) { is = 0; break; }
		sort(stor[i].begin(), stor[i].end(), [&](int i, int j){
			return (x[i] < x[j]);
		});
		for(int j=1;j<(int)stor[i].size();j++){
			int l = x[stor[i][j-1]], r = x[stor[i][j]];
			if(l == r) continue;
			int m = (l + r) >> 1;
			tree.add(l, m, 0, 1);
			tree.add(m + 1, r, r - m - 1, -1);
		}
		
		tree.add(0, x[stor[i][0]], x[stor[i][0]], -1);
		tree.add(x[stor[i].back()], MX, 0, 1);
	}
	
	while(q--){
		int l, y;
		cin>>l>>y;
		if(is){
			cout<<tree.get(l)<<"\n";
		} else {
			cout<<-1<<"\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7336 KB Output is correct
2 Incorrect 5 ms 7440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7336 KB Output is correct
2 Incorrect 5 ms 7440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1911 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1747 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7336 KB Output is correct
2 Incorrect 5 ms 7440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7336 KB Output is correct
2 Incorrect 5 ms 7440 KB Output isn't correct
3 Halted 0 ms 0 KB -