Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A 、B
这个是个人日常训练记录
A-Math Problem
给你\(n\)组边界,让你求能包含每个边界相交部分的
#include <iostream>
#include <cstdio>
using namespace std;
int t, l, r, n;
int main() {
scanf("%d", &t);
while(t --) {
scanf("%d", &n);
int a = 0, b = 0x3f3f3f3f;
for(int i = 0; i < n; i++) {
scanf("%d%d", &l, &r);
a = max(l, a); b = min(b, r);
}
if(a < b) puts("0");
else printf("%d\n", a - b);
}
return 0;
}
B-Box
构造题,不多写了
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[N], n, t;
int ans[N], idx;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> t;
while(t --) {
set<int> se;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
se.insert(i);
}
int maxn = -1; bool f = 0;
for(int i = 1; i <= n; i++) {
if(a[i] > maxn) {
maxn = a[i];
se.erase(a[i]);
ans[++idx] = a[i];
} else if(se.size()) {
auto p = se.begin();
if(maxn > *p) {
ans[++idx] = *p;
se.erase(p);
} else {
f = 1; break;
}
} else {
f = 1; break;
}
}
if(f) cout << "-1";
else for(int i = 1; i <= idx; i++) cout << ans[i] << ' ';
cout << '\n';
while(idx) ans[idx--] = 0;
}
return 0;
}