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 target("arch=icelake-server")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <bitset>
using namespace std;
#define int long long
typedef long long ll;
typedef long double ld;
int log_ = 11;
int inf = 4000000007000000007;
long long mod = 1000000007;
int p = 499;
int NADIYA = 39;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; i++)
{
char c;
cin >> c;
if (c == 'C')
a[i] = 1;
else
a[i] = -1;
}
vector <int> pref1(n);
int p = 0;
for (int i = 0; i < n; i++)
{
p += a[i];
pref1[i] = p;
}
p = 0;
vector <int> pref2(n);
for (int i = n - 1; i >= 0; i--)
{
p += a[i];
pref2[i] = p;
}
p = 0;
int q;
cin >> q;
for (int j = 0; j < q; j++)
{
int l, r;
cin >> l >> r;
l--;
r--;
int x = 0;
if (l != 0)
x = pref1[l - 1];
int mn = pref1[l] - x;
for (int i = l; i <= r; i++)
{
mn = min(mn, pref1[i] - x);
}
int y = 0;
if (r+1 != n)
y = pref2[r + 1];
int mn2 = pref2[r] - y;
for (int i = l; i <= r; i++)
{
mn2 = min(mn2, pref2[i] - y);
}
cout << max(max(-mn, -mn2), 0ll) << "\n";
}
}
/*5
1 2 1
2 3 1
2 4 1
1 5 4
*/
Compilation message (stderr)
election.cpp:1: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
1 | #pragma target("arch=icelake-server")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |