HGOI 20200724
T1 电话号码(phone)
水题
把数字变成X,字母变成Y,然后直接塞map搞就完事
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define siz(a) (int)a.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
const int N = 100010 ;
int m, n ;
string s ;
map <string, int> occ ;
string work(string s) {
int len = siz(s) ;
rep(i, 0, len - 1) {
if (isdigit(s[i])) s[i] = 'x' ;
else if (isalpha(s[i])) s[i] = 'y' ;
}
return s ;
}
signed main() {
// freopen("phone.in", "r", stdin) ;
// freopen("phone.out", "w", stdout) ;
scanf("%d%d\n", &m, &n) ;
rep(i, 1, m) {
getline(cin, s) ;
s = work(s) ;
occ[s] = 1 ;
}
rep(i, 1, n) {
getline(cin, s) ;
s = work(s) ;
puts(occ[s] ? "Yes" : "No") ;
}
return 0 ;
}
/*
4 4
555-555(0505)-555(1)
555 555(0505)-555(1)
(0505)555-555-555(1)
555(0505)-555(1)-555
246-110(1010)-111(1)
abc(abab)-aaa(1)
abc(abab)-aaa(1)-aaa
555 554(0505)-555(1)
*/
T2
CF1195E
两遍单调队列
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define siz(a) (int)a.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
const int iinf = 0x3f3f3f3f ;
const int N = 5010 ;
int n, m, a, b ;
int h[N][N] ;
int C[N][N];
ll ans ;
namespace READ {
int g[N * N] ;
int x, y, z ;
void read() {
scanf("%d%d%d%d", &n, &m, &a, &b) ;
scanf("%d%d%d%d", &g[0], &x, &y, &z) ;
rep(i, 1, n * m) g[i] = (1ll * g[i - 1] * x + y) % z ;
rep(i, 1, n)
rep(j, 1, m)
h[i][j] = g[(i - 1) * m + j - 1] ;
}
}
signed main() {
READ::read() ;
rep(i, 1, n) {
deque<pair<int, int> > Q;
rep(j, 1, m) {
while (!Q.empty() && Q.front().first + b <= j) Q.pop_front();
while (!Q.empty() && Q.back().second > h[i][j]) Q.pop_back();
Q.push_back({j, h[i][j]});
C[i][j] = Q.front().second;
}
}
per(j, m, b) {
deque<pair<int, int> > Q;
rep(i, 1, n) {
while (!Q.empty() && Q.front().first + a <= i) Q.pop_front();
while (!Q.empty() && Q.back().second > C[i][j]) Q.pop_back();
Q.push_back({i, C[i][j]});
if (i >= a) ans += Q.front().second;
}
}
printf("%lld\n", ans) ;
return 0 ;
}
T3 主星(stars)
Codeforces 708C
换根dp
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define siz(a) (int)a.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
const int N = 500010 ;
vector <int> e[N] ;
int head[N], sz[N], ans[N] ;
int msize[N] ;
int down[N] ;
int up[N] ;
int which[N] ;
int n, Cnt = 0, lim ;
void detect(int u,int ft) {
rep(i, 0, siz(e[u]) - 1) {
int v = e[u][i] ;
if(v != ft && sz[v] >= lim) {
which[u] = v ;
detect(v, u) ;
}
}
}
void dfs1(int u,int fa) {
msize[u] = sz[u] = down[u] = 1 ;
rep(i, 0, siz(e[u]) - 1) {
int v = e[u][i] ;
if (v == fa) continue ;
dfs1(v, u) ;
sz[u] += sz[v] ;
msize[u] = max(msize[u], sz[v]) ;
down[u] = max(down[u], down[v]) ;
}
if (sz[u] <= lim) down[u] = sz[u] ;
msize[u] = max(msize[u], n - sz[u]) ;
}
void dfs2(int u, int fa) {
pair<int, int> fir(0, 0), sec(0, 0) ;
rep(i, 0, siz(e[u]) - 1) {
int v = e[u][i] ;
if (v == fa) continue ;
if (down[v] > fir.first) {
swap(fir, sec) ;
fir = mp(down[v], v) ;
} else if (down[v] > sec.first) sec = mp(down[v], v) ;
}
rep(i, 0, siz(e[u]) - 1) {
int v = e[u][i] ;
if (v == fa) continue;
up[v] = max(up[u], v == fir.second ? sec.first : fir.first) ;
if ((n - sz[v]) <= lim) up[v] = max(up[v], n - sz[v]) ;
dfs2(v, u) ;
}
}
void getans(int u, int fa) {
int v ;
ans[u] = 0 ;
if (msize[u] <= lim) ans[u] = 1;
else {
if (which[u]) {
if (sz[which[u]] - down[which[u]] <= lim) ans[u] = 1;
}
else if ((n - sz[u] - up[u]) <= lim) ans[u] = 1;
}
rep(i, 0, siz(e[u]) - 1) {
v = e[u][i];
if (v == fa) continue ;
getans(v, u) ;
}
}
signed main() {
memset(up, 0, sizeof(up)) ;
memset(which, 0, sizeof(which)) ;
scanf("%d", &n) ;
rep(i, 1, n - 1) {
int u, v ; scanf("%d%d", &u, &v) ;
e[u].pb(v) ; e[v].pb(u) ;
}
lim = n / 2 ;
dfs1(1, 0) ;
detect(1, 0) ;
dfs2(1, 0) ;
getans(1, 0) ;
rep(i, 1, n) {
printf("%d", ans[i]) ;
if (i < n) printf(" ") ;
else printf("\n") ;
}
return 0 ;
}
加油ヾ(◍°∇°◍)ノ゙