Pro2
原始文件为 CPP 代码,本文是转换后的 Markdown 文件。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
const int maxn = 2005;
const int maxtime = 1000005;
bool atime[maxtime];
bool btime[maxtime];
int main()
{
//freopen("in.txt","r",stdin);
memset(atime,false,sizeof(atime));
memset(btime,false,sizeof(btime));
int n,s,t;
int uppertime = 0;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%d%d",&s,&t);
if (t > uppertime) uppertime = t;
atime[s] = true;
while(++s < t)
atime[s] = true;
}
for (int i = 0; i < n; ++i)
{
scanf("%d%d",&s,&t);
if (t > uppertime) uppertime = t;
btime[s] = true;
while(++s < t)
btime[s] = true;
}
int ans = 0;
for (int i = 1; i <= uppertime; ++i)
{
if (atime[i] && btime[i])
++ans;
}
printf("%d\n",ans);
}