寒假习题集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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值