(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 #245278

#TimeUsernameProblemLanguageResultExecution timeMemory
245278OrtGrudanje (COCI19_grudanje)C++11
70 / 70
1546 ms13996 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<ext/rope> #define mem(a, b) memset(a, (b), sizeof(a)) #define all(c) (c).begin(),(c).end() #define sz(a) ((int)(a.size())) #define ll long long #define linf (ll)1e18 #define inf (int)1e9 #define minf 0x3F3F3F3F #define pb push_back #define fs first #define sc second #define mp make_pair #define mod 1000000007 #define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define MAX 100010 #define MXT 100005 #define watch(x) cerr<<#x<<" = "<<(x)<<endl; using namespace std; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int n; string s; int bit[40][MAX]; int arr[MAX]; vector<pii> Q; int sum(int c, int k) { int s = 0; while(k>=1) { s += bit[c][k]; k -= k&-k; } return s; } void add(int c, int k, int x) { while(k<=MXT) { bit[c][k] += x; k += k&-k; } } int rsum(int c, int a, int b) { return sum(c, b)-sum(c, a-1); } bool valid(int id) { bool ret = true; for(int i=1;i<=id;i++) { char c = s[arr[i]-1]; add(c-'a', arr[i], -1); } for(int i=0;i<sz(Q);i++) { for(int j=0;j<27;j++) { int cnt = rsum(j, Q[i].fs, Q[i].sc); if(cnt>1) ret = false; } } for(int i=1;i<=id;i++) { char c = s[arr[i]-1]; add(c-'a', arr[i], 1); } return ret; } int main() { IO; cin >> s >> n; for(int i=0;i<sz(s);i++) { add(s[i]-'a', i+1, 1); } for(int i=0;i<n;i++) { int a, b; cin >> a >> b; Q.pb(mp(a,b)); } for(int i=1;i<=sz(s);i++) cin >> arr[i]; int low = 0, high = sz(s), ans = 0; while(low<=high) { int mid = (low+high)>>1; if(valid(mid)) ans = mid, high = mid-1; else low = mid+1; } cout << ans; return 0; }
#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...