Submission #979677

# Submission time Handle Problem Language Result Execution time Memory
979677 2024-05-11T09:45:22 Z temporary1 Passport (JOI23_passport) C++17
100 / 100
624 ms 78876 KB
#include <bits/stdc++.h>
using namespace std;
 
#define f first
#define s second
 
vector<pair<int,int>> graph[800001];
int dist[3][800001];
int node[200001];

int max1 = 0;

priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;

int build(int n, int a, int b) {
	if (a == b) {
		max1 = max(max1,n);
		return node[a] = n;
	}
	graph[build(2*n,a,(a+b)/2)].push_back({n,0});
	graph[build(2*n+1,(a+b)/2+1,b)].push_back({n,0});
	return n;
}
 
void upd(int n, int a, int b, int x, int y, int k) {
	if (a > b || b < x || y < a)return;
	if (x <= a && b <= y) {
		graph[n].push_back({k,1});
		return;
	}
	upd(2*n,a,(a+b)/2,x,y,k);
	upd(2*n+1,(a+b)/2+1,b,x,y,k);
	return;
}

int main() {
	int n;
	scanf("%d",&n);
	build(1,1,n);
	for (int i = 1; i <= n; ++i) {
		int l, r;
		scanf("%d%d",&l,&r);
		upd(1,1,n,l,r,node[i]);
	}
	for (int i = 0; i < 3; ++i) {
		fill(dist[i]+1,dist[i]+max1+1,1e9);
		if (i == 0) {
			dist[0][node[1]] = 0;
			pq.push({0,node[1]});
		} else if (i == 1) {
			dist[1][node[n]] = 0;
			pq.push({0,node[n]});
		} else if (i == 2) {
			dist[0][node[1]] = 1;
			dist[1][node[n]] = 1;
			for (int j = 1; j <= n; ++j) {
				dist[2][node[j]] = dist[0][node[j]]+dist[1][node[j]]-1;
				pq.push({dist[2][node[j]],node[j]});
			}
		}
		while (pq.size()) {
			int d, x;
			tie(d,x) = pq.top();
			pq.pop();
			if (dist[i][x] < d)continue;
			for (auto it : graph[x]) {
				if (dist[i][it.f] > dist[i][x]+it.s) {
					dist[i][it.f] = dist[i][x]+it.s;
					pq.push({dist[i][it.f],it.f});
				}
			}
		}
	}
	int q;
	scanf("%d",&q);
	for (int qi = 0; qi < q; ++qi) {
		int x;
		scanf("%d",&x);
		if (dist[2][node[x]] > n)printf("-1\n");
		else printf("%d\n",dist[2][node[x]]);
	}
	return 0;
}

Compilation message

passport.cpp: In function 'int main()':
passport.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
passport.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d",&l,&r);
      |   ~~~~~^~~~~~~~~~~~~~
passport.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
passport.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 557 ms 72344 KB Output is correct
5 Correct 272 ms 52284 KB Output is correct
6 Correct 158 ms 47144 KB Output is correct
7 Correct 173 ms 44776 KB Output is correct
8 Correct 150 ms 52920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27176 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 26972 KB Output is correct
12 Correct 6 ms 26972 KB Output is correct
13 Correct 6 ms 27228 KB Output is correct
14 Correct 6 ms 27228 KB Output is correct
15 Correct 6 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27176 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 26972 KB Output is correct
12 Correct 6 ms 26972 KB Output is correct
13 Correct 6 ms 27228 KB Output is correct
14 Correct 6 ms 27228 KB Output is correct
15 Correct 6 ms 26972 KB Output is correct
16 Correct 8 ms 27484 KB Output is correct
17 Correct 8 ms 27484 KB Output is correct
18 Correct 8 ms 27480 KB Output is correct
19 Correct 8 ms 27668 KB Output is correct
20 Correct 7 ms 27228 KB Output is correct
21 Correct 7 ms 27396 KB Output is correct
22 Correct 6 ms 27344 KB Output is correct
23 Correct 8 ms 27484 KB Output is correct
24 Correct 7 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 6 ms 27176 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 5 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 6 ms 26972 KB Output is correct
10 Correct 5 ms 27168 KB Output is correct
11 Correct 7 ms 26972 KB Output is correct
12 Correct 6 ms 26972 KB Output is correct
13 Correct 6 ms 27228 KB Output is correct
14 Correct 6 ms 27228 KB Output is correct
15 Correct 6 ms 26972 KB Output is correct
16 Correct 8 ms 27484 KB Output is correct
17 Correct 8 ms 27484 KB Output is correct
18 Correct 8 ms 27480 KB Output is correct
19 Correct 8 ms 27668 KB Output is correct
20 Correct 7 ms 27228 KB Output is correct
21 Correct 7 ms 27396 KB Output is correct
22 Correct 6 ms 27344 KB Output is correct
23 Correct 8 ms 27484 KB Output is correct
24 Correct 7 ms 27484 KB Output is correct
25 Correct 5 ms 26972 KB Output is correct
26 Correct 5 ms 26972 KB Output is correct
27 Correct 9 ms 27480 KB Output is correct
28 Correct 9 ms 27484 KB Output is correct
29 Correct 8 ms 27436 KB Output is correct
30 Correct 7 ms 27484 KB Output is correct
31 Correct 8 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 5 ms 26972 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 557 ms 72344 KB Output is correct
5 Correct 272 ms 52284 KB Output is correct
6 Correct 158 ms 47144 KB Output is correct
7 Correct 173 ms 44776 KB Output is correct
8 Correct 150 ms 52920 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 5 ms 26972 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 6 ms 27176 KB Output is correct
13 Correct 5 ms 26972 KB Output is correct
14 Correct 5 ms 26972 KB Output is correct
15 Correct 5 ms 26972 KB Output is correct
16 Correct 5 ms 26972 KB Output is correct
17 Correct 6 ms 26972 KB Output is correct
18 Correct 5 ms 27168 KB Output is correct
19 Correct 7 ms 26972 KB Output is correct
20 Correct 6 ms 26972 KB Output is correct
21 Correct 6 ms 27228 KB Output is correct
22 Correct 6 ms 27228 KB Output is correct
23 Correct 6 ms 26972 KB Output is correct
24 Correct 8 ms 27484 KB Output is correct
25 Correct 8 ms 27484 KB Output is correct
26 Correct 8 ms 27480 KB Output is correct
27 Correct 8 ms 27668 KB Output is correct
28 Correct 7 ms 27228 KB Output is correct
29 Correct 7 ms 27396 KB Output is correct
30 Correct 6 ms 27344 KB Output is correct
31 Correct 8 ms 27484 KB Output is correct
32 Correct 7 ms 27484 KB Output is correct
33 Correct 5 ms 26972 KB Output is correct
34 Correct 5 ms 26972 KB Output is correct
35 Correct 9 ms 27480 KB Output is correct
36 Correct 9 ms 27484 KB Output is correct
37 Correct 8 ms 27436 KB Output is correct
38 Correct 7 ms 27484 KB Output is correct
39 Correct 8 ms 27484 KB Output is correct
40 Correct 624 ms 74720 KB Output is correct
41 Correct 289 ms 53184 KB Output is correct
42 Correct 394 ms 78876 KB Output is correct
43 Correct 404 ms 78660 KB Output is correct
44 Correct 187 ms 48064 KB Output is correct
45 Correct 217 ms 54840 KB Output is correct
46 Correct 112 ms 38148 KB Output is correct
47 Correct 344 ms 55576 KB Output is correct
48 Correct 283 ms 63092 KB Output is correct