Tallest Cow

每次询问,所给的条件为
A B
条件1:h[A] <= h[B]
条件2:同时h[A]>= hi
为了让高度尽可能地高,我们让每头牛的身高都为最大值。
然后,我们按照题目所给信息,来给牛降低身高。
显然,我们只需要对条件2进行操作就好了。
这里使用差分数组。

/*
 *@author SunLakeWalk
 */
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits.h>
#include <sstream>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inlin")

using namespace std;

#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 10010, INF = 0x3f3f3f3f, mod = 1e9 + 7, base = 131;
const double eps = 1e-6, PI = acos(-1);

//直接差分数组就ok了
int n, x, y, Q;
int b[N];
unordered_map<int, int> h[N];

void add(int l, int r) {
  // b[l] --;
  // b[r + 1] ++;
  b[l + 1] --;
  b[r] ++;
}

void work() {
  ios; cin >> n >> x >> y >> Q;

  b[1] = y;
  while (Q -- ) {
    int x, y; cin >> x >> y;
    if (x > y) swap(x, y);
    if (h[x][y]) continue;
    h[x][y] ++;
    if (x + 1 <= y) add(x, y);
  }

  for (int i = 1; i <= n; i ++ ) {
    b[i] += b[i - 1];
    cout << b[i] << endl;
  }
}

int main() {

  work();

  return 0;
}
全部评论

相关推荐

2025年10月3日中午,在写完定时一年后发给自己的信之后,敲下键盘,写下这篇文字。我把标题的“所有人”加了引号,因为如我们所见,确实有的人顺风顺水,每天过的很开心,或是早早进入大厂,或是年纪轻轻就拿到了高薪offer,或是过着可能我努力十年也不一定实现的生活。但也许,不是每个人的痛苦都能被别人看到的,这个月我经常会哭,被骗6000块钱、手上钱不够导致拖欠房租、生活还要借朋友钱、国庆长假也没有钱去旅游,互联网公司不稳定担心试用期不过(毕竟上段实习就是被裁了,一有点风吹草动就害怕),但这样的我,不是所有人都知道的,居然是有些朋友的羡慕对象。回忆我的七年“长跑”别人都是多年幸福的恋爱长跑,我没有恋...
故事和酒66:让每一颗种子找到合适自己的生长方式,最终绽放出独一无二的花朵,这远比所有人都被迫长成同一棵“参天大树”的世界,更加美好和富有生机。这是社会和环境的问题,而不是我们的问题。然而就是在这样的环境中,楼主依然能突破自我,逆势成长,其中的艰辛可想而知。这一路的苦难终究会化作你成长的养料
你小时候最想从事什么职业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务