Luogu3740 [HAOI2014]贴海报 (线段树)
Posted bingoyes
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Luogu3740 [HAOI2014]贴海报 (线段树)相关的知识,希望对你有一定的参考价值。
倒着来
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\\n\\n----------\\n\\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios
template<typename ATP>ios& operator >> (ATP &x)
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
io;
using namespace std;
const int N = 1007;
struct Post
int l, r;
a[N];
int flag;
int t[40000003];
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
inline void Pushup(int rt)
t[rt] = t[rt << 1] && t[rt << 1 | 1];
inline void Updata(int rt, int l, int r, int L, int R)
if(t[rt]) return;
if(L <= l && r <= R)
t[rt] = 1;
flag = 1;
return;
int mid = (l + r) >> 1;
if(L <= mid)
Updata(lson, L, R);
if(R > mid)
Updata(rson, L, R);
Pushup(rt);
int main()
int LEN ,n;
io >> LEN >> n;
R(i,1,n)
io >> a[i].l >> a[i].r;
int ans = 0;
nR(i,n,1)
flag = 0;
Updata(1, 1, LEN, a[i].l, a[i].r);
ans += flag;
printf("%d", ans);
return 0;
以上是关于Luogu3740 [HAOI2014]贴海报 (线段树)的主要内容,如果未能解决你的问题,请参考以下文章