Submission #668506

#TimeUsernameProblemLanguageResultExecution timeMemory
668506hoanghq2004Rarest Insects (IOI22_insects)C++17
57.92 / 100
154 ms560 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "insects.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; // //static inline constexpr int kMaxQueries = 40000; // //static int N; //// Insect types are compressed to colors in the range [0, N). //static std::vector<int> color; //static std::vector<bool> in_box; // //static std::vector<int> color_occurrences; //static std::multiset<int> max_occurrences; // //static std::vector<int> op_counter(3, 0); // //static inline void protocol_violation(std::string message) { // printf("Protocol Violation: %s\n", message.c_str()); // exit(0); //} // //void move_inside(int i) { // if (i < 0 || i >= N) { // protocol_violation("invalid parameter"); // } // ++op_counter[0]; // if (op_counter[0] > kMaxQueries) { // protocol_violation("too many calls"); // } // if (!in_box[i]) { // in_box[i] = true; // max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); // ++color_occurrences[color[i]]; // max_occurrences.insert(color_occurrences[color[i]]); // } //} // //void move_outside(int i) { // if (i < 0 || i >= N) { // protocol_violation("invalid parameter"); // } // ++op_counter[1]; // if (op_counter[1] > kMaxQueries) { // protocol_violation("too many calls"); // } // if (in_box[i]) { // in_box[i] = false; // max_occurrences.erase(max_occurrences.find(color_occurrences[color[i]])); // --color_occurrences[color[i]]; // max_occurrences.insert(color_occurrences[color[i]]); // } //} // //int press_button() { // ++op_counter[2]; // if (op_counter[2] > kMaxQueries) { // protocol_violation("too many calls"); // } // return *(max_occurrences.rbegin()); //} int min_cardinality(int n) { vector <int> s, root(n); for (int i = 0; i < n; ++i) { move_inside(i); if (press_button() == 1) s.push_back(i), ++root[i]; else move_outside(i); } vector <int> a; for (int i = 0; i < n; ++i) if (!root[i]) a.push_back(i); function <void(int, int, vector <int>)> divide = [&](int L, int R, vector <int> a) { if (L > R || a.empty()) return; if (L == R) { for (auto x: a) ++root[s[L]]; return; } int mid = L + R >> 1; for (int i = mid + 1; i <= R; ++i) move_outside(s[i]); vector <int> l, r; for (auto x: a) { move_inside(x); if (press_button() > 1) l.push_back(x); else r.push_back(x); move_outside(x); } divide(L, mid, l); for (int i = mid + 1; i <= R; ++i) move_inside(s[i]); divide(mid + 1, R, r); }; divide(0, s.size() - 1, a); int ans = n; for (int i = 0; i < n; ++i) if (root[i]) ans = min(ans, root[i]); return ans; } // //int main() { // assert(1 == scanf("%d", &N)); // color.resize(N); // in_box.assign(N, false); // // std::map<int, int> type_to_color; // for (int i = 0; i < N; ++i) { // int Ti; // assert(1 == scanf("%d", &Ti)); // if (type_to_color.find(Ti) == type_to_color.end()) { // int new_color = type_to_color.size(); // type_to_color[Ti] = new_color; // max_occurrences.insert(0); // } // color[i] = type_to_color[Ti]; // } // // color_occurrences.assign(type_to_color.size(), 0); // // int answer = min_cardinality(N); // int Q = *std::max_element(op_counter.begin(), op_counter.end()); // printf("%d\n", answer); // printf("%d\n", Q); // return 0; //}

Compilation message (stderr)

insects.cpp: In lambda function:
insects.cpp:85:23: warning: unused variable 'x' [-Wunused-variable]
   85 |             for (auto x: a) ++root[s[L]];
      |                       ^
insects.cpp:88:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |         int mid = L + R >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...