[洛谷] P1276 校门外的树(增强版)
程序员文章站
2022-07-13 11:30:49
...
暴力模拟
//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
int arr[MAXN] = {0};
bool rein[MAXN] = {0};
int main()
{
int n, t, retin = 0;
cin>>n>>t;
for(int i = 0; i <= n; i++)
arr[i] = 1;
while(t--)
{
int mode, a, b;
cin>>mode>>a>>b;
if(mode == 0)
{
for(int i = a; i <= b; i++)
{
if(rein[i] == true && arr[i] == 1)
retin++;
else
rein[i] = true;
arr[i] = 0;
}
}
else
{
for(int i = a; i <= b; i++)
{
arr[i] = 1;
}
}
}
ll sum = 0;
for(int i = 0; i <= n; i++)
{
if(rein[i] && arr[i])
sum ++;
}
cout<<sum<<endl;
cout<<retin<<endl;
return 0;
}
上一篇: 线段树专题