跳到正文

个人记录

T616437 校门外的树

rgjjy约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

题目

T616437 校门外的树

错误原因:

没找出错误原因

思路

1.输入
2.while
3.if a[i]的值是奇数
4.a[i]++,ans1++
5.if a[i]的值是偶数
6.a[i]++
7.for
8.if ans2++
9.输出ans2和ans1-ans2

正确代码

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n,k,a[N],ans1,ans2,opt,l,r;
int main()
{
	cin>>n>>k;
	while(k--)
	{
		cin>>opt>>l>>r;//输入
		for(int i=l;i<=r;i++)
		{
			if(a[i]%2==1 && opt==1)
			{
				//奇数
				a[i]++;
				ans1++;
			}
			else if(a[i]%2==0 && opt==0)
			{
				//偶数
				a[i]++;
			}
		}
	}
	for(int i=0;i<=n;i++)
	{
		if(a[i]%2==0 && a[i]!=0)
		{
			ans2++;
		}
	}
	cout<<ans2<<endl<<ans1-ans2;
	return 0;
}
原文