Submission #932515

#TimeUsernameProblemLanguageResultExecution timeMemory
93251512345678 Martian DNA (BOI18_dna)C++17
0 / 100
83 ms25576 KiB
#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]; void update(int l, int r, int i, int ql, int qr, int vl) { if (qr<l||r<ql||r<l) return; if (ql<=l&&r<=qr) return d[i]=min(d[i], vl), 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) { 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; d[2*i]=min(d[2*i], d[i]); solve(l, md, 2*i); d[2*i+1]=min(d[2*i+1], d[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 (stderr)

dna.cpp: In function 'int main()':
dna.cpp:42:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         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';
      |                       ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...