2019 Multi-University Training Contest 9
2019-08-20 / Luo Jinrong   

进度

A B C D E F G H I J K

1002. Rikka with Cake

题意

一个$n\times m$的蛋糕,有$k$条射线,求这个蛋糕被分成几块。

做法

离散化+树状数组。求这$k$条射线的交点数,答案即为交点数+1。

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define per(i,a,n) for (int i=a;i<n;i++)
#define rep(i,a,n) for (int i=n-1;i>=a;i--)

const int MAXN(5e5+7);
int T;
ll n, m, x, y;
ll posh, poss, pos, K, cntx, cnty;
char Dir[] = {'L', 'R', 'U', 'D'}, Dd;
struct nd{
ll x, y;
ll D;
}hln[MAXN], sln[MAXN];
ll hashx[MAXN], hashy[MAXN];
ll outt;

inline ll Lowbit(ll k) { return (k&-k); }

ll sizze;
struct Ln {
ll c[MAXN];
inline void init() {
per(i, 0, sizze+1) c[i]=0;
}
inline void update(ll _pos) {
while (_pos <= sizze) { //注意这里
c[_pos] += 1ll;
_pos += Lowbit(_pos);
}
}
inline ll sum(ll _pos) {
ll s = 0;
while (_pos > 0) {
s += c[_pos];
_pos -= Lowbit(_pos);
}
return s;
}
}LT, RT;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

cin >> T;
while(T--) {
outt = posh = poss = outt = cntx = cnty = 1;
cin >> n >> m >> K;
per(i, 1, K+1) {
cin >> x >> y >> Dd;
hashx[cntx++] = x;
hashy[cnty++] = y;
per(j, 0, 4) {
if(Dd==Dir[j]) {
if(j<2) {
hln[posh].D = j;
hln[posh].x = x;
hln[posh++].y = y;
} else {
sln[poss].D = j;
sln[poss].x = x;
sln[poss++].y = y;
}
break;
}
}
}

//离散化
sort(hashx+1, hashx+cntx);
sort(hashy+1, hashy+cnty);
cntx = unique(hashx+1, hashx+cntx)-hashx;
cnty = unique(hashy+1, hashy+cnty)-hashy;
per(i, 1, poss) {
sln[i].x = lower_bound(hashx+1, hashx+cntx, sln[i].x)-hashx;
sln[i].y = lower_bound(hashy+1, hashy+cnty, sln[i].y)-hashy;
}
per(i, 1, posh) {
hln[i].x = lower_bound(hashx+1, hashx+cntx, hln[i].x)-hashx;
hln[i].y = lower_bound(hashy+1, hashy+cnty, hln[i].y)-hashy;
}
//离散化完成

sizze = cntx;
pos = poss;
sort(sln+1, sln+poss, [](const nd& a, const nd& b) {return a.D==b.D?a.y>b.y:a.D<b.D;});
//向上线处理
LT.init();
RT.init();
//对横向线从上到下排序
int tmph=1;
ll lx=0, rx=cntx, tmpy=cnty;
sort(hln+1, hln+posh, [](const nd& a, const nd& b){return a.y>b.y;});
per(i, 1, poss) {
if(sln[i].D==3) {
pos = i;
break;
}
while(tmph<posh && hln[tmph].y>=sln[i].y) {
//判断是否还在上一个一行
if(hln[tmph].y==tmpy) {
if(!hln[tmph].D) {
lx = max(lx, hln[tmph].x);
} else {
rx = min(rx, hln[tmph].x);
}
} else {
if(lx>=rx) {
lx = 0;
rx = 1;
}
//处理树状数组
if(lx) LT.update(lx);
if(rx<cntx) RT.update(rx);
tmpy=hln[tmph].y, lx=0, rx=cntx;
if(!hln[tmph].D) {
lx = hln[tmph].x;
} else {
rx = hln[tmph].x;
}
}
tmph++;
}
if(tmpy>=sln[i].y) {
if(lx>=rx) {
lx = 0;
rx = 1;
}
//处理树状数组
if(lx) LT.update(lx);
if(rx<cntx) RT.update(rx);
if(tmph<posh) {
tmpy=hln[tmph].y, lx=0, rx=cntx;
if (!hln[tmph].D) {
lx = hln[tmph].x;
} else {
rx = hln[tmph].x;
}
} else {
tmpy=0;
}
}
//判断穿过多少条线
outt += (LT.sum(sizze)-LT.sum(sln[i].x-1));
outt += RT.sum(sln[i].x);
}
//向下线处理
LT.init();
RT.init();
tmph=1, lx=0, rx=cntx;
tmpy=0;
sort(hln+1, hln+posh, [](const nd& a, const nd& b){return a.y<b.y;});
rep(i, pos, poss) {
while(tmph<posh && hln[tmph].y<=sln[i].y) {
//判断是否还在上一个一行
if(hln[tmph].y==tmpy) {
if(!hln[tmph].D) {
lx = max(lx, hln[tmph].x);
} else {
rx = min(rx, hln[tmph].x);
}
} else {
if(lx>=rx) {
lx = 0;
rx = 1;
}
//处理树状数组
if(lx) LT.update(lx);
if(rx<cntx) RT.update(rx);
tmpy=hln[tmph].y, lx=0, rx=cntx;
if(!hln[tmph].D) {
lx = hln[tmph].x;
} else {
rx = hln[tmph].x;
}
}
tmph++;
}
if(tmpy<=sln[i].y) {
if(lx>=rx) {
lx = 0;
rx = 1;
}
//处理树状数组
if(lx) LT.update(lx);
if(rx<cntx) RT.update(rx);
if(tmph<posh) {
tmpy=hln[tmph].y, lx=0, rx=cntx;
if (!hln[tmph].D) {
lx = hln[tmph].x;
} else {
rx = hln[tmph].x;
}
} else {
tmpy = cnty;
}
}
//判断穿过多少条线
outt += (LT.sum(sizze)-LT.sum(sln[i].x-1));
outt += RT.sum(sln[i].x);
}
cout << outt << endl;
}

return 0;
}

1005. Rikka with Game

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
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define upf(a,b,c) for(int a=b;a<=c;++a)
#define drf(a,b,c) for(int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define Tcase(n) for(int _=1;_<=n;++_)
#define ll long long
#define ull unsigned long long
#define ShaShiBuGan bool woyebuzhidaogaiganmasuoyishenmedoubugan=false;
const ll mod(1e9);
const int maxn(105);
const ll INF(0x3fffffffff);
const double sfive(sqrt(5));
using namespace std;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int T;
int n, m, x, y, k;
char s[maxn * 3];
ll dp[maxn];
ll mp[maxn][maxn], num[maxn], marked[maxn];

int main() {
#ifdef ACM_LOCAL
freopen("./ACM.in", "r", stdin);
freopen("./ACM.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
Tcase(T) {
cin >> s;
int length = strlen(s);
upf(i, 0, length - 1) {
if (s[i] != 'y') {
if (s[i] == 'z')
s[i] = 'b';
break;
}
}
cout << s << endl;
}
}

return 0;


本文链接:
https://luojinrong.github.io/2019/08/20/2019-Multi-University-Training-Contest-9/