Submission #548613

#TimeUsernameProblemLanguageResultExecution timeMemory
548613Olympia Martian DNA (BOI18_dna)C++17
40 / 100
2050 ms1048576 KiB
#include <cmath> #include <iostream> #include <set> #include <climits> #include <algorithm> #include <cassert> #include <vector> #include <iomanip> #include <type_traits> #include <string> #include <queue> #include <map> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") typedef long long ll; using namespace std; template<class T> class SegmentTree { public: void resz (int N) { N = (1 << ((int)floor(log2(N - 1)) + 1)); this->N = N; val.assign(2 * N, ID); } void update (int x, T y) { x += N - 1; val[x] = y; while (x != 0) { x = (x - 1)/2; val[x] = merge(val[2 * x + 1], val[2 * x + 2]); } } T query (int ind, const int l, const int r, int tl, int tr) { if (tl >= l && tr <= r) { return val[ind]; } if (tr < l || tl > r) { return ID; } return merge(query(2 * ind + 1, l, r, tl, (tl + tr)/2), query(2 * ind + 2, l, r, (tl + tr)/2 + 1, tr)); } T query (int l, int r) { return query(0, l, r, 0, N - 1); } private: vector<T> val; T ID = 0; T merge (T x, T y) { return x + y; } int N; }; vector<SegmentTree<int>> st; vector<int> arr; vector<pair<int,int>> queries; bool okay (int l, int r) { int R = queries.size(); for (int i = 0; i < R; i++) { if (st[i].query(l, r) < queries[i].second) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, K, R; cin >> N >> K >> R; st.resize(R); for (int i = 0; i < R; i++) { st[i].resz(N); } arr.resize(N); for (int i = 0; i < N; i++) { cin >> arr[i]; } queries.resize(R); for (int i = 0; i < R; i++) { cin >> queries[i].first >> queries[i].second; } for (int i = 0; i < N; i++) { for (int j = 0; j < R; j++) { if (arr[i] == queries[j].first) { st[j].update(i, 1); } } } int myMin = INT_MAX; for (int i = 0; i < N; i++) { if (!okay(i, N - 1)) { break; } int l = i; int r = N - 1; while (l != r) { int m = (l + r)/2; if (okay(i, m)) { r = m; } else { l = m + 1; } } //cout << i << " " << l << '\n'; myMin = min(myMin, l - i + 1); } if (myMin == INT_MAX) { cout << "impossible\n"; } else { cout << myMin; } }

Compilation message (stderr)

dna.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   14 | #pragma GCC optimization ("O3")
      | 
dna.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...