This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
using namespace std;
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi>
#define pc __builtin_popcountll
#define vp vector<pii>
#define sp << " " <<
#define all(x) x.bg()+1,x.end()
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back
const int inf = 1e18;
const int MOD = 998244353;
const int N = 2e5+1;
vvi up(N,vi(22));
int n;
string s;
void build(int node,int l,int r) {
F(i,n) up[i][0] = (1<<(s[i-1]-'a'));
for (int i=1;i<=21;i++) {
for (int j=1;j+(1<<(i-1))<=n;j++) {
up[j][i] = up[j][i-1]|up[j+(1<<(i-1))][i-1];
}
}
return;
}
int query(int L,int R) {
int x = __lg(R-L+1);
return up[L][x]|up[R-(1<<x)+1][x];
}
void solve() {
cin >> n;
cin >> s;
build(1,1,n);
double best = 1;
pii ans;
for (int x = 1;x<=26;x++) {
for (int i=1;i<=n;i++){
int l = i;
int r = n;
while (l<=r) {
int m = (l+r) >> 1;
if (pc(query(i,m)) <= x) l = m+1;
else r = m-1;
}
double v = (double)x/(r-i+1);
if (best > v) {
best = v;
ans = {i,r};
}
}
}
cout << ans.ff sp ans.ss << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef Local
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message (stderr)
nivelle.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
2 | #pragma optimize "DostSeferoğlu"
|
# | 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... |