差分的进一步应用
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int N = 10010;
typedef pair<int,int> pp;
int b[N];
set<pp> chk;
int n,p,h,m;
void ins(int l,int r,int num){
b[l] += num;
b[r + 1] -= num;
}
int main(){
cin >> n >> p >> h >> m;
b[1] = h;
for(int i = 1;i <= m;i ++){
int a,b;
cin >> a >> b;
if(a > b) swap(a,b);
if(chk.count({a,b})) continue;
chk.insert({a,b});
ins(a + 1,b - 1,-1);
}
for(int i = 1;i <= n;i ++){
b[i] += b[i - 1];
cout << b[i] << endl;
}
}
岛
#include<iostream>
#include<map>
using namespace std;
const int N = 100010;
int n;
int h[N];
map<int,int> b;
int main(){
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> h[i];
//i = 1的时候把最大的一块算好了
//出现新的一块那么淹没比他小的任何一块都会出现一个新的岛,所以 + 1
if(h[i] > h[i - 1]){
b[h[i - 1]] ++;
b[h[i]] --;
}
}
int res = 0,t = 0;
for(auto i : b){
t += i.second;
res = max(res,t);
}
cout << res;
}