이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,l,r,mas[500005],a[2],rez;
vector<int> k;
vector<int>::iterator it;
char c;
int main()
{
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n;
i=0;
while (i<n)
{
cin >> c;
if (c=='C')
{
mas[i]=1;
}
i++;
}
cin >> m;
i=0;
while (i<m)
{
cin >> l >> r;
l--;
r--;
j=l;
a[0]=0;
a[1]=0;
k.clear();
rez=0;
while (j<=r)
{
a[mas[j]]++;
if (a[1]<a[0])
{
a[mas[j]]--;
k.push_back(j);
rez++;
}
j++;
}
a[0]=0;
a[1]=0;
j=r;
it=k.end();
it--;
while (j>=l)
{
if (k.empty()||j!=*it)
{
a[mas[j]]++;
if (a[1]<a[0])
{
a[mas[j]]--;
rez++;
//cout << j << "\n";
}
}
else
{
k.pop_back();
it=k.end();
it--;
}
j--;
}
cout << rez << "\n";
i++;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |