https://codeforces.com/contest/1562/problem/C
c
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10,M=1e6+10;
int n,m;
int q[55],sum[10];
bool st[N];
void solve()
{
int l0=0;
cin>>n;
string s;
cin>>s;
l0=s.find('0');
if(l0==-1)
{
printf("1 %d 2 %d\n",n-1,n);
return ;
}
else
{
if(l0+1<=n/2)
printf("%d %d %d %d\n",l0+1,n,l0+2,n);
else
printf("%d %d %d %d\n",1,l0+1,1,l0);
}
}
int main()
{
int T;cin>>T;
while(T--)
solve();
return 0;
}
D1
其实③也满足下面红字那句话 满足的条件 代码中归为一类
#include <iostream>
using namespace std;
int a[1000000 + 5], p[1000000 + 5];
int get_sum(int l, int r) {
if (l > r) {
return 0;
}
return (l % 2 == 1) ? p[r] - p[l - 1] : p[l - 1] - p[r];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while (t--) {
int n, q;
cin >> n >> q;
string ss;
cin >> ss;
for (int i = 1; i <= n; i++) {
a[i] = (ss[i - 1] == '+' ? 1 : -1);
}
p[0] = 0;
for (int i = 1; i <= n; i++) {
p[i] = p[i - 1] + (i % 2 == 1 ? a[i] : -a[i]);
}
for (int o = 0; o < q; o++) {
int l, r;
cin >> l >> r;
if (get_sum(l, r) == 0) {
cout << "0\n";
continue;
}
if ((r - l + 1) % 2 == 0) {
cout << "2\n";
}
else {
cout << "1\n";
}
}
}
}