답안 #927053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927053 2024-02-14T07:40:35 Z Pragmatism Martian DNA (BOI18_dna) C++17
100 / 100
86 ms 4972 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 2e5 + 7;
const int M = 5e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define int long long

int n, k, q, a[N], req[N], t[4 * N];
void update(int v, int tl, int tr, int pos, int x) {
    if (tl == tr) {
        t[v] += x;
        return;
    }
    int mid = (tl + tr) / 2;
    if (pos <= mid)update(v * 2, tl, mid, pos, x);
    else update(v * 2 + 1, mid + 1, tr, pos, x);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}
void solve() {
    cin >> n >> k >> q;
    for (int i = 1;i <= n;i++)cin >> a[i], a[i]++;
    for (int i = 1;i <= q;i++) {
        int x, cnt;
        cin >> x >> cnt;
        req[++x] = cnt, update(1, 1, n, x, cnt);
    }
    int r = 0, ans = inf;
    for (int l = 1;l <= n;l++) {
        while (r < n && t[1] > 0)r++, update(1, 1, n, a[r], -1);
        if (t[1] <= 0)ans = min(ans, r - l + 1);
        update(1, 1, n, a[l], 1);
    }
    if (ans == inf)cout << "impossible";
    else cout << ans;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Compilation message

dna.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    4 | #pragma comment(linker, "/stack:200000000")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 0 ms 2404 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2564 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3116 KB Output is correct
2 Correct 25 ms 2908 KB Output is correct
3 Correct 26 ms 2904 KB Output is correct
4 Correct 24 ms 2908 KB Output is correct
5 Correct 54 ms 3684 KB Output is correct
6 Correct 29 ms 2904 KB Output is correct
7 Correct 35 ms 2908 KB Output is correct
8 Correct 66 ms 4972 KB Output is correct
9 Correct 46 ms 2904 KB Output is correct
10 Correct 31 ms 2904 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2548 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 3760 KB Output is correct
2 Correct 64 ms 3544 KB Output is correct
3 Correct 59 ms 3548 KB Output is correct
4 Correct 26 ms 2908 KB Output is correct
5 Correct 75 ms 3960 KB Output is correct
6 Correct 86 ms 4764 KB Output is correct
7 Correct 54 ms 2904 KB Output is correct
8 Correct 67 ms 2908 KB Output is correct
9 Correct 28 ms 3308 KB Output is correct
10 Correct 25 ms 2908 KB Output is correct
11 Correct 25 ms 2908 KB Output is correct
12 Correct 30 ms 2908 KB Output is correct
13 Correct 58 ms 3676 KB Output is correct
14 Correct 30 ms 2908 KB Output is correct
15 Correct 34 ms 2908 KB Output is correct
16 Correct 68 ms 4956 KB Output is correct
17 Correct 57 ms 2908 KB Output is correct
18 Correct 31 ms 2904 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2548 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct