#pragma GCC optimize(3,"Ofast","inline") //G++
#include
#define TEST freopen("C:\\Users\\hp\\Desktop\\ACM\\in.txt","r",stdin);
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int inf=0x3f3f3f3f;
const ll INF=0x7fffffffffffffff;
const int mod=1e9+7;
const int maxn = 1e6+5;
const double eps=1e-8;
template<typename T> void read(T &x) {
x = 0;
char ch = getchar();
ll f = 1;
while(!isdigit(ch)) {
if(ch == '-')f*=-1;
ch=getchar();
}
while(isdigit(ch)) {
x = x*10+ch-48;
ch=getchar();
}
x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
int sgn(double a) {
return a<-eps?-1:a<eps?0:1;
}
inline int add(int x,int y) {
return x+y>=mod?x+y-mod:x+y;
}
inline int sub(int x,int y) {
return x-y<0?x-y+mod:x-y;
}
inline int mul(int x,int y) {
return 1ll*x*y%mod;
}
inline int sq(int x) {
return 1ll*x*x%mod;
}
int pow(int a,int b) {
return b == 0?1:( b&1?mul(a,sq(pow(a,b/2))):sq(pow(a,b/2)));
}
int main() {
int T;
read(T);
while(T--) {
int n,sum=0,pos=0;
read(n);
for(int i=1; i<=n; i++) {
int x;
read(x);
if(x&1) pos=i;
sum+=x;
}
if(sum%2==0) {
cout<<n<<"\n";
for(int i=1; i<=n; i++) {
cout<<i<<" ";
}
} else {
if(n==1)
cout<<"-1";
else {
cout<<n-1<<"\n";
for(int i=1; i<=n; i++) {
if(i!=pos)
cout<<i<<" ";
}
}
}
cout<<"\n";
}
}
#pragma GCC optimize(3,"Ofast","inline") //G++
#include
#define TEST freopen("C:\\Users\\hp\\Desktop\\ACM\\in.txt","r",stdin);
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll INF=0x7fffffffffffffff;
const int mod=1e9+7;
const int maxn = 1e6+5;
const double eps=1e-8;
template<typename T> void read(T &x) {
x = 0;
char ch = getchar();
ll f = 1;
while(!isdigit(ch)) {
if(ch == '-')f*=-1;
ch=getchar();
}
while(isdigit(ch)) {
x = x*10+ch-48;
ch=getchar();
}
x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
int sgn(double a) {
return a<-eps?-1:a<eps?0:1;
}
inline int add(int x,int y) {
return x+y>=mod?x+y-mod:x+y;
}
inline int sub(int x,int y) {
return x-y<0?x-y+mod:x-y;
}
inline int mul(int x,int y) {
return 1ll*x*y%mod;
}
inline int sq(int x) {
return 1ll*x*x%mod;
}
int pow(int a,int b) {
return b == 0?1:( b&1?mul(a,sq(pow(a,b/2))):sq(pow(a,b/2)));
}
vector<pii>v;
void solve(int n){
for(int i=1;i*i<=n;i++){
if(n%i==0){
v.push_back({i,n/i});
if(i*i!=n)
v.push_back({n/i,i});
}
}
}
int n,m,k;
int a[maxn],b[maxn];
int sum[maxn][2];
int main() {
read(n,m,k);
for(int i=1;i<=n;i++){
read(a[i]);
sum[i][0]+=sum[i-1][0]+a[i];
}
for(int i=1;i<=m;i++){
read(b[i]);
sum[i][1]+=sum[i-1][1]+b[i];
}
solve(k);
ll ans=0;
for(auto it:v){
int x=it.first,y=it.second;
int sum1=0,sum2=0;
for(int i=1;i<=n-x+1;i++){
sum1+=(sum[i+x-1][0]-sum[i-1][0]==x);
}
for(int i=1;i<=m-y+1;i++){
sum2+=(sum[i+y-1][1]-sum[i-1][1]==y);
}
ans+=1ll*sum1*sum2;
}
cout<<ans<<"\n";
}
括号序列性质:左括号减1右括号加1。方法序列的情况需要满足下面的2个条件
1:前缀和为0时
2:前缀最小值为0时为合法序列
知道这些就好做了
#pragma GCC optimize(3,"Ofast","inline") //G++
#include
#define TEST freopen("C:\\Users\\hp\\Desktop\\ACM\\in.txt","r",stdin);
#define mem(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << ": " << x << endl;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fcout cout<
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll INF=0x7fffffffffffffff;
const int mod=1e9+7;
const int maxn = 1e6+5;
const double eps=1e-8;
template<typename T> void read(T &x) {
x = 0;
char ch = getchar();
ll f = 1;
while(!isdigit(ch)) {
if(ch == '-')f*=-1;
ch=getchar();
}
while(isdigit(ch)) {
x = x*10+ch-48;
ch=getchar();
}
x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
read(first);
read(args...);
}
int sgn(double a) {
return a<-eps?-1:a<eps?0:1;
}
inline int add(int x,int y) {
return x+y>=mod?x+y-mod:x+y;
}
inline int sub(int x,int y) {
return x-y<0?x-y+mod:x-y;
}
inline int mul(int x,int y) {
return 1ll*x*y%mod;
}
inline int sq(int x) {
return 1ll*x*x%mod;
}
int pow(int a,int b) {
return b == 0?1:( b&1?mul(a,sq(pow(a,b/2))):sq(pow(a,b/2)));
}
char s[maxn];
int cnt[2];
stack<char>st;
int main(){
int n;
cin>>n;
cin>>s+1;
for(int i=1;i<=n;i++){
if(s[i]=='(') cnt[0]++;
else cnt[1]++;
}
if(cnt[0]!=cnt[1]){
cout<<"-1\n";
return 0;
}
cnt[0]=cnt[1]=0;
int sum=0,pre=0;
int ans=0;
for(int i=1;i<=n;i++){
if(s[i]=='('){
sum++;
cnt[0]++;
}
else{
sum--;
cnt[1]++;
}
pre=min(sum,pre);
if(sum==0&&pre==0&&cnt[0]==cnt[1]){
cnt[0]=cnt[1]=0;
}
if(pre<0&&cnt[0]==cnt[1]&&sum==0){
ans+=cnt[0]*2;
cnt[0]=cnt[1]=pre=0;
}
}
cout<<ans<<"\n";
}