Submission #495792

#TimeUsernameProblemLanguageResultExecution timeMemory
495792Nuraly_SerikbayBirthday gift (IZhO18_treearray)C++14
0 / 100
13 ms23800 KiB
#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; } bool did; 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; for (int j = l; j <= r; ++ j) { if (a[j] == to) did = 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]; } for (int o = 1; o <= q; ++ o) { ll type; cin >> type; if (type == 1) { cin >> pos >> val; a[pos] = val; } else { 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); if (did) { cout << l << ' ' << r; continue; } 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]]); } 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 */

Compilation message (stderr)

treearray.cpp: In function 'void get(ll)':
treearray.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for (int i = 0; i < g[v].size(); ++ i) {
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...