2019 中山大学程序设计竞赛

rank solved A B C D E F G H I J K
23 6 . O . O O . . O O . O

B Triangle

Solved by wb(+2).

长度很长时一定存在。

D Monitor

Solved by wb and XLor(+3).

总体大小很小,一维数组模拟二维。

第一次差分搞出每个位置的出现次数,第二次差分搞出每个前缀矩形的被覆盖点数。

E Coding Problem

Solved by XLor(+3).

模拟。

G Clumsy Keke

Solved by wb.

三维枚举一下。

H Enlarge it

Solved by XLor.

模拟。

K Party

Solved by XLor.

每个位置配对到的位置是左右一段连续区间,对每个点维护一下左右端点的范围。

询问时,每次统计将区间内的点的区间扩大了的数量,这是答案的两倍,加一个剪枝。

询问后做区间覆盖。

代码

B

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define forsaken
#ifdef forsaken
#define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
#define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int max_n=5000005;
namespace {
inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
inline int Mul(int x,int y) {return 1ll*x*y%mod;}
inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int a[max_n];
int n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)scanf("%d",a+i);
if(n>=100000)printf("YES\n");
else
{
sort(a+1,a+n+1);
bool f=false;
for(int i=1;i+2<=n;i++)if(1ll*a[i]+a[i+1]>a[i+2])f=true;
if(f)printf("YES\n");
else printf("NO\n");
}
}
return 0;
}

D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#ifdef XLor
#define dbg(args...) do {cout << #args << " -> "; err(args);} while (0)
#else
#define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 2000000 + 5;

int n, m, p, q;
int a[maxn * 10];

int getid(int i, int j) {
return i * m + j;
}

int main() {
while (scanf("%d%d", &n, &m) == 2) {
scanf("%d", &p);
for (int i = 1; i <= p; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
a[getid(x1, y1)]++;
a[getid(x1, y2 + 1)]--;
a[getid(x2 + 1, y1)]--;
a[getid(x2 + 1, y2 + 1)]++;
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
a[getid(i, j)] += -a[getid(i - 1, j - 1)] + a[getid(i - 1, j)] + a[getid(i, j - 1)];
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
if (a[getid(i, j)] > 0) a[getid(i, j)] = 1;
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) {
a[getid(i, j)] += -a[getid(i - 1, j - 1)] + a[getid(i - 1, j)] + a[getid(i, j - 1)];
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= m; j++) {
// printf("%d ", a[getid(i, j)]);
// }
// puts("");
// }
scanf("%d", &q);
for (int i = 1; i <= q; i++) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int sum = a[getid(x2, y2)] + a[getid(x1 - 1, y1 - 1)] - a[getid(x1 - 1, y2)] - a[getid(x2, y1 - 1)];
dbg(sum);
if (sum == (x2 - x1 + 1) * (y2 - y1 + 1)) {
puts("YES");
} else {
puts("NO");
}
}
ms(a, 0);
// for (int i = 0; i <= (n + 1) * m; i++) a[i] = 0;
}
return 0;
}

E

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 300000 + 5;

char s[maxn], t[100 * maxn];

int main() {
cin >> s;
vector<int> v;
int tot = 0, n = strlen(s);
for (int i = 0; i < n; i++) {
int x = (int)s[i];
for (int i = 0; i < 8; i++) {
t[tot++] = (x >> i & 1) + '0';
}
}
for (int i = 0; i < tot; i += 6) {
int x = 0;
for (int j = i; j < i + 6; j++) {
x = x * 2 + (t[j] - '0');
}
// if (i) putchar(' ');
printf("%d ", x);
}
// puts("");
return 0;
}

H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=105;
int x,y,z;
bool a[max_n][max_n],b[max_n][max_n],c[max_n][max_n];
int main()
{
while(~scanf("%d%d%d",&x,&y,&z))
{
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=y;i++)
{
for(int j=1;j<=z;j++)
{
scanf("%d",&b[i][j]);
}
}
for(int i=1;i<=z;i++)
{
for(int j=1;j<=x;j++)
{
scanf("%d",&c[i][j]);
}
}
int ans=0;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
for(int k=1;k<=z;k++)
{
if(a[i][j]&&b[j][k]&&c[k][i])ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}

I

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 2000 + 5;

int n, m, k;
char s[maxn][maxn], ans[maxn][maxn];

int main() {
while (scanf("%d%d%d", &n, &m, &k) == 3) {
for (int i = 0; i < n; i++) scanf("%s", s[i]);
for (int i = 0; i < k * n; i++) {
for (int j = 0; j < k * m; j++) {
putchar(s[i / k][j / k]);
}
puts("");
}
}
return 0;
}

K

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#ifdef XLor
#define dbg(args...) do {cout << #args << " -> "; err(args);} while (0)
#else
#define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 500000 + 5;

int n, m;

int ll[maxn << 2], rr[maxn << 2], tagl[maxn << 2], tagr[maxn << 2], chk[maxn << 2];
void pushdown(int rt) {
int l = tagl[rt], r = tagr[rt];
if (tagl[rt]) {
if (l < ll[rt << 1]) {
ll[rt << 1] = tagl[rt << 1] = l;
}
if (l < ll[rt << 1 | 1]) {
ll[rt << 1 | 1] = tagl[rt << 1 | 1] = l;
}
}
if (tagr[rt]) {
if (r > rr[rt << 1]) {
rr[rt << 1] = tagr[rt << 1] = r;
}
if (r > rr[rt << 1 | 1]) {
rr[rt << 1 | 1] = tagr[rt << 1 | 1] = r;
}
}
tagl[rt] = tagr[rt] = 0;
}
void pushup(int rt) {
ll[rt] = min(ll[rt << 1], ll[rt << 1 | 1]);
rr[rt] = max(rr[rt << 1], rr[rt << 1 | 1]);
}
void build(int l, int r, int rt) {
tagl[rt] = tagr[rt] = chk[rt] = 0;
ll[rt] = n + 1; rr[rt] = 0;
if (l == r) {
chk[rt] = 1;
ll[rt] = rr[rt] = l; return ;
}
int m = (l + r) / 2;
build(lson); build(rson);
// pushup(rt);
}
void update(int L, int R, int l, int r, int rt) {
if (L <= l && r <= R) {
if (L < ll[rt]) {
ll[rt] = tagl[rt] = L;
}
if (R > rr[rt]) {
rr[rt] = tagr[rt] = R;
}
return ;
}
int m = (l + r) / 2; pushdown(rt);
if (L <= m) update(L, R, lson);
if (R > m) update(L, R, rson);
// pushup(rt);
}
LL query(int L, int R, int l, int r, int rt) {
if (l == r) {
// dbg(l, r, ll[rt], rr[rt]);
return max(R - rr[rt], 0) + max(ll[rt] - L, 0);
}
if (R <= rr[rt] && L >= ll[rt]) return 0;
int m = (l + r) / 2;
// dbg(l, r, ll[rt], rr[rt], tagl[rt], tagr[rt]);
pushdown(rt);
LL ans = 0;
if (L <= m) ans += query(L, R, lson);
if (R > m) ans += query(L, R, rson);
return ans;
}

int main() {
while (scanf("%d%d", &n, &m) == 2) {
build(1, n, 1);
for (int i = 1, l, r; i <= m; i++) {
scanf("%d%d", &l, &r);
LL sum = query(l, r, 1, n, 1);
printf("%lld\n", sum / 2ll);
update(l, r, 1, n, 1);
}
// puts("?");
}
return 0;
}