답안 #865149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865149 2023-10-24T06:02:22 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
150 ms 262144 KB
//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 = 1e5 + 10;
const int lg = 22;

int n, m, q, a[maxn], pr[maxn];
vector <int> g[maxn];

void dfs(int v, int p) {
	pr[v] = p;
	for (auto to: g[v]) {
		if (to != p) {
			dfs(v, to);
		}
	} 
}

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;
			bool ok = 0;
			for (int i = l; i <= r; i++) {
				if (pr[a[i]] == u) {
					ok = 1;
					break;
				}
			}
			if (ok) {
				cout << l << " " << r << '\n';
				continue;
			}
			int id = 0;
			for (int i = l; i <= r; i++) {
				if (a[i] == u) {
					ok = 1;
					id = i;
					break;
				}
			}
			if (ok) {
				cout << id << " " << id << '\n';
				continue;
			}
			cout << -1 << " " << -1 << '\n';
		}
	}
} 

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
# 결과 실행 시간 메모리 Grader output
1 Runtime error 150 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 150 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 150 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 150 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -