Submission #349236

#TimeUsernameProblemLanguageResultExecution timeMemory
349236dolphingarlicThe Potion of Great Power (CEOI20_potion)C++14
100 / 100
1754 ms104428 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, C = 6; int H[100000]; bool odd[100000]; vector<int> u_times[100000]; vector<vector<int>> trust[100000]; struct cmp { bool operator()(pair<int, int> a, pair<int, int> b) const { return tie(H[a.second], a.first) < tie(H[b.second], b.first); } }; vector<set<pair<int, int>, cmp>> updates[100000]; void init(int N, int D, int H[]) { for (int i = 0; i < N; i++) { trust[i].push_back({}); updates[i].push_back({}); u_times[i].push_back(0); ::H[i] = H[i]; } } vector<int> playback(int s, int t) { int ub = upper_bound(u_times[s].begin(), u_times[s].end(), t) - u_times[s].begin() - 1; vector<int> orig = trust[s][ub]; set<pair<int, int>, cmp> upd = updates[s][ub]; for (int i : orig) odd[i] ^= 1; for (pair<int, int> i : upd) { if (i.first >= t) continue; odd[i.second] ^= 1; } vector<int> ret1, ret2; for (int i : orig) if (odd[i]) ret1.push_back(i), odd[i] = 0; for (pair<int, int> i : upd) { if (i.first >= t) continue; if (odd[i.second]) ret2.push_back(i.second), odd[i.second] = 0; } vector<int> mrg; int ptr1 = 0, ptr2 = 0; while (ptr1 < ret1.size() && ptr2 < ret2.size()) { if (H[ret1[ptr1]] < H[ret2[ptr2]]) mrg.push_back(ret1[ptr1++]); else mrg.push_back(ret2[ptr2++]); } while (ptr1 < ret1.size()) mrg.push_back(ret1[ptr1++]); while (ptr2 < ret2.size()) mrg.push_back(ret2[ptr2++]); return mrg; } void curseChanges(int U, int A[], int B[]) { for (int i = 0; i < U; i++) { updates[A[i]].back().insert({i, B[i]}); updates[B[i]].back().insert({i, A[i]}); if (updates[A[i]].back().size() == C) { trust[A[i]].push_back(playback(A[i], i + 1)); updates[A[i]].push_back({}); u_times[A[i]].push_back(i + 1); } if (updates[B[i]].back().size() == C) { trust[B[i]].push_back(playback(B[i], i + 1)); updates[B[i]].push_back({}); u_times[B[i]].push_back(i + 1); } } } int question(int x, int y, int v) { vector<int> sx = playback(x, v); vector<int> sy = playback(y, v); int ans = INF; for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) { ans = min(ans, abs(H[sx[xptr]] - H[sy[yptr]])); if (H[sx[xptr]] <= H[sy[yptr]]) xptr++; else yptr++; } return ans; }

Compilation message (stderr)

potion.cpp: In function 'std::vector<int> playback(int, int)':
potion.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while (ptr1 < ret1.size() && ptr2 < ret2.size()) {
      |            ~~~~~^~~~~~~~~~~~~
potion.cpp:43:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while (ptr1 < ret1.size() && ptr2 < ret2.size()) {
      |                                  ~~~~~^~~~~~~~~~~~~
potion.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     while (ptr1 < ret1.size()) mrg.push_back(ret1[ptr1++]);
      |            ~~~~~^~~~~~~~~~~~~
potion.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     while (ptr2 < ret2.size()) mrg.push_back(ret2[ptr2++]);
      |            ~~~~~^~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:73:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) {
      |                                  ~~~~~^~~~~~~~~~~~
potion.cpp:73:60: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int xptr = 0, yptr = 0; xptr != sx.size() && yptr != sy.size();) {
      |                                                       ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...