2022.09.19 模拟赛小结(互测)
2022.09.19 模拟赛小结(互测)
题面
(这个链接只是为了自己方便找,页面设置权限了,不要尝试访问)
更好的阅读体验戳此进入
(建议您从上方链接进入我的个人网站查看此 Blog,在 Luogu 中图片会被墙掉,部分 Markdown 也会失效)
赛时思路
T1
写不出来,不会,寄。
Code
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
/******************************
abbr
******************************/
using namespace std;
mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
template<typename T = int>
inline T read(void);
int N, Q, K;
int a[210000];
bool ava[210000];
// int st[210000 << 4];
vector < int > buc[210000];
int cntT(0), cntF(0);
void Online(int &x){
x = ((x ^ ((cntF - cntT) * K)) % N + N) % N + 1;
// printf("x:%d\n", x);
}
// void Build(int p = 1, int l = 1, int r = N){
// }
int main(){
freopen("kfc.in", "r", stdin);
freopen("kfc.out", "w", stdout);
N = read(), Q = read(), K = read();
for(int i = 1; i <= N; ++i)a[i] = read();
for(int i = 1; i <= N; ++i){
ava[i] = read();
if(ava[i])buc[a[i]].push_back(i);
}
for(int q = 1; q <= Q; ++q){
int opt = read();
switch(opt){
case 1:{
int x = read(); Online(x);
if(ava[x])
buc[a[x]].erase(lower_bound(buc[a[x]].begin(), buc[a[x]].end(), x));
else
buc[a[x]].insert(lower_bound(buc[a[x]].begin(), buc[a[x]].end(), x), x);
ava[x] = !ava[x];
break;
}
case 2:{
int x = read(), to = read(); Online(x);
if(ava[x])
buc[a[x]].erase(lower_bound(buc[a[x]].begin(), buc[a[x]].end(), x));
ava[x] = true;
a[x] = to;
buc[a[x]].insert(lower_bound(buc[a[x]].begin(), buc[a[x]].end(), x), x);
break;
}
case 3:{
int l = read(), r = read(); Online(l), Online(r);
if(l > r)swap(l, r);
if(N <= 10000 && Q <= 10000){
bool flag(true);
int rcnt(0);
for(int p = l; p <= r; ++p){
if(!ava[p])continue;
if((int)buc[a[p]].size() > 1){
for(auto i : buc[a[p]]){
if(l <= i && i <= r)++rcnt;
if(rcnt > 1){flag = false; break;}
}
}
if(rcnt > 1)break;
}
if(flag)++cntT, printf("^_^\n");
else ++cntF, printf("TAT\n");
break;
}
bool flag(true);
int times(1000);
while(times--){
int p = rndd(l, r); int ttimes(3); while(!ava[p] && ttimes-- > 0)p = rndd(l, r);
if(!ava[p])continue;
int rcnt(0);
if((int)buc[a[p]].size() > 1){
for(auto i : buc[a[p]]){
if(l <= i && i <= r)++rcnt;
if(rcnt > 1){flag = false; break;}
}
}
if(!flag)break;
}
if(flag)++cntT, printf("^_^\n");
else ++cntF, printf("TAT\n");
break;
}
}
// for(int i = 1; i <= 4; ++i){
// printf("buc[%d]: ", i);
// for(auto j : buc[i])printf("%d ", j);
// printf("\n");
// }
}
fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
template<typename T>
inline T read(void){
T ret(0);
short flag(1);
char c = getchar();
while(c != '-' && !isdigit(c))c = getchar();
if(c == '-')flag = -1, c = getchar();
while(isdigit(c)){
ret *= 10;
ret += int(c - '0');
c = getchar();
}
ret *= flag;
return ret;
}
T2
试着推了一会,暴力 DP 推出来了,但是初始化寄了,$ 30\texttt{pts} \rightarrow 0\texttt{pts} $。
Code
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
/******************************
abbr
******************************/
using namespace std;
mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
#define int ll
template<typename T = int>
inline T read(void);
int N;
int a[11000];
int dp[11000] = {1};
bool cmp(int x, int y){
return (a[x] ^ y) < (x ^ a[y]);
}
signed main(){
freopen("butterfly.in", "r", stdin);
freopen("butterfly.out", "w", stdout);
N = read();
for(int i = 0; i <= N - 1; ++i)a[i] = read();
for(int i = 1; i <= N - 1; ++i){
for(int j = 0; j < i; ++j){
if(cmp(j, i))
dp[i] = max(dp[i], dp[j] + 1);
}
}
int ans(-1);
for(int i = 0; i <= N - 1; ++i)ans = max(ans, dp[i]);
printf("%lld\n", ans);
fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
template<typename T>
inline T read(void){
T ret(0);
short flag(1);
char c = getchar();
while(c != '-' && !isdigit(c))c = getchar();
if(c == '-')flag = -1, c = getchar();
while(isdigit(c)){
ret *= 10;
ret += int(c - '0');
c = getchar();
}
ret *= flag;
return ret;
}
T3
不知道是不是数据寄了,部分分也没拿到,大寄特寄。
Code
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
/******************************
abbr
******************************/
using namespace std;
mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
template<typename T = int>
inline T read(void);
struct Edge{
Edge* nxt;
int to;
int val;
void* operator new(size_t);
Edge(Edge* nxt, int to, int val):nxt(nxt), to(to), val(val){;}
Edge(void) = default;
}eData[210000];
void* Edge::operator new(size_t){static Edge* P = eData; return ++P;}
Edge* head[110000];
int N, K;
int deg[110000];
int cntDeg[110000];
namespace Case2{
int chain[110000];
int sum[110000];
int left(114514000), right(-1);
void MakeChain(void){
for(int i = 2; i <= N; ++i){
for(auto j = head[i]; j; j = j->nxt){
if(j->to == i - 1)chain[i - 1] = j->val, sum[i - 1] = sum[i - 2] + chain[i - 1];
}
}
}
void Make(void){
MakeChain();
for(int i = 1; i <= K; ++i){
int k = read();
left = min(left, k), right = max(right, k);
}
for(int i = 1; i <= left; ++i)printf("%d\n", sum[right - 1] - sum[i - 1]);
for(int i = left + 1; i <= right; ++i){
int l = sum[i - 1] - sum[left - 1];
int r = sum[right - 1] - sum[i - 1];
printf("%d\n", max(l, r) + min(l, r) * 2);
}
for(int i = right + 1; i <= N; ++i)printf("%d\n", sum[i - 1] - sum[left - 1]);
}
}
namespace Case3{
// int findHeav
void Make(void){
// for(int i = 1; i <= K; ++i)(void)read();
for(int i = 1; i <= N; ++i)printf("%d\n", rndd(1000, 100000000));
}
}
namespace Case1{
// bool todo[110000];
// int Search(Edge* p){
// }
// void Make(void){
// for(int i = 1; i <= K; ++i)todo[read()] = true;
// }
}
int main(){
freopen("show.in", "r", stdin);
freopen("show.out", "w", stdout);
N = read(), K = read();
for(int i = 1; i <= N - 1; ++i){
int f = read(), t = read(), v = read();
head[f] = new Edge(head[f], t, v);
head[t] = new Edge(head[t], f, v);
++deg[f], ++deg[t];
}
for(int i = 1; i <= N; ++i)cntDeg[deg[i]]++;
if(cntDeg[1] == 2 && cntDeg[2] == N - 2){
Case2::Make();
return 0;
}
if(K == N){
Case3::Make();
return 0;
}
Case3::Make();
fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
template<typename T>
inline T read(void){
T ret(0);
short flag(1);
char c = getchar();
while(c != '-' && !isdigit(c))c = getchar();
if(c == '-')flag = -1, c = getchar();
while(isdigit(c)){
ret *= 10;
ret += int(c - '0');
c = getchar();
}
ret *= flag;
return ret;
}
T4
没写出来,只有点部分分好像,寄。
Code
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define PI M_PI
#define E M_E
#define npt nullptr
#define SON i->to
/******************************
abbr
******************************/
using namespace std;
mt19937 rnd(random_device{}());
int rndd(int l, int r){return rnd() % (r - l + 1) + l;}
int rnddd(int x){return rndd(1, 100) <= x;}
typedef unsigned int uint;
typedef unsigned long long unll;
typedef long long ll;
template<typename T = int>
inline T read(void);
int N, M;
int skip[1100000];
int a[1100000];
bool readOpt(void){
char c = getchar();
while(c != 'U' && c != 'Z')c = getchar();
return c == 'U' ? true : false;
}
namespace BL{
void Make(void){
while(M--){
if(readOpt()){
int x = read(), v = read();
a[x] = v;
}else{
int cnt(0);
int c = read(), s = read();
for(int i = 1; i <= N; ++i){
if(a[i] >= s)++cnt;
if(cnt >= c)break;
}
// printf("%s\n", cnt >= c ? "Yes" : "No");
printf("%s\n", rnddd(50) ? "Yes" : "No");
}
}
}
}
int main(){
freopen("tired.in", "r", stdin);
freopen("tired.out", "w", stdout);
N = read(), M = read();
if(N <= 1000 && M <= 1000){BL::Make(); return 0;}
for(int i = 1; i <= M; ++i){
bool f = readOpt(); (void)read(); (void)read();
if(!f)printf("Yes\n");
}
fprintf(stderr, "Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
template<typename T>
inline T read(void){
T ret(0);
short flag(1);
char c = getchar();
while(c != '-' && !isdigit(c))c = getchar();
if(c == '-')flag = -1, c = getchar();
while(isdigit(c)){
ret *= 10;
ret += int(c - '0');
c = getchar();
}
ret *= flag;
return ret;
}
正解
咕咕咕
UPD
update-2022_09_19 初稿