省选模拟 19/10/07
Posted qq62c30ac77b2a7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了省选模拟 19/10/07相关的知识,希望对你有一定的参考价值。
CF793G Oleg and chess 首先暴力就是个二分图匹配,行向列连边
想到了线段树优化建图
于是有一种做法是先扫描线,然后每一列的线段树暴力连边
考虑到每一次只会有一段区间被修改,于是类似主席树一样
对于修改的节点我们行建一个点向下连边
然后就是 的模板
#include<bits/stdc++.h>
#define N 40050
#define M 4000050
using namespace std;
int read()
int cnt = 0, f = 1; char ch = 0;
while(!isdigit(ch)) ch = getchar(); if(ch == -) f = 0;
while(isdigit(ch)) cnt = (cnt + (cnt << 2) << 1) + (ch ^ 48), ch = getchar();
return f ? cnt : -cnt;
const int inf = 1e9;
struct opt int x, l, r, f;;
vector<opt> v[N];
int n, m, st, ed, node;
int first[M], f2[M], nxt[M], to[M], w[M], tot = 1;
void add(int x, int y, int z)
nxt[++tot] = first[x], first[x] = tot, to[tot] = y, w[tot] = z;
nxt[++tot] = first[y], first[y] = tot, to[tot] = x, w[tot] = 0;
struct SGT
int pos[M], cov[N];
void pushup(int x)
pos[x] = ++node;
if(!cov[x<<1]) add(pos[x], pos[x<<1], inf);
if(!cov[x<<1|1]) add(pos[x], pos[x<<1|1], inf);
void build(int x, int l, int r)
if(l == r) pos[x] = n + l; return;
int mid = (l+r) >> 1; build(x<<1, l, mid); build(x<<1|1, mid+1, r);
pushup(x);
void modify(int x, int l, int r, int L, int R, int k)
if(L<=l && r<=R) cov[x] += k; return;
int mid = (l+r) >> 1;
if(L<=mid) modify(x<<1, l, mid, L, R, k);
if(R>mid) modify(x<<1|1, mid+1, r, L, R, k);
pushup(x);
Seg;
int dis[M];
bool bfs()
queue<int> q; q.push(st);
memset(dis, -1, sizeof(int)*(node+1)); dis[st] = 0;
while(!q.empty())
int x = q.front(); q.pop();
for(int i = first[x]; i; i = nxt[i])
int t = to[i]; if(w[i] && dis[省选模拟27