zoukankan      html  css  js  c++  java
  • [CF816B] Karen and Coffee(前缀和,思维)

    题目链接:http://codeforces.com/contest/816/problem/B

    题意:一个大区间被n条线覆盖,接下来有q次询问,询问[l,r]内有多少个点被>=k个线覆盖。

    区间两头左闭右开打标记,左边+1右边-1,维护这个标记的前缀和,再维护一个前缀和,找到上一个前缀和里>=k的点,更新到当前的前缀和里就是了。 
     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <climits>
     6 #include <complex>
     7 #include <cassert>
     8 #include <cstdio>
     9 #include <bitset>
    10 #include <vector>
    11 #include <deque>
    12 #include <queue>
    13 #include <stack>
    14 #include <ctime>
    15 #include <set>
    16 #include <map>
    17 #include <cmath>
    18 using namespace std;
    19 #define fr first
    20 #define sc second
    21 #define cl clear
    22 #define BUG puts("here!!!")
    23 #define W(a) while(a--)
    24 #define pb(a) push_back(a)
    25 #define Rint(a) scanf("%d", &a)
    26 #define Rll(a) scanf("%lld", &a)
    27 #define Rs(a) scanf("%s", a)
    28 #define Cin(a) cin >> a
    29 #define FRead() freopen("in", "r", stdin)
    30 #define FWrite() freopen("out", "w", stdout)
    31 #define Rep(i, len) for(int i = 0; i < (len); i++)
    32 #define For(i, a, len) for(int i = (a); i < (len); i++)
    33 #define Cls(a) memset((a), 0, sizeof(a))
    34 #define Clr(a, x) memset((a), (x), sizeof(a))
    35 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
    36 #define lrt rt << 1
    37 #define rrt rt << 1 | 1
    38 #define pi 3.14159265359
    39 #define RT return
    40 #define lowbit(x) x & (-x)
    41 #define onenum(x) __builtin_popcount(x)
    42 typedef long long LL;
    43 typedef long double LD;
    44 typedef unsigned long long ULL;
    45 typedef pair<int, int> pii;
    46 typedef pair<string, int> psi;
    47 typedef pair<LL, LL> pll;
    48 typedef map<string, int> msi;
    49 typedef vector<int> vi;
    50 typedef vector<LL> vl;
    51 typedef vector<vl> vvl;
    52 typedef vector<bool> vb;
    53 
    54 const int maxn = 200200;
    55 int n, k, q;
    56 int line[maxn];
    57 int sum[maxn];
    58 
    59 signed main() {
    60     // FRead();
    61     int x, y;
    62     while(~Rint(n)) {
    63         Rint(k); Rint(q);
    64         Cls(line); Cls(sum);
    65         Rep(i, n) {
    66             Rint(x); Rint(y);
    67             line[x]++; line[y+1]--;
    68         }
    69         For(i, 1, 200020) {
    70             line[i] += line[i-1];
    71             if(line[i] >= k) sum[i] = sum[i-1] + 1;
    72             else sum[i] = sum[i-1];
    73         }
    74         W(q) {
    75             Rint(x); Rint(y);
    76             printf("%d
    ", sum[y]-sum[x-1]);
    77         }
    78     }
    79     RT 0;
    80 }
  • 相关阅读:
    算数基本定理与质因数分解
    质数的两种筛法
    质数及其判法
    二十二、Spring MVC与Structs2的区别总结
    二十一、MVC的WEB框架(Spring MVC)
    二十、MVC的WEB框架(Spring MVC)
    十九、Spring框架(注解方式测试)
    十八、Spring框架(AOP)
    十七、Spring框架(IOC/DI)
    创建型模式篇(建造者模式Builder Pattern)
  • 原文地址:https://www.cnblogs.com/kirai/p/7043915.html
Copyright © 2011-2022 走看看