每次询问,所给的条件为
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; }