답안 #548619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548619 2022-04-14T02:27:09 Z Olympia Martian DNA (BOI18_dna) C++17
0 / 100
233 ms 8520 KB
#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> struct Seg { // comb(ID,b) = b
    const T ID = 1; T comb(T a, T b) { return min(a,b); }
    int n; vector<T> seg;
    void init(int _n) { n = _n; seg.assign(2*n,ID); }
    void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
    void upd(int p, T val) { // set val at position p
        seg[p += n] = val; for (p /= 2; p; p /= 2) pull(p); }
    T query(int l, int r) {	// sum on interval [l, r]
        T ra = ID, rb = ID;
        for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
            if (l&1) ra = comb(ra,seg[l++]);
            if (r&1) rb = comb(seg[--r],rb);
        }
        return comb(ra,rb);
    }
};
vector<int> arr;
vector<pair<int,int>> queries;
Seg<int> valid;
vector<int> cnt;
map<int,int> myMap;
void updater (int x, int d) {
    if (!myMap.count(arr[x])) {
        return;
    }
    cnt[myMap[arr[x]]] += d;
    valid.upd(myMap[arr[x]], cnt[myMap[arr[x]]] >= queries[myMap[arr[x]]].second);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K, R;
    cin >> N >> K >> R;
    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;
        myMap[queries[i].first] = i;
    }
    cnt.resize(R);
    valid.init(R + 1);
    for (int i = 0; i <= R; i++) {
        valid.upd(i, 0);
    }
    int l = -1;
    int r = -1;
    int myMin = INT_MAX;
    while (l + 1 < N && r < N) {
        if (l != -1) {
            updater(l, -1);
        }
        l++;
        while (r != N - 1 && !valid.query(0, R - 1)) {
            updater(r + 1, 1);
            r++;
        }
        if (!valid.query(0, R - 1)) {
            break;
        }
        myMin = min(myMin, r - l + 1);
    }
    cout << myMin;
}

Compilation message

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")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1108 KB Output is correct
2 Correct 15 ms 1108 KB Output is correct
3 Correct 26 ms 1108 KB Output is correct
4 Correct 23 ms 1108 KB Output is correct
5 Correct 23 ms 1108 KB Output is correct
6 Correct 20 ms 1108 KB Output is correct
7 Incorrect 16 ms 1108 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 8192 KB Output is correct
2 Correct 222 ms 6596 KB Output is correct
3 Correct 109 ms 3788 KB Output is correct
4 Correct 16 ms 1488 KB Output is correct
5 Incorrect 170 ms 8520 KB Output isn't correct
6 Halted 0 ms 0 KB -