답안 #932517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932517 2024-02-23T14:53:07 Z 12345678 Martian DNA (BOI18_dna) C++17
0 / 100
151 ms 37820 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;
int n, v[nx], k, r, res[nx], b, q, ans=INT_MAX;
vector<int> d[nx];

struct segtree
{
    int d[4*nx], lz[4*nx], lzs[4*nx];
    void pushlz(int l, int r, int i)
    {
        if (!lz[i]) return;
        lz[i]=0;
        if (l==r) return d[i]=min(d[i], lzs[i]), void();
        if (!lz[2*i]) lz[2*i]=1, lzs[2*i]=lzs[i];
        else lzs[2*i]=min(lzs[2*i], lzs[i]);
        if (!lz[2*i+1]) lz[2*i+1]=1, lzs[2*i+1]=lzs[i];
        else lzs[2*i+1]=min(lzs[2*i+1], lzs[i]);
    }
    void update(int l, int r, int i, int ql, int qr, int vl)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql||r<l) return;
        if (ql<=l&&r<=qr) return lz[i]=1, lzs[i]=vl, pushlz(l, r, i), void();
        int md=(l+r)/2;
        update(l, md, 2*i, ql, qr, vl);
        update(md+1, r, 2*i+1, ql, qr, vl);
    }
    void solve(int l, int r, int i)
    {
        pushlz(l, r, i);
        if (l==r) return ans=min(ans, (d[i]!=INT_MIN)?l-d[i]+1:INT_MAX),void(); //cout<<l<<' '<<d[i]<<'\n', void();
        int md=(l+r)/2;
        solve(l, md, 2*i);
        solve(md+1, r, 2*i+1);
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k>>r;
    for (int i=1; i<=n; i++) cin>>v[i], d[v[i]].push_back(i);
    for (int i=1; i<4*nx; i++) s.d[i]=INT_MAX;
    for (int i=1; i<=r; i++)
    {
        cin>>b>>q;
        d[b].push_back(n+1);
        s.update(1, n, 1, 1, d[b][q-1]-1, INT_MIN);
        for (int j=q; j<d[b].size(); j++) s.update(1, n, 1, d[b][j-1], d[b][j]-1, d[b][j-q]); //cout<<"update "<<d[b][j-1]<<' '<<d[b][j]-1<<' '<<d[b][j-q]<<'\n';
        //cout<<"ask\n";
        //s.solve(1,n , 1);
    }
    s.solve(1,n , 1);
    if (ans==INT_MAX) cout<<"impossible";
    else cout<<ans;
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int j=q; j<d[b].size(); j++) s.update(1, n, 1, d[b][j-1], d[b][j]-1, d[b][j-q]); //cout<<"update "<<d[b][j-1]<<' '<<d[b][j]-1<<' '<<d[b][j-q]<<'\n';
      |                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Incorrect 3 ms 12892 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 3 ms 12888 KB Output is correct
4 Correct 4 ms 12888 KB Output is correct
5 Correct 3 ms 12888 KB Output is correct
6 Correct 4 ms 13148 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Incorrect 2 ms 12892 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 16988 KB Output is correct
2 Correct 27 ms 16912 KB Output is correct
3 Correct 44 ms 16600 KB Output is correct
4 Correct 35 ms 16948 KB Output is correct
5 Correct 27 ms 18424 KB Output is correct
6 Correct 12 ms 16984 KB Output is correct
7 Correct 18 ms 16728 KB Output is correct
8 Correct 30 ms 21848 KB Output is correct
9 Correct 19 ms 16988 KB Output is correct
10 Correct 38 ms 16904 KB Output is correct
11 Correct 3 ms 12888 KB Output is correct
12 Correct 3 ms 12892 KB Output is correct
13 Correct 2 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 13148 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 4 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Incorrect 2 ms 12892 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 18268 KB Output is correct
2 Correct 132 ms 17752 KB Output is correct
3 Correct 69 ms 17844 KB Output is correct
4 Correct 34 ms 15692 KB Output is correct
5 Runtime error 42 ms 37820 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -