QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209011#4207. Uplifting Excursionfryan0 0ms0kbC++202.3kb2023-10-10 02:27:262023-10-10 02:27:26

Judging History

你现在查看的是最新测评结果

  • [2023-10-10 02:27:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-10-10 02:27:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define P pair
#define pi P<int,int>
#define ff first
#define ss second
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define V vector
#define vi V<int>
#define v2i V<vi>
#define v3i V<v2i>
#define vpi V<pi>
#define vsi V<si>
#define vb V<bool>
#define pb push_back
#define si set<int>
#define ins insert
#define mii map<int,int>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
const int INF=1e18;

int n,q;
vpi evs;
v2i jmp;

template<class T>
struct RMQ {
	vector<vector<T>> jmp;
	RMQ(const vector<T>& V) : jmp(1, V) {
		for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k) {
			jmp.emplace_back(sz(V) - pw * 2 + 1);
			rep(j,0,sz(jmp[k]))
				jmp[k][j] = comb(jmp[k - 1][j], jmp[k - 1][j + pw]);
		}
	}
	T query(int a, int b) {
		assert(a < b); // or return inf if a == b
		int dep = 31 - __builtin_clz(b - a);
		return comb(jmp[dep][a], jmp[dep][b - (1 << dep)]);
	}
	T comb(T a, T b) {
		if (a==INF) return b;
		if (b==INF) return a;
		if (evs[a].ff<evs[b].ff) return a;
		return b;
	}
};

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n>>q; evs=vpi(n); si rev; jmp=v2i(n,vi(30,0));
	for (int i=0; i<n; i++) {
		cin>>evs[i].ff>>evs[i].ss;
		rev.ins(evs[i].ff); rev.ins(evs[i].ss);
	}
	mii cmp; int c=0;
	for (auto i:rev) {cmp[i]=c; c++;}
	for (int i=0; i<n; i++) {
		evs[i].ff=cmp[evs[i].ff];
		evs[i].ss=cmp[evs[i].ss];
	}
	vi ses(c,INF);
	for (int i=0; i<n; i++) {
		int pos=evs[i].ss;
		if (ses[pos]==INF || evs[ses[pos]].ff>evs[i].ff) {
			ses[pos]=i;
		}
	}
	RMQ<int> rmqse(ses);
	for (int i=0; i<n; i++) {
		int x=rmqse.query(evs[i].ff,evs[i].ss+1);
		jmp[i][0]=x;
	}
	while (q--) {
		int s,e; cin>>s>>e; s--; e--;
		if (s==e) {
			cout<<"0\n"; continue;
		}
		int cp=e;
		int num=0; bool ok=0;
		while (true) {
			if (evs[jmp[cp][0]].ff>evs[s].ff) {
				if (cp==jmp[cp][0]) {break;}
				cp=jmp[cp][0];
				num++;
			} else {
				break;
			}
		}
		for (int i=0; i<5; i++) {
			if (evs[cp].ff<=evs[s].ss && evs[s].ss<=evs[cp].ss) {
				num++; ok=1; break;
			} else {
				num++; cp=jmp[cp][0];
			}
		}
		if (ok) {
			cout<<num<<"\n";
		} else {
			cout<<"impossible\n";
		}
	}

	return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1 5
0 0 6

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #19:

score: 0
Runtime Error

input:

30 38887954194235
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 444113827766 26 511237030935 22 696666627923 315938808146 20 952560827478 924020644151 850666790939 23 587888300072 23 797812801251 911390834853 677171102320 4 2 22 950650764450 278888113729 23 15 15 13 9 637120041802 20 1...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 0
Skipped

Dependency #7:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

0%