# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
922547 |
2024-02-05T16:29:37 Z |
KiaRez |
Passport (JOI23_passport) |
C++17 |
|
2000 ms |
847464 KB |
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
ll n, q, dist[3][5*N], vis[3][5*N], x[N], id[2*N], L[N], R[N], cnt;
vector<pll> adj[5*N];
void build(int ind=1) {
id[ind] = ++cnt;
if(ind>=(1<<lg)) {
int f = ind - (1<<lg) + 1;
if(f<=n) adj[f].pb({id[ind], 0});
return;
}
build(2*ind); build(2*ind+1);
adj[id[2*ind+1]].pb({id[ind], 0});
adj[id[2*ind]].pb({id[ind], 0});
}
void query(int v, int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
if(l>=rc || lc>=r) return;
if(lc>=l && rc<=r) {
adj[id[ind]].pb({v, 1});
return;
}
int mid = (lc+rc)/2;
query(v, l, r, 2*ind, lc, mid);
query(v, l, r, 2*ind+1, mid, rc);
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n;
cnt=n;
for(int i=1; i<=n; i++) cin>>L[i]>>R[i];
cin>>q;
for(int i=1; i<=q; i++) cin>>x[i];
build(1);
for(int i=1; i<=n; i++) {
query(i, L[i], i);
query(i, i+1, R[i]+1);
}
priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;
pq.push({0, 0, 1});
pq.push({0, 1, n});
while(size(pq) > 0) {
vector<int> v = pq.top();
pq.pop();
if(vis[v[1]][v[2]] == 1) continue;
vis[v[1]][v[2]] = 1, dist[v[1]][v[2]] = v[0];
if(vis[1][v[2]]==1 && vis[0][v[2]]==1) {
pq.push({dist[1][v[2]]+dist[0][v[2]]-(v[2]>1&&v[2]<n), 2, v[2]});
}
for(auto it : adj[v[2]]) {
pq.push({v[0]+it.S, v[1], it.F});
}
}
for(int i=1; i<=q; i++) {
if(vis[2][x[i]] == 1) cout<<dist[2][x[i]]<<endl;
else cout<<-1<<endl;
}
return 0;
}
Compilation message
passport.cpp: In function 'int main()':
passport.cpp:86:17: warning: narrowing conversion of 'n' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
86 | pq.push({0, 1, n});
| ^
passport.cpp:86:17: warning: narrowing conversion of 'n' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
passport.cpp:93:40: warning: narrowing conversion of '((dist[1][v.std::vector<int>::operator[](2)] + dist[0][v.std::vector<int>::operator[](2)]) - ((ll)((int)((v.std::vector<int>::operator[](2) > 1) && (((ll)v.std::vector<int>::operator[](2)) < n)))))' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
93 | pq.push({dist[1][v[2]]+dist[0][v[2]]-(v[2]>1&&v[2]<n), 2, v[2]});
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
passport.cpp:93:40: warning: narrowing conversion of '((dist[1][v.std::vector<int>::operator[](2)] + dist[0][v.std::vector<int>::operator[](2)]) - ((ll)((int)((v.std::vector<int>::operator[](2) > 1) && (((ll)v.std::vector<int>::operator[](2)) < n)))))' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
passport.cpp:96:17: warning: narrowing conversion of '(((long long int)v.std::vector<int>::operator[](0)) + it.std::pair<long long int, long long int>::second)' from 'long long int' to 'int' [-Wnarrowing]
96 | pq.push({v[0]+it.S, v[1], it.F});
passport.cpp:96:17: warning: narrowing conversion of '(((long long int)v.std::vector<int>::operator[](0)) + it.std::pair<long long int, long long int>::second)' from 'long long int' to 'int' [-Wnarrowing]
passport.cpp:17:48: warning: narrowing conversion of 'it.std::pair<long long int, long long int>::first' from 'long long int' to 'int' [-Wnarrowing]
17 | #define F first
| ^
passport.cpp:96:33: note: in expansion of macro 'F'
96 | pq.push({v[0]+it.S, v[1], it.F});
| ^
passport.cpp:17:48: warning: narrowing conversion of 'it.std::pair<long long int, long long int>::first' from 'long long int' to 'int' [-Wnarrowing]
17 | #define F first
| ^
passport.cpp:96:33: note: in expansion of macro 'F'
96 | pq.push({v[0]+it.S, v[1], it.F});
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
68188 KB |
Output is correct |
2 |
Correct |
35 ms |
68344 KB |
Output is correct |
3 |
Correct |
37 ms |
68268 KB |
Output is correct |
4 |
Execution timed out |
2083 ms |
847464 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
68324 KB |
Output is correct |
2 |
Correct |
37 ms |
68432 KB |
Output is correct |
3 |
Correct |
37 ms |
68180 KB |
Output is correct |
4 |
Correct |
39 ms |
68156 KB |
Output is correct |
5 |
Correct |
40 ms |
68184 KB |
Output is correct |
6 |
Correct |
38 ms |
68180 KB |
Output is correct |
7 |
Correct |
36 ms |
68196 KB |
Output is correct |
8 |
Correct |
43 ms |
68188 KB |
Output is correct |
9 |
Correct |
38 ms |
68180 KB |
Output is correct |
10 |
Correct |
40 ms |
68180 KB |
Output is correct |
11 |
Correct |
38 ms |
68440 KB |
Output is correct |
12 |
Correct |
51 ms |
68296 KB |
Output is correct |
13 |
Correct |
50 ms |
68436 KB |
Output is correct |
14 |
Correct |
49 ms |
68700 KB |
Output is correct |
15 |
Correct |
46 ms |
68432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
68324 KB |
Output is correct |
2 |
Correct |
37 ms |
68432 KB |
Output is correct |
3 |
Correct |
37 ms |
68180 KB |
Output is correct |
4 |
Correct |
39 ms |
68156 KB |
Output is correct |
5 |
Correct |
40 ms |
68184 KB |
Output is correct |
6 |
Correct |
38 ms |
68180 KB |
Output is correct |
7 |
Correct |
36 ms |
68196 KB |
Output is correct |
8 |
Correct |
43 ms |
68188 KB |
Output is correct |
9 |
Correct |
38 ms |
68180 KB |
Output is correct |
10 |
Correct |
40 ms |
68180 KB |
Output is correct |
11 |
Correct |
38 ms |
68440 KB |
Output is correct |
12 |
Correct |
51 ms |
68296 KB |
Output is correct |
13 |
Correct |
50 ms |
68436 KB |
Output is correct |
14 |
Correct |
49 ms |
68700 KB |
Output is correct |
15 |
Correct |
46 ms |
68432 KB |
Output is correct |
16 |
Correct |
73 ms |
71808 KB |
Output is correct |
17 |
Correct |
57 ms |
71360 KB |
Output is correct |
18 |
Correct |
77 ms |
71916 KB |
Output is correct |
19 |
Correct |
73 ms |
72076 KB |
Output is correct |
20 |
Correct |
51 ms |
71296 KB |
Output is correct |
21 |
Correct |
49 ms |
68948 KB |
Output is correct |
22 |
Correct |
59 ms |
71956 KB |
Output is correct |
23 |
Correct |
71 ms |
74000 KB |
Output is correct |
24 |
Correct |
56 ms |
70840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
68324 KB |
Output is correct |
2 |
Correct |
37 ms |
68432 KB |
Output is correct |
3 |
Correct |
37 ms |
68180 KB |
Output is correct |
4 |
Correct |
39 ms |
68156 KB |
Output is correct |
5 |
Correct |
40 ms |
68184 KB |
Output is correct |
6 |
Correct |
38 ms |
68180 KB |
Output is correct |
7 |
Correct |
36 ms |
68196 KB |
Output is correct |
8 |
Correct |
43 ms |
68188 KB |
Output is correct |
9 |
Correct |
38 ms |
68180 KB |
Output is correct |
10 |
Correct |
40 ms |
68180 KB |
Output is correct |
11 |
Correct |
38 ms |
68440 KB |
Output is correct |
12 |
Correct |
51 ms |
68296 KB |
Output is correct |
13 |
Correct |
50 ms |
68436 KB |
Output is correct |
14 |
Correct |
49 ms |
68700 KB |
Output is correct |
15 |
Correct |
46 ms |
68432 KB |
Output is correct |
16 |
Correct |
73 ms |
71808 KB |
Output is correct |
17 |
Correct |
57 ms |
71360 KB |
Output is correct |
18 |
Correct |
77 ms |
71916 KB |
Output is correct |
19 |
Correct |
73 ms |
72076 KB |
Output is correct |
20 |
Correct |
51 ms |
71296 KB |
Output is correct |
21 |
Correct |
49 ms |
68948 KB |
Output is correct |
22 |
Correct |
59 ms |
71956 KB |
Output is correct |
23 |
Correct |
71 ms |
74000 KB |
Output is correct |
24 |
Correct |
56 ms |
70840 KB |
Output is correct |
25 |
Correct |
35 ms |
68128 KB |
Output is correct |
26 |
Correct |
38 ms |
68176 KB |
Output is correct |
27 |
Correct |
70 ms |
71688 KB |
Output is correct |
28 |
Correct |
57 ms |
71504 KB |
Output is correct |
29 |
Correct |
50 ms |
71304 KB |
Output is correct |
30 |
Correct |
48 ms |
69144 KB |
Output is correct |
31 |
Correct |
72 ms |
70028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
68188 KB |
Output is correct |
2 |
Correct |
35 ms |
68344 KB |
Output is correct |
3 |
Correct |
37 ms |
68268 KB |
Output is correct |
4 |
Execution timed out |
2083 ms |
847464 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |