This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
//types
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define pw2(x) (1LL << (x))
#define getBit(x, y) ((x) & (1LL << (y)))
template<class X, class Y>
bool cmax(X &a, const Y &b) {
return a < b ? a = b, 1 : 0;
}
template<class X, class Y>
bool cmin(X &a, const Y &b) {
return a > b ? a = b, 1 : 0;
}
struct Answer {
ll l, r, first, second;
Answer(ll _l = 0, ll _r = 0, ll _first = 0, ll _second = 0) {
l = _l; r = _r; first = _first; second = _second;
}
};
//lowercase 31, all 53
//(P/Q) % M = (P % M) * (Q^(M-2) % M)
//-------------------------------------------------------
const ld PI = 3.14159265359;
const ll N = 1e5+5, L = 18, mod = 1e9+7;
int n, a[N];
int lg[N], st[N][L+2];
int get(int l, int r) {
int j = lg[r - l + 1];
return __builtin_popcount(st[l][j] | st[r - (1 << j) + 1][j]);
}
Answer ans(0, 0, inf, 1);
Answer comp(Answer x, Answer y) {
Answer t1 = x, t2 = y;
x.fi *= y.se; y.fi *= x.se;
x.se = y.se = x.se * y.se;
if (x.fi <= y.fi) return t1;
return t2;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
char tmp; cin >> tmp; a[i] = 'z' - tmp;
st[i][0] = (1 << a[i]);
}
for (int i = 2; i <= n; i++)
lg[i] = lg[i/2] + 1;
for (int j = 1; j <= L; j++) {
for (int i = 1; i <= n - (1 << j) + 1; i++) {
st[i][j] = st[i][j-1] | st[i + (1 << (j-1))][j-1];
}
}
for (int cnt = 1; cnt <= 26; cnt++) {
for (int i = 1; i <= n; i++) {
int l = i, r = n, kq = -1;
while (l <= r) {
int mid = (l+r) / 2;
if (get(i, mid) <= cnt) {
kq = mid;
l = mid + 1;
}
else r = mid - 1;
}
if (kq != -1 && get(i, kq) == cnt) {
ans = comp(ans, Answer(i, kq, cnt, kq-i+1));
}
}
}
cout << ans.l << " " << ans.r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |