답안 #750707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750707 2023-05-30T07:52:05 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
782 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define sync 	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii	pair<int, int>
#define pb	push_back
#define mp	make_pair
#define fi	first
#define se	second

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e5 + 10, inf = 1e9 + 7, mood = 1e9+7, mood2 = 19025953, base = 31, maxsq = 400, maxlg = 20; 
vector<pii> query[maxn];
int s[maxn], f[maxn], ans[maxn];
vector<int> order;
int n, q;

bool cmp(int a, int b)
{
	return mp(s[a], f[a]) < mp(s[b], f[b]);
}

bool cmp2(int a, int b)
{
	return mp(f[a], s[a]) < mp(f[b], s[b]);
}

int main()
{
	sync;
	cin >> n >> q;
	for(int i = 1; i <= n; i++)
		cin >> s[i] >> f[i], order.pb(i);

	for(int i = 0; i < q; i++)
	{
		int ss, ff;
		cin >> ss >> ff;
		query[ss].pb(mp(ff, i));
		ans[i] = 0 - maxn;
	}

	sort(order.begin(), order.end(), cmp);

	for(int i = 0; i < n; i++)
	{
		int v = order[i];
		vector<int> vc, vc2;
		int mx = v;
		int j = i+1;
		int u;
		if(j < n-1)
		{
			u = order[j];
			while(s[u] <= f[v] && j < n)
			{
				vc.pb(f[u]);
				vc2.pb(u);
				if(f[u] >= f[mx])
					mx = u;
				j++;
				u = order[j];
			}
		}

		if(!vc.empty())
		{
			sort(vc.begin(), vc.end());
			sort(vc2.begin(), vc2.end(), cmp2);
		}

		for(auto x : query[v])
		{
		//	cout << v << endl;
			u = x.fi;
			int ind = x.se;
			if(u == v)
			{
				ans[ind] += maxn;
				continue;
			}	
			if(mx == v)
				continue;
			if(f[mx] <= f[u])
			{
				ans[ind]++;
				query[mx].pb(x);
				continue;
			}	

			int tmp = lower_bound(vc.begin(), vc.end(), f[u]) - vc.begin();
			while(vc[tmp] > f[u] && tmp > 0)
				tmp--;

			if(vc[tmp] > f[u])
				continue;

			ans[ind]++;
			query[vc2[tmp]].pb(x);
		}

		query[v].clear();

	}

	for(int i = 0; i < q; i++)
	{
		if(ans[i] < 0)
			cout << "impossible" << '\n';
		else
			cout << ans[i] << '\n';
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Runtime error 782 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 3 ms 3716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 3 ms 3716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 3 ms 3716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 776 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Runtime error 782 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -