제출 #294497

#제출 시각아이디문제언어결과실행 시간메모리
294497FlashGamezzz사다리꼴 (balkan11_trapezoid)C++17
0 / 100
146 ms11608 KiB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

struct trap {
	long a, b, c, d, i;
	trap(long i1, long i2, long i3, long i4){
		a = i1; b = i2; c = i3; d = i4; i = 0;
	}
};
struct comp1 {
	bool operator()(trap t1, trap t2){
		return t1.a > t2.a;
	}
};
struct comp2 {
	bool operator()(trap t1, trap t2){
		return t1.b > t2.b;
	}
};

long n, dp[100000]; //dp[i] stores longest sequence ending in trapezoid i
priority_queue<trap, vector<trap>, comp1> pqa; // for sorting the values by a initially
priority_queue<trap, vector<trap>, comp2> pqb; // sorts trapezoids by b
map<long, long> mp; //map(i, j) j = longest sequence of trapezoids with lower right distance i

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for (long i = 0; i < n; i++){
		long i1, i2, i3, i4;
		cin >> i1 >> i2 >> i3 >> i4;
		pqa.push(trap(i1, i2, i3, i4));
	}
	mp.insert(make_pair(-1, 0));
	long a1 = 0;
	for (int i = 0; i < n; i++){
		trap curr = pqa.top(); pqa.pop();
		map<long, long>::iterator temp;
		while (pqb.size() > 0 && pqb.top().b < curr.a){ //while the b values in our priority queue are less than our current a
			temp = mp.lower_bound(pqb.top().d); temp--; //find lowest value in map that's smaller than our current
			mp.insert(make_pair(pqb.top().d, max(dp[pqb.top().i], temp->second))); //map values
			pqb.pop();
		}
		curr.i = i; //set i so that we can find the dp value associated with this trapezoid
		pqb.push(curr);
		temp = mp.lower_bound(curr.c); temp--; //find longest sequence of trapezoids with lower right distance i less than curr.c
		dp[i] = temp->second + 1;
		a1 = max(a1, dp[i]);

	}
	cout << a1 << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...