이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define Zymraq() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double ld;
typedef long double lld;
const int N = 1e6 + 17;
const int modd = 1e9 + 7;
const int INF = 1e9 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const ld eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
return (a.second < b.second);
}
void pre (ll a) {
cout << fixed << setprecision(a);
return;
}
ll n, m, q;
vector <ll> g[N];
ll x, y, a[N];
ll pos, val;
ll l, r, mn = INF;
bool ok;
vector <ll> ans;
ll col[N];
void get (ll v) {
for (int i = 0; i < g[v].size(); ++ i) {
ll to = g[v][i];
if (v == val) {
col[to] = i + 1;
} else {
col[to] = col[v];
}
get (to);
}
return;
}
inline void Solution () {
cin >> n >> m >> q;
for (int i = 1; i < n; ++ i) {
cin >> x >> y;
g[min (x, y)].pb (max (x, y));
}
for (int i = 1; i <= m; ++ i) {
cin >> a[i];
}
while (q --) {
ll type;
cin >> type;
if (type == 1) {
cin >> pos >> val;
a[pos] = val;
} else {
bool did = 0;
cin >> l >> r >> val;
for (int i = l; i <= r; ++ i) {
if (val == a[i]) {
cout << i << ' ' << i << '\n';
did = 1;
break;
}
}
if (did) continue;
get (val);
for (int i = l; i < r; ++ i) {
for (int j = l + 1; j <= r; ++ j) {
set <ll> ss;
for (int k = i; k <= j; ++ k) {
ss.insert(a[k]);
}
if (ss.size() == 1 && val == a[i]) {
cout << i << ' ' << j << '\n';
did = 1;
}
if (did) break;
set <ll> s;
for (int k = i; k <= j; ++ k) {
s.insert (col[a[k]]);
}
//cout << s.size() << ' ';
if (s.size() >= 2) {
cout << i << ' ' << j << '\n';
did = 1;
}
if (did) break;
}
if (did) break;
}
for (int k = 1; k <= n; ++ k) col[k] = 0;
if (!did) cout << -1 << ' ' << -1 << '\n';
}
}
return;
}
int main () {
Zymraq();
Solution ();
exit (0);
}
/*
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
*/
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp: In function 'void get(ll)':
treearray.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < g[v].size(); ++ i) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |