Submission #852588

#TimeUsernameProblemLanguageResultExecution timeMemory
852588Mher777Birthday gift (IZhO18_treearray)C++17
0 / 100
6 ms27684 KiB
//////////////////////////////// Mher777 /* -------------------- Includes -------------------- */ #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <fstream> #pragma warning(disable : 4996) #pragma warning(disable : 6031) using namespace std; /* -------------------- Typedefs -------------------- */ typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef float fl; typedef double db; typedef long double ld; /* -------------------- Usings -------------------- */ using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; /* -------------------- Defines -------------------- */ #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"YES\n" #define no cout<<"NO\n" #define all(x) (x).begin(), (x).end() /* -------------------- Constants -------------------- */ const int MAX = int(1e9 + 5); const ll MAXL = ll(1e18 + 5); const ll MOD = ll(1e9 + 7); const ll MOD2 = ll(998244353); /* -------------------- Functions -------------------- */ void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return; } void precision(int x) { cout.setf(ios::fixed | ios::showpoint); cout.precision(x); return; } ull gcd(ull a, ull b) { while (b) { a %= b; swap(a, b); } return a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } ll range_sum(ll a, ll b) { ll dif = a - 1, cnt = b - a + 1; ll ans = ((b - a + 1) * (b - a + 2)) / 2; ans += ((b - a + 1) * dif); return ans; } string dec_to_bin(ll a) { string s = ""; for (ll i = a; i > 0; ) { ll k = i % 2; i /= 2; char c = k + 48; s += c; } if (a == 0) { s = "0"; } reverse(all(s)); return s; } ll bin_to_dec(string s) { ll num = 0; for (int i = 0; i < s.size(); i++) { num *= 2ll; num += (s[i] - '0'); } return num; } bool isPrime(ll a) { if (a == 1) { return false; } for (ll i = 2; i * i <= a; i++) { if (a % i == 0) { return false; } } return true; } int dig_sum(ll a) { int sum = 0; while (a) { sum += int(a % 10); a /= 10; } return sum; } ll binpow(ll a, int b) { ll ans = 1; while (b) { if ((b & 1) == 1) { ans *= a; } b >>= 1; a *= a; } return ans; } ll binpow_by_mod(ll a, ll b, ll mod) { ll ans = 1; while (b) { if ((b & 1) == 1) { ans *= a; ans %= mod; } b >>= 1; a *= a; a %= mod; } return ans; } ll factorial(int a) { ll ans = 1; for (int i = 2; i <= a; i++) { ans *= ll(i); } return ans; } ll factorial_by_mod(int a, ll mod) { ll ans = 1; for (int i = 2; i <= a; i++) { ans *= ll(i); ans %= mod; } return ans; } /* -------------------- Solution -------------------- */ const int N = 200005; vi g[N]; set<int> ans[N], id[N]; int a[N], used[N], pox[N], tin[N], tout[N], num, l, timer; vector<vi> up; void dfs(int u, int v = 0) { used[u] = 1, pox[u] = num++, tin[u] = timer++; up[u][0] = v; for (int i = 1; i <= l; i++) { up[u][i] = up[up[u][i - 1]][i - 1]; } for (auto to : g[u]) { if (!used[to]) dfs(to, u); } tout[u] = timer++; } bool upper(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tin[v]; } int lca(int u, int v) { if (upper(u, v)) return u; if (upper(v, u)) return v; for (int i = l; i >= 0; i--) { if (!upper(up[u][i], v)) u = up[u][i]; } return up[u][0]; } void slv() { int n, m, q; cin >> n >> m >> q; for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x--, y--; g[x].pub(y); g[y].pub(x); } l = log2(n) + 2; up.resize(n); for (int i = 0; i < n; i++) up[i].resize(l + 1); dfs(0); for (int i = 0; i < m; i++) { cin >> a[i]; a[i]--; a[i] = pox[a[i]]; id[a[i]].insert(i); if (i > 0) { ans[lca(a[i], a[i - 1])].insert(i - 1); } } while (q--) { int tp; cin >> tp; if (tp == 1) { int pos, x; cin >> pos >> x; pos--, x--; id[a[pos]].erase(pos); id[pox[x]].insert(pos); if (pos < m - 1) { ans[lca(a[pos], a[pos + 1])].erase(pos); ans[lca(pox[x], a[pos + 1])].insert(pos); } if (pos > 0) { ans[lca(a[pos], a[pos - 1])].erase(pos - 1); ans[lca(pox[x], a[pos - 1])].insert(pos - 1); } a[pos] = pox[x]; } else { int l, r, x; cin >> l >> r >> x; x--; auto lb1 = id[x].lower_bound(l - 1); if (lb1 != id[x].end() && *lb1 < r) { cout << *lb1 + 1 << " " << *lb1 + 1 << '\n'; continue; } auto lb = ans[x].lower_bound(l - 1); if (lb == ans[x].end() || *lb >= r - 1) { cout << -1 << " " << -1 << '\n'; } else { cout << *lb + 1 << " " << *lb + 2 << '\n'; } } } } /* 7 7 1000 1 2 2 3 2 4 1 5 5 6 5 7 1 2 3 4 5 6 7 2 1 7 1 */ void cs() { int tstc = 1; //cin >> tstc; while (tstc--) { slv(); } } void precalc() { return; } int main() { fastio(); precalc(); //precision(1); cs(); return 0; }

Compilation message (stderr)

treearray.cpp:25: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   25 | #pragma warning(disable : 4996)
      | 
treearray.cpp:26: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   26 | #pragma warning(disable : 6031)
      | 
treearray.cpp: In function 'll range_sum(ll, ll)':
treearray.cpp:95:21: warning: unused variable 'cnt' [-Wunused-variable]
   95 |     ll dif = a - 1, cnt = b - a + 1;
      |                     ^~~
treearray.cpp: In function 'll bin_to_dec(std::string)':
treearray.cpp:118:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for (int i = 0; i < s.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...