(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #222375

#TimeUsernameProblemLanguageResultExecution timeMemory
222375dwscGrudanje (COCI19_grudanje)C++14
70 / 70
802 ms11680 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; int prevArr[100010]; struct node{ int s,e,m,v; node *l,*r; node(int _s,int _e){ s = _s; e = _e; m = (s+e)/2; v = 0; if (s != e){ l = new node(s,m); r = new node(m+1,e); } } void updateAll(){ if (s == e) v = prevArr[s]; else{ l->updateAll(); r->updateAll(); v = max(l->v,r->v); } } int rmq(int x,int y){ if(s == x && e == y) return v; if (y <= m) return l->rmq(x,y); if (x > m) return r->rmq(x,y); return max(l->rmq(x,m),r->rmq(m+1,y)); } }*root; int main(){ string s; cin >> s; int n,q; cin >> q; n = s.length(); root = new node(0,n-1); ii arr[q]; for (int i = 0; i < q; i++) { cin >> arr[i].first>> arr[i].second; arr[i].first--; arr[i].second--; } int toss[n+1]; for (int i = 1; i <= n; i++) { cin >> toss[i]; toss[i]--; } int l = 0,r = n+1; while (l != r){ int m = (l+r)/2; //cout << m << "here\n"; char temp[n]; for (int i =0; i < n; i++) temp[i] = s[i]; for (int i = 1; i <= m; i++) temp[toss[i]] = '-'; int pos[26]; for (int i = 0; i < 26; i++) pos[i] = -1; for (int i = 0; i < n; i++){ if (temp[i] == '-') prevArr[i] = -1; else{ prevArr[i] = pos[temp[i]-97]; pos[temp[i]-97] = i; } //cout << prevArr[i] << " "; } //cout << "\n"; root->updateAll(); int can = 1; for (int i = 0; i < q; i++){ //cout << arr[i].first << " " << arr[i].second << "\n"; //cout << root->rmq(arr[i].first,arr[i].second) << "hi\n"; if (root->rmq(arr[i].first,arr[i].second) >= arr[i].first) can = 0; } if (can) r = m; else l = m+1; } cout << l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...