题解 P3740 【[HAOI2014]贴海报】
我非常喜欢暴力的数据结构,所以我用暴力A了这道题
//Code by : Y-k-y
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#define ll long long
const int N=10000010;
using namespace std;
inline int read()
{
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
return res*f;
}
inline void wr(int x)
{
if(x<0){putchar('-');x=-x;}
if(x>9) wr(x/10);putchar(x%10+'0');
}
int n,m,x,y;
int a[N],t[N];//原数组、桶
int main()
{
n=read();m=read();
for(int i=1;i<=m;i++)
{
x=read();y=read();
for(int j=x;j<=y;j++)//直接修改
a[j]=i;
}
t[0]=1;//防止不贴时也加上
int num=0;//计数
for(int i=1;i<=n;i++)
{
if(!t[a[i]]){//如果没出现过这种颜色,++
num++;
t[a[i]]=1;
}
}
wr(num);//快输
return 0;
}
完结散花