# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
789339 |
2023-07-21T09:24:58 Z |
이동현(#10044) |
Tourism (JOI23_tourism) |
C++17 |
|
196 ms |
46660 KB |
#include <bits/stdc++.h>
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> way(n);
for(int i = 1; i < n; ++i){
int x, y;
cin >> x >> y;
--x, --y;
way[x].push_back(y);
way[y].push_back(x);
}
vector<int> a(m);
for(int i = 0; i < m; ++i){
cin >> a[i];
--a[i];
}
vector<vector<int>> mx(m, vector<int>(20, -1));
vector<vector<int>> mn(m, vector<int>(20, (int)1e9));
for(int i = m - 1; i >= 0; --i){
mx[i][0] = mn[i][0] = a[i];
for(int j = 1; j < 20; ++j){
mx[i][j] = mx[i][j - 1];
mn[i][j] = mn[i][j - 1];
if(i + (1 << (j - 1)) < m){
mx[i][j] = max(mx[i][j], mx[i + (1 << (j - 1))][j - 1]);
mn[i][j] = min(mn[i][j], mn[i + (1 << (j - 1))][j - 1]);
}
}
}
while(q--){
int l, r;
cin >> l >> r;
--l, --r;
int up = -1, down = (int)1e9;
for(int i = 19; i >= 0; --i){
if(l + (1 << i) <= r + 1){
up = max(up, mx[l][i]);
down = min(down, mn[l][i]);
l += (1 << i);
}
}
cout << up - down + 1 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
110 ms |
39152 KB |
Output is correct |
5 |
Correct |
86 ms |
27716 KB |
Output is correct |
6 |
Correct |
87 ms |
38388 KB |
Output is correct |
7 |
Correct |
120 ms |
46228 KB |
Output is correct |
8 |
Correct |
126 ms |
46232 KB |
Output is correct |
9 |
Correct |
120 ms |
46308 KB |
Output is correct |
10 |
Correct |
136 ms |
46256 KB |
Output is correct |
11 |
Correct |
196 ms |
46228 KB |
Output is correct |
12 |
Correct |
88 ms |
46256 KB |
Output is correct |
13 |
Correct |
99 ms |
46600 KB |
Output is correct |
14 |
Correct |
96 ms |
46660 KB |
Output is correct |
15 |
Correct |
38 ms |
6300 KB |
Output is correct |
16 |
Correct |
159 ms |
46212 KB |
Output is correct |
17 |
Correct |
108 ms |
40692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |