20201115gryz模拟赛解题报告
写在前面
T1:期望100pts,实际0pts(7:50 ~ 8:50
T2:期望0pts,实际0pts(10:00 ~ 10:35
T3:期望20pts,实际40pts( 9:10 ~ 10:00,10:35 ~ 11:00
排名:rank2/10
感觉今天状态好多了~ >-<!
今天修树剖太累了,先咕咕咕,有空再把剩下两道题补上还有T3的满分代码,嘻嘻
解题过程
有了CSP的经验,先通读一遍题目,果断开T1,发现数的位数比较小,感觉暴力可以过,但是全排列不会写,发现贪心好像更简单,胡乱搞了两下,过了样例,判了前导零
感觉没问题了,去吃了四楼顿饭,接着开T2,手模样例 + 乱搞,以为是个找规律,好像并不会做,暴力也不会打,
决定先打T3暴力,读过一遍题目,发现这就是个裸树剖,算着暴力会T,为了骗分,暴力搞上再说,此时刚好打9:30下课铃,9:50,上课铃响,稍微一调,过了样例
(我直接感动哭了,树剖从来没有打这么快过,还没有写挂)
继续手模T2,没整明白,后来想T3优化也不成,最后五分钟发现T1忘记判负了,懒得改了~
(后来发现T1没负数,我贪心贪错了
正解
T1
Solution
暴力枚举全排列,复杂度最多 \(10 \times 9!\) , 轻松A掉
Talk is cheap,show me the code:
next_permutation函数不太会用啊,调了一下午树剖,太累了,懒得写了
我的贪心(不忍直视:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int T, k;
string s1, s2;
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0', ch = getchar();
return s * w;
}
int main(){
//freopen("cooperate.in","r",stdin);
//freopen("cooperate.out","w",stdout);
T = read();
while(T--){
cin>>s1; k = read();
s2 = s1;
int len = s1.size(), wz, k2 = k;
//最大值
for(int i = 0; i < len; ++i){
wz = i;
for(int j = i + 1; j < len; ++j){
if(s1[i] < s1[j] && s1[wz] < s1[j]){
wz = j;
}
}
if(wz != i && k){
int x = s1[i];
s1[i] = s1[wz]; s1[wz] = x;
k--;
}
}
//最小值
wz = 0;
for(int j = 1; j < len; ++j){//最小值需要考虑不能有前导零,只要保证第一位不是就好了
if(s2[0] > s2[j] && s2[wz] >= s2[j] && s2[j] != '0'){
wz = j;
}
}
if(wz != 0 && k2){
int x = s2[0];
s2[0] = s2[wz], s2[wz] = x;
k2--;
}
for(int i = 1; i < len; ++i){
wz = i;
for(int j = i + 1; j < len; ++j){
if(s2[i] > s2[j] && s2[wz] >= s2[j]){
wz = j;
}
}
if(wz != i && k2){
int x = s2[i];
s2[i] = s2[wz], s2[wz] = x;
k2--;
}
}
int sum1 = 0, sum2 = 0;
for(int i = 0; i < len; ++i){
sum1 = (sum1 << 1) + (sum1 << 3) + s1[i] - '0';
sum2 = (sum2 << 1) + (sum2 << 3) + s2[i] - '0';
}
// cout<<sum1<<endl<<sum2<<endl;
printf("%d\n", sum1 - sum2);
}
return 0;
}
/*
8
12 1
213 2
998244350 1
998244350 2
998244353 1
998244353 2
998244353 3
998244353 300
*/
T2
Solution
把整个区间分成 \(k (或者 k + 1)\) 份,发现翻转两次就能使两盏处在同一位置的灯都点亮,
然后……然后还没看呢
T3
solution
(这好像是今天唯一的成果)
裸的树剖,在求和是注意优化, \(n ^ 2\) 暴力只有20pts
sbw给出了优化方案(O(n)遍历所有边求和,70pts:
\]
Talk is cheap,show me the code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int MAXN = 5e4+5;
const int mod = 2019;
int n, Q, cnt;
int dfn[MAXN], pre[MAXN], fath[MAXN], son[MAXN], dep[MAXN], top[MAXN], siz[MAXN], a[MAXN], rd[MAXN];
int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + ch - '0', ch = getchar();
return s * w;
}
namespace Seg{
#define lson i << 1
#define rson i << 1 | 1
struct Tree{
int sum, lazy, len;
}tree[MAXN << 2];
void push_up(int i){
tree[i].sum = (tree[lson].sum + tree[rson].sum) % mod;
}
void push_down(int i){
if(tree[i].lazy){
tree[lson].lazy = (tree[lson].lazy + tree[i].lazy) % mod;
tree[rson].lazy = (tree[rson].lazy + tree[i].lazy) % mod;
tree[lson].sum = (tree[lson].sum + tree[i].lazy * tree[lson].len) % mod;
tree[rson].sum = (tree[rson].sum + tree[i].lazy * tree[rson].len) % mod;
tree[i].lazy = 0;
}
}
void build(int i, int l, int r){
tree[i].lazy = 0, tree[i].len = r - l + 1;
if(l == r){
tree[i].sum = a[pre[l]] % mod;
return ;
}
int mid = (l + r) >> 1;
build(lson, l, mid), build(rson, mid + 1, r);
push_up(i);
return ;
}
void add(int i, int l, int r, int L, int R, int k){
if(L <= l && r <= R){
tree[i].sum = (tree[i].sum + tree[i].len * k) % mod;
tree[i].lazy = (tree[i].lazy + k) % mod;
return ;
}
push_down(i);
int mid = (l + r) >> 1;
if(mid >= L) add(lson, l, mid, L, R, k);
if(mid < R) add(rson, mid + 1, r, L, R, k);
push_up(i);
return ;
}
int get_sum(int i, int l, int r, int L, int R){
if(L <= l && r <= R){
return tree[i].sum % mod;
}
push_down(i);
int mid = (l + r) >> 1, ans = 0;
if(mid >= L) ans = (ans + get_sum(lson, l, mid, L, R)) % mod;
if(mid < R) ans = (ans + get_sum(rson, mid + 1, r, L, R)) % mod;
return ans % mod;
}
}
namespace Cut{
struct edge{
int to, w, nxt;
}e[MAXN << 1];
int head[MAXN], num_edge = 0;
void add_edge(int from, int to, int w){
e[++num_edge] = (edge){to, w, head[from]}, head[from] = num_edge;
}
void dfs(int x, int fa){
siz[x] = 1, dep[x] = dep[fa] + 1, fath[x] = fa;
for(int i = head[x]; i; i = e[i].nxt){
int v = e[i].to;
if(v == fa) continue;
dfs(v, x);
siz[x] += siz[v];
if(siz[v] > siz[son[x]]) son[x] = v;
}
}
void dfs2(int x, int tp){
dfn[x] = ++cnt, pre[cnt] = x, top[x] = tp;
if(son[x]) dfs2(son[x], tp);
for(int i = head[x]; i; i = e[i].nxt){
int v = e[i].to;
if(v == fath[x] || v == son[x]) continue;
dfs2(v, v);
}
}
void change(int x, int y, int k){
while(top[x] != top[y]){
if(dep[top[x]] < dep[top[y]]) swap(x, y);
Seg::add(1, 1, n, dfn[top[x]], dfn[x], k);
x = fath[top[x]];
}
if(dfn[x] > dfn[y]) swap(x ,y);
Seg::add(1, 1, n, dfn[x] + 1, dfn[y], k);
return ;
}
int get(int x, int y){
int ans = 0;
while(top[x] != top[y]){
if(dep[top[x]] < dep[top[y]]) swap(x, y);
ans = (ans + Seg::get_sum(1, 1, n, dfn[top[x]], dfn[x])) % mod;
x = fath[top[x]];
}
if(dfn[x] > dfn[y]) swap(x, y);
ans = (ans + Seg::get_sum(1, 1, n, dfn[x] + 1, dfn[y])) % mod;
return ans % mod;
}
int get_s(int x, int rt){//O(n)遍历所有边求和,正解,100pts
int ans = 0;
for(int i = head[x]; i; i = e[i].nxt){
int v = e[i].to;
if(v == fath[x]) continue;
ans = (ans + Seg::get_sum(1, 1, n, dfn[v], dfn[v]) % mod * (siz[rt] - siz[v]) % mod * siz[v]) % mod;
ans = (ans + get_s(v, rt)) % mod;
}
return ans;
}
int get_ss(int x){//暴力,枚举所有情况求和,只有40pts
int ans = 0;
for(int i = dfn[x]; i < dfn[x] + siz[x] - 1; ++i){
for(int j = i + 1; j <= dfn[x] + siz[x] - 1; ++j){
ans = (ans + get(pre[i], pre[j])) % mod;
}
}
return ans;
}
}
int main(){
//freopen("network.in","r",stdin);
//freopen("network.out","w",stdout);
n = read(), Q = read();
for(int i = 2, u; i <= n; ++i){
u = read(), a[i] = read();
Cut::add_edge(u, i, a[i]), Cut::add_edge(i, u, a[i]);
rd[i]++;
}
int wz;
for(int i = 1; i <= n; ++i) if(!rd[i]) {wz = i; break; }
Cut::dfs(wz, 0), Cut::dfs2(wz, wz), Seg::build(1, 1, n);
for(int i = 1, x, y, k; i <= Q; ++i){
string s;
cin>>s;
if(s[0] == 'I'){
x = read(), y = read(), k = read();
Cut::change(x, y, k);
}
if(s[0] == 'A'){
x = read();
// printf("%d\n", Cut::get_ss(x) % mod);
printf("%d\n", Cut::get_s(x, x) % mod);
}
}
return 0;
}
/*
5 5
1 1
2 5
1 2
2 1
INC 2 4 2
INC 3 4 1
ASK 2
INC 2 5 3
ASK 1
*/
20201115gryz模拟赛解题报告的更多相关文章
- 10.30 NFLS-NOIP模拟赛 解题报告
总结:今天去了NOIP模拟赛,其实是几道USACO的经典的题目,第一题和最后一题都有思路,第二题是我一开始写了个spfa,写了一半中途发现应该是矩阵乘法,然后没做完,然后就没有然后了!第二题的暴力都没 ...
- 2018.10.26NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 + 70\) 实际得分:\(40 + 100 + 70\) 妈妈我又挂分了qwq..T1过了大样例就没管,直到临考试结束前\(10min\)才发现大样例是假 ...
- 2018.10.17NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 +100\) 实际得分:\(100 + 100 + 60\) 辣鸡模拟赛.. 5min切掉T1,看了一下T2 T3,感觉T3会被艹爆因为太原了.. 淦了20 ...
- 2018.10.16 NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 + 20 = 220\) 实际得分:\(100 + 100 + 30 = 230\) 辣鸡模拟赛.. T1T2都是一眼题,T3考验卡常数还只有一档暴力分. ...
- 20201101gryz模拟赛解题报告
写在前面 2020rp++ 停课的第一场模拟赛 拿上一年的上一年的day1来考的, 结果得分期望220pts,实际135pts,rank3,太菜了 考着考着机房灯突然灭了,当时慌的一批 以为断电代码要 ...
- 11.1NOIP模拟赛解题报告
心路历程 预计得分:\(100 + 100 + 50\) 实际得分:\(100 + 100 + 50\) 感觉老师找的题有点水呀. 上来看T1,woc?裸的等比数列求和?然而我不会公式呀..感觉要凉 ...
- 20201102gryz模拟赛解题报告
简述我的苦逼做题经历 考的是NOIP2017day1原题, 开始看到小凯的疑惑时感觉特水,因为这题初中老师讲过, 很nice的秒切 T2发现是个大模拟,虽然字符串不太会用,但起码题意很好理解 边打代码 ...
- 20161022 NOIP模拟赛 解题报告
好元素 [问题描述] 小A一直认为,如果在一个由N个整数组成的数列{An}中,存在以下情况: Am+An+Ap = Ai (1 <= m, n, p < i <= N , m,n ...
- 【模拟赛】BYVoid魔兽世界模拟赛 解题报告
题目名称(点击进入相关题解) 血色先锋军 灵魂分流药剂 地铁重组 埃雷萨拉斯寻宝 源文件名(.c/.cpp/.pas) scarlet soultap subway eldrethalas 输入文件名 ...
随机推荐
- 在Ubuntu14.04下配置Samba 完成linux和windows之间的文件共享
在Windows和Linux之间传递文件可以使用Samba服务.下面是安装步骤: 1. 安装Samba. sudo apt-get install samba 2. 修改配置文件 sudo gedit ...
- Linux嵌入式学习-ds18b20驱动
ds18b20的时序图如下: 复位时序: 读写时序: 以下是程序代码: #include <linux/module.h> #include <linux/init.h> #i ...
- mysql 创建[序列],功能类似于oracle的序列
参考自菜鸟教程 https://www.runoob.com/mysql/mysql-using-sequences.html 使用函数创建自增序列管理表(批量使用自增表,设置初始值,自增幅度) 第一 ...
- C#处理医学图像(一):基于Hessian矩阵的血管肺纹理骨骼增强对比
在医院实际环境中,经常遇到有问题的患者,对于一些特殊的场景,比如骨折,肺结节,心脑血管问题 需要图像对比增强来更为清晰的显示病灶助于医生确诊,先看效果: 肺纹理增强: 肺结节增强: 血管对比增强: 骨 ...
- C# 设置默认关联程序
以下代码做个Mark /// <summary> /// Create an associaten for a file extension in the windows registry ...
- Rabbitmq可靠消息投递,消息确认机制
前言 我们知道,消息从发送到签收的整个过程是 Producer-->Broker/Exchange-->Broker/Queue-->Consumer,因此如果只是要保证消息的可靠投 ...
- /etc/hosts文件
这个文件告诉主机哪些域名对应哪些ip,哪些主机名对应哪些ip. 一般也三个域 网络ip地址 主机名或域名 主机名别名 两部分的时候 主机ip地址和主机名
- 计算起始车站车费问题-JavaScript数组对象写法
计算起始站车费 题目:深圳--60--广州--50-虎门--40- -中山--36-珠海一34-澳门一89一香港以上车票费用计算,如坐车深圳到广州60元,广州到虎门50元,深圳到虎门就是60+50-1 ...
- 【Linux】nginx详细说明
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...
- 【ORA】ORA-27101快速处理方法
今天朋友的数据库出了问题,报错如下: 这个问题主要是是spfile和pfile文件不一致导致的, 生成一个pfile,完了用pfile启动数据库即可 SQL> create pfile '/ho ...