寒假习题集2

接上
DAY5 天天在家里好无聊喔
E. 完美数(真因子的和等于本身的数字)打表
F.扫描线模板题


#include<iostream>
#include<algorithm>
#define lson (id<<1)
#define rson (id<<1|1)
using namespace std;
int n,tot;
const int maxn = 1000005;
int X[maxn << 1];
struct ScanLine {
 long long l, r, h;
 int mark;
 bool operator<(const ScanLine &b) const {
  return b.h >  h;
 }
}line[maxn<<1];
struct SegTree {
 int l, r, sum, len;
} tree[maxn << 2];
void build(int id,int l, int r) {
 tree[id].l = l;
 tree[id].r = r;
 tree[id].len = 0;
 tree[id].sum = 0;
 if (l == r) return;
 int mid = (l + r) >> 1;
 build(lson, l, mid);
 build(rson,mid + 1, r);
}
void pushup(int id) {
 int l = tree[id].l;
 int r = tree[id].r;
 if (tree[id].sum) {
  tree[id].len = X[r + 1] - X[l];
 }
 else {
  tree[id].len = tree[lson].len + tree[rson].len;
 }
}
void edit(int id,long long L,long long R,int c) {
 int l = tree[id].l;
 int r = tree[id].r;
 if (X[r + 1] <= L || R <= X[l]) {
  return;
 }
 if (L <= X[l] && X[r + 1] <= R) {
  tree[id].sum += c;
  pushup(id);
  return;
 }
 edit(lson, L, R, c);
 edit(rson, L, R, c);
 pushup(id);
}
int main() {
 cin >> n;
 for (int i = 1;i <= n;i++) {
  int ax, ay, bx, by;
  cin >> ax >> ay >> bx >> by;
  X[2 * i - 1] = ax;
  X[2 * i] = bx;
  ScanLine s;
  s.l = ax;s.r = bx;
  s.h = ay;s.mark = 1;
  line[2 * i - 1] = s;
  s.h = by; s.mark = -1;
  line[2 * i] = s;
 }
 n <<= 1;
 sort(line + 1, line + n + 1);
 sort(X + 1, X + 1 + n);
 tot = unique(X + 1, X + n + 1) - X - 1;
 build(1, 1, tot - 1);
 long long ans = 0;
 for (int i = 1;i < n;i++) {
  edit(1,line[i].l,line[i].r,line[i].mark);
  ans += tree[1].len*(line[i + 1].h - line[i].h);
 }
 cout << ans << endl;
 return 0;
}

很好 今天满地找锅的时候发现 原来cmath库里有y1定义过了(谜之变量名

#include<iostream>
#include<map>
#include<set>
using namespace std;
int c, p, s,cnt;
string People[50005];
set<string> people;
map<string, int> Problem,tot;
int main() {
 cin >> c >> p >> s;
 for (int i = 1;i <= c;i++) {
  string ss;
  cin >> ss;
  People[++cnt] = ss;
  people.insert(ss);
 }
 for (int i = 1;i <= p;i++) {
  string ss;
  int x;
  cin >> ss >> x;
  Problem[ss] = x;
 }
 for (int i = 1;i <= s;i++) {
  string person, problem, status;
  cin >> person >> problem >> status;
  if (status == "AC") {
   if (people.count(person) && Problem[problem]!= 0) {
    tot[person] += Problem[problem];
   }
  }
 }
 for (int i = 1;i <= cnt;i++) {
  cout << People[i] << " " << tot[People[i]] << endl;
 }
 return 0;
}
发布了24 篇原创文章 · 获赞 2 · 访问量 956

猜你喜欢

转载自blog.csdn.net/weixin_43521836/article/details/104112776