제출 #865219

#제출 시각아이디문제언어결과실행 시간메모리
865219vjudge1Birthday gift (IZhO18_treearray)C++17
0 / 100
1 ms6744 KiB
//Bismillahir-Rahmanir-Rahim #include <bits/stdc++.h> using namespace std; #define flash ios_base::sync_with_stdio(0),cin.tie(0) #define pb push_back #define ll long long #define ld long double #define dbg(x) cerr << #x << " = " << x << "\n"; #define ff first #define ss second /* #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma comment (linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ const long long INF = 1e9 + 7; const long long MOD = 1e9 + 7; const int maxn = 2e5 + 10; const int lg = 22; int n, m, q, a[maxn], pr[maxn], cl[maxn]; vector <int> g[maxn]; void dfs(int v, int p) { pr[v] = p; for (auto to: g[v]) { if (to != p) { dfs(to, v); } } } void fnd(int v, int p) { if (cl[v] == 0) { cl[v] = 2; } for (auto to: g[v]) { if (to != p) { fnd(to, v); } } } void press_F_() { cin >> n >> m >> q; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } for (int i = 1; i <= m; i++) { cin >> a[i]; } dfs(1, 0); while(q--) { int tp; cin >> tp; if (tp == 1) { int pos, v; cin >> pos >> v; a[pos] = v; } else { int l, r, u; cin >> l >> r >> u; for (int i = 1; i <= m; i++) { cl[i] = 0; } cl[u] = 1; for (auto to: g[u]) { if (to != pr[u]) { cl[to] = 1; fnd(to, u); } } bool ok = 0, ok2 = 0; int x = l, y = l, nx = INF, ny = -INF; for (int i = l; i <= r; i++) { if (cl[a[i]] == 2) { y = i; ok2 = 1; } if (cl[a[i]] == 1) { y = i; ok = 1; } if (cl[a[i]] == 0) { ok = 0; ok2 = 0; x = i + 1; y = x; } if (ny - nx + 1 < y - x + 1 && ok == 1 && ok2 == 1) { nx = x; ny = y; } } if (nx == INF && ny == -INF) { nx = -1; ny = -1; } cout << nx << " " << ny << '\n'; } } } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */ int main() { flash; // srand(time(0)); int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { // cout << "Case" << " " << i << ':' << "\n"; press_F_(); } //Respa gold 2023-2024 InshAllah return 0; } /* Maybe not today and tomorrow, but InshAllah one day I will reach expert */ // g++ -std=c++17 main.cpp // ./a.out
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...