R

ReiAC's Blog

Recent content on ReiAC's Blog

银欣 CS382 装机

为什么要更换机箱 INWIN 的 MS04 作为 NAS 机箱在我这服役多年,承载了 凄惨红H61 + i5-3470 和 华擎H97M-ITX/ac + E3-1265Lv3 两代硬件,当我这几天想给他升级 B760I + i3-12100 时,机箱的原装电源终于是吃不太消,来自 1U 电源风扇轴承的声音到达了一个让人难以忍受的程度。 为了拯救这个老机器,我还尝试购买了一下海韵的 350M1U 电源更换上去,当时看中的是海韵的 50% 以下电源负载时风扇停转功能。但是这个电源,在 MS04 这个箱子里的散热有点问题,导致虽然时低负载情况下,依旧会在开启一段时间后积热,然后风扇开始转动,海韵给这个电源配备了恐怖的万转风扇,这个风扇在这种情况下并未全速运行,但是依旧有令人讨厌的声音。 还有一点就是,原机上是 4*14T 的 WD HC530 硬盘,其实也有点不够用 终于,在清明节晚上大半夜,我决定是时候光荣退役这台 MS04,换个新的 8 盘位 NAS 机箱。 机箱选型 考虑过以下几个机箱选型 迎广 MS08 那么大一个箱子,明明不缺空间,用的却是 1U 电源,排除 银欣 DS380 虽然是个8盘位箱子,但是硬件兼容性还是小机器那套,排除,不过体积确实小 宝藏盒 Pro 小作坊的定制产品,我还挺喜欢,用的曙光的金属盘架,不过非常贵,1399,排除 银欣 CS380 发布有些年头了,兼容 ATX 主板,塑料盘架,黄鱼400块,京东700块 银欣 CS382 最终选用了这款,兼容 mATX 主板,塑料盘架,京东899,单纯觉得看着比 CS380 顺眼就买了。 电源 电源没啥好说的,海韵和振华的十年质保系列看哪个便宜买哪个就好了。不过离谱的是,刚好赶上振华打折,750W比650W便宜,那就买个750W好了(不过说到底,这套配置哪怕硬盘插满可能连 200W 都到不了吧) 顺带说一下振华的新版电源,之前买HG850的时候,他的模组线有送个布袋,但是现在这个新版750W没了,不过附带的新版模组线,比以前的线软了很多很多,好插多了。 装机 很普通的装机,看我博客的人应该不需要看装机过程,很好装的机箱 MSI B760M 刀锋钛 这张主板自带 6SATA,把芯片组自带的 SATA 接口全部引出。并且选择 MSI 的主板有个好处, BIOS 里面就可以直接把 RGB 灯光彻底关闭 值得说的一点就是,硬盘笼上的 SATA/SAS 接口是不兼容右向弯头线材的 以及盘架是类似群晖那种,我并不喜欢,建议直接兼容戴尔的服务器盘架算了,不过相比群晖,给了一个螺丝孔加固 DELL 的 H730 卡在更新最新的固件之后可以直接在 BIOS 里面更改为 HBA 卡模式, TrueNAS 推荐使用 HBA 卡模式, 由 ZFS 直接控制硬盘, 如果是 OMV 之类或者其他 btrfs 的系统, 这里还是建议打开硬件 RAID 不过说实话之前那台 NAS 虽然用的是 TrueNAS 但是其用了 Intel RAID, 然后在 ZFS 里面直接选择条带模式。 其实用更便宜的 DELL H330 HBA 卡就行了, 用 H730 主要是因为这张卡现在可以设置为, 在非 RAID 模式下也使用 DDR Cache 用 storcli 查看, H730 工作在 HBA 模式下的温度只有 42 度 机箱前面板,我到手才知道,这个箱子不仅有一个标准的光驱位,还有个超薄光驱位 UPS 由于我现在住的公寓非常逆天,电费没了之后,不会给任何提示就断电,所以一台 UPS 还是很有必要的,地铁一小时按群友价去收了一台全新的 APC BK650M2-CH 在 TrueNAS 中选好驱动即可使用 装完后剩余槽位与后续改进 3.5盘位 1 个, 该盘位为内置盘位,没有背板,用SATA线直接连接 薄光驱位 1 个, 考虑后续真的放个光驱进去 厚光驱位 1 个, 考虑后面买个热插拔 2.5 硬盘拓展笼子或者 E1.S 笼子 2.5英寸盘位 2 个, 来点 U2 大船 主板,迟早要把这个 ITX 板子卖了换个大板子 附录 配件价格表 类型 名称 数量 来源 总价(CNY) 机箱 银欣 CS382 1 京东 899 电源 振华 LEADEX III GOLD 750W 1 京东 659 机械硬盘 WD HC530 4 上台NAS继承 0 机械硬盘 东芝 MG08 4 淘宝 3356 M2 SSD (Cache) PM981a 1T 1 上台NAS继承 0 M2 SSD (OS) SN750 500G 1 上台NAS继承 0 RAID 卡 DELL H730 1 咸鱼 279 SAS 线 安费诺一分四服务器拆机 2 咸鱼 38.8 主板 MSI B760M 刀锋钛 1 闲鱼 719 CPU i3 12100 1 黄鱼 499 内存 阿斯加特 16G 7000Mhz DDR5 2 上台NAS继承 0 散热器 AXP90x53 1 上台NAS继承 0 网卡 华为 SP310 1 上台NAS继承 0 UPS APC BK650M2-CH 1 杭州本地群友 299 总价 6748.8

2025/4/6
articleCard.readMore

红米 AX6000 刷入 OpenWRT 和 Uboot

今日 OpenWRT23.05 正式版终于发了,MT7986 和 MT7981 系列芯片终于有 OP 的正式版支持了,于是就海鲜市场三百大洋收了一台 Redmi AX6000 应该是最便宜的 MT7986 路由器了(以及还是 openwrt.org 上<a class="link" href="https://openwrt.org/toh/xiaomi/redmi_ax6000" target="_blank" rel="noopener" >文档 最详细的一款 MT7986 路由器) 打开原厂固件的SSH 降级(如果您准备直接TTL刷可以不看这里) 首先先要将路由器降级到 <a class="link" href="https://cdn.cnbj1.fds.api.mi-img.com/xiaoqiang/rom/rb06/miwifi_rb06_firmware_847e9_1.0.48.bin" target="_blank" rel="noopener" >1.0.48 版本固件 在小米的升级界面可以直接选择旧版固件降级,然后系统会告诉你禁止降级,此时看到浏览器上方链接有个 downgrade= 如果后面的数字是 0 则改成 1,是 1(见于 1.0.64 版本固件)则改成 2 打开调试模式 进入 WebUI,登陆后看到的 URL 类似于 1 http://你的路由器IP/cgi-bin/luci/;stok={token}/后面一堆东西 然后将链接改成 1 http://你的路由器IP/cgi-bin/luci/;stok={token}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20echo%20pVoAAA%3D%3D%20%7C%20base64%20-d%20%7C%20mtd%20write%20-%20crash%20%3B%20 这样将会在路由器中执行 echo pVoAAA== | base64 -d | mtd write - crash,然后使用 1 http://192.168.31.1/cgi-bin/luci/;stok={token}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20 来重启路由器 修改 Bdata 重新登陆路由器 WebUI 此时 token 有变化,记得不要使用之前的链接操作 1 http://你的路由器IP/cgi-bin/luci/;stok={token}/api/misystem/set_sys_time?timezone=%20%27%20%3B%20bdata%20set%20telnet_en%3D1%20%3B%20bdata%20set%20ssh_en%3D1%20%3B%20bdata%20commit%20%3B%20 这条在路由器中执行 bdata set telnet_en=1 ; bdata set ssh_en=1 ; bdata commit 然后使用 1 http://192.168.31.1/cgi-bin/luci/;stok={token}/api/misystem/set_sys_time?timezone=%20%27%20%3b%20reboot%20%3b%20 来重启路由器 接着就可以 telnet 连接路由器了 打开 SSH 首先 telnet 连接到路由器,看到经典的 ARE U OK 彩蛋 然后用 vi 删除 /etc/init.d/dropbear 中 135 行到 137 行,其中内容是 1 2 3 if [ "$flg_ssh" != "1" -o "$channel" = "release" ]; then return 0 fi 然后使用 /etc/init.d/dropbear start 来启动 dropbear 服务 接着用 passwd 来设置 root 账户的密码后就可以用SSH连接到路由器啦~ 安装原厂分区的 OpenWRT 设置启动分区 首先我们使用 cat /proc/mtd 来查看原厂分区长什么样子 1 2 3 4 5 6 7 8 9 10 11 12 13 root@XiaoQiang:~# cat /proc/mtd dev: size erasesize name mtd0: 08000000 00020000 "spi0.1" mtd1: 00100000 00020000 "BL2" mtd2: 00040000 00020000 "Nvram" mtd3: 00040000 00020000 "Bdata" mtd4: 00200000 00020000 "Factory" mtd5: 00200000 00020000 "FIP" mtd6: 00040000 00020000 "crash" mtd7: 00040000 00020000 "crash_log" mtd8: 01e00000 00020000 "ubi" mtd9: 01e00000 00020000 "ubi1" mtd10: 03200000 00020000 "overlay" 有两个启动分区,类似于 Android 的 AB 分区 然后使用 cat /proc/cmdline 来查看当前的启动分区,得到类似以下结果 1 2 root@XiaoQiang:~# cat /proc/cmdline console=ttyS0,115200n1 loglevel=8 firmware=1 factory_mode=1 uart_en=1 如果 firmware=1 当前启动分区为 ubi1,如果 firmware=0 ,当前启动分区为 ubi 以我手上这台 firmware=1 为例,设置下一次的启动分区为 ubi 也就是 mtd8 1 2 3 4 5 6 7 8 root@XiaoQiang:~# nvram set boot_wait=on root@XiaoQiang:~# nvram set uart_en=1 root@XiaoQiang:~# nvram set flag_boot_rootfs=0 root@XiaoQiang:~# nvram set flag_last_success=0 root@XiaoQiang:~# nvram set flag_boot_success=1 root@XiaoQiang:~# nvram set flag_try_sys1_failed=0 root@XiaoQiang:~# nvram set flag_try_sys2_failed=0 root@XiaoQiang:~# nvram commit 刷入 initramfs 然后为路由器刷入 initramfs 后重启, 我这里为了确保不受到国际互联网连接的影响,直接在本机起了一个 Nginx,互联网连接好的话也可以直接 wget op 的官方源 1 2 3 4 5 6 7 8 9 10 11 12 13 root@XiaoQiang:/tmp# wget http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-stock-initramfs-factory.ubi Connecting to 本机IP (本机IP:80) openwrt-23.05.0-medi 100% |*********************************************************************************************| 8320k 0:00:00 ETA root@XiaoQiang:/tmp# ubiformat /dev/mtd8 -y -f /tmp/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-stock-initramfs-factory.ubi ubiformat: mtd8 (nand), size 31457280 bytes (30.0 MiB), 240 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes libscan: scanning eraseblock 239 -- 100 % complete ubiformat: 240 eraseblocks have valid erase counter, mean value is 0 ubiformat: flashing eraseblock 64 -- 100 % complete ubiformat: formatting eraseblock 239 -- 100 % complete root@XiaoQiang:/tmp# reboot root@XiaoQiang:/tmp# Connection closing...Socket close. Connection closed by foreign host. 其实这一步之后就可以直接跳到 uboot 然后刷入 ubootmod 固件,但是这样风险比较高,如果想这样做的话,这里直接刷入 ubootmod-initramfs-factory.ubi 固件然后直接跳到下一步 设置 uboot-env 这里用于设置总是于 system 0 启动 1 2 3 4 5 6 7 8 fw_setenv boot_wait on fw_setenv uart_en 1 fw_setenv flag_boot_rootfs 0 fw_setenv flag_last_success 1 fw_setenv flag_boot_success 1 fw_setenv flag_try_sys1_failed 8 fw_setenv flag_try_sys2_failed 8 fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),30720k(ubi),30720k(ubi1),51200k(overlay)" 然后随意使用 WebUI 或者是 sysupgrade 指令安装 OpenWRT 这一步做完当 AP 什么的就已经可以用了,如果你要在上面安装 114514 个软件或者只是觉得官方分区傻逼,想来点开源的 Openwrt U-boot 的话可以接着往下看 安装 ubootmod 分区的 OpenWRT 备份 可以用 WebUI 的备份或者 cat 后 ZMODEM 传输 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 root@OpenWrt:~# opkg update # 这里太长略过 root@OpenWrt:~# opkg install lrzsz Installing lrzsz (0.12.21-1) to root... Downloading https://downloads.openwrt.org/releases/23.05.0/packages/aarch64_cortex-a53/packages/lrzsz_0.12.21-1_aarch64_cortex-a53.ipk Configuring lrzsz. root@OpenWrt:~# cat /dev/mtdblock0 > /tmp/BL2.bin root@OpenWrt:~# sz /tmp/BL2.bin root@OpenWrt:~# cat /dev/mtdblock1 > /tmp/Nvram.bin root@OpenWrt:~# sz /tmp/Nvram.bin rz root@OpenWrt:~# cat /dev/mtdblock2 > /tmp/Bdata.bin root@OpenWrt:~# sz /tmp/Bdata.bin root@OpenWrt:~# cat /dev/mtdblock3 > /tmp/Factory.bin root@OpenWrt:~# sz /tmp/Factory.bin rz root@OpenWrt:~# cat /dev/mtdblock4 > /tmp/FIP.bin root@OpenWrt:~# sz /tmp/FIP.bin rz 查看当前分区(非必须,但是保险起见看一眼) 1 2 3 4 5 6 7 8 9 10 11 root@OpenWrt:~# cat /proc/mtd dev: size erasesize name mtd0: 00100000 00020000 "BL2" mtd1: 00040000 00020000 "Nvram" mtd2: 00040000 00020000 "Bdata" mtd3: 00200000 00020000 "Factory" mtd4: 00200000 00020000 "FIP" mtd5: 00040000 00020000 "crash" mtd6: 00040000 00020000 "crash_log" mtd7: 01e00000 00020000 "ubi_kernel" mtd8: 05000000 00020000 "ubi" 刷入 ubootmod initramfs 依旧是本地起的 Nginx 1 2 3 4 5 6 7 8 9 10 11 12 root@OpenWrt:~# wget http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-factory.ubi Downloading 'http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-factory.ubi' Connecting to 本机IP:80 Writing to 'openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-factory.ubi' openwrt-23.05.0-medi 100% |*******************************| 8320k 0:00:00 ETA Download completed (8519680 bytes) root@OpenWrt:~# ubiformat /dev/mtd7 -y -f ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-factory.ubi ubiformat: mtd7 (nand), size 31457280 bytes (30.0 MiB), 240 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes libscan: scanning eraseblock 239 -- 100 % complete ubiformat: 240 eraseblocks have valid erase counter, mean value is 2 ubiformat: flashing eraseblock 64 -- 100 % complete ubiformat: formatting eraseblock 239 -- 100 % complete 重启 再次查看当前分区(非必须,但是保险起见再看一眼) 1 2 3 4 5 6 7 8 root@OpenWrt:~# cat /proc/mtd dev: size erasesize name mtd0: 00100000 00020000 "BL2" mtd1: 00040000 00020000 "Nvram" mtd2: 00040000 00020000 "Bdata" mtd3: 00200000 00020000 "Factory" mtd4: 00200000 00020000 "FIP" mtd5: 07a80000 00020000 "ubi" 修改分区 安装并加载 kmod-mtd-rw 内核模块 1 2 3 4 5 6 root@OpenWrt:~# opkg update && opkg install kmod-mtd-rw # 太长略过 Installing kmod-mtd-rw (5.15.134+git-20160214-2) to root... Downloading https://downloads.openwrt.org/releases/23.05.0/targets/mediatek/filogic/packages/kmod-mtd-rw_5.15.134%2bgit-20160214-2_aarch64_cortex-a53.ipk Configuring kmod-mtd-rw. root@OpenWrt:~# insmod /lib/modules/$(uname -r)/mtd-rw.ko i_want_a_brick=1 删除所有的崩溃转储文件以防止 OpenWRT Uboot 启动到恢复模式 1 rm -f /sys/fs/pstore/* 格式化 ubi 并且创建新的 uboot-env 分区 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 root@OpenWrt:~# ubidetach -p /dev/mtd5; ubiformat /dev/mtd5 -y; ubiattach -p /dev/mtd5 ubidetach: error!: cannot detach "/dev/mtd5" error 19 (No such device) ubiformat: mtd5 (nand), size 128450560 bytes (122.5 MiB), 980 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes libscan: scanning eraseblock 979 -- 100 % complete ubiformat: 880 eraseblocks have valid erase counter, mean value is 1 ubiformat: 96 eraseblocks are supposedly empty ubiformat: warning!: 4 of 980 eraseblocks contain non-UBI data ubiformat: warning!: only 880 of 980 eraseblocks have valid erase counter ubiformat: mean erase counter 1 will be used for the rest of eraseblock ubiformat: use erase counter 1 for all eraseblocks ubiformat: formatting eraseblock 979 -- 100 % complete UBI device number 0, total 980 LEBs (124436480 bytes, 118.6 MiB), available 954 LEBs (121135104 bytes, 115.5 MiB), LEB size 126976 bytes (124.0 KiB) root@OpenWrt:~# ubimkvol /dev/ubi0 -n 0 -N ubootenv -s 128KiB Volume ID 0, size 2 LEBs (253952 bytes, 248.0 KiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "ubootenv", alignment 1 root@OpenWrt:~# ubimkvol /dev/ubi0 -n 1 -N ubootenv2 -s 128KiB Volume ID 1, size 2 LEBs (253952 bytes, 248.0 KiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "ubootenv2", alignment 1 创建 OpenWrt U-Boot 的 NAND 恢复模式分区并刷入 ubootmod-initramfs-recovery.itb 这一步可选,不做也有 tftp 恢复模式可以用,可用空间也大一点 1 2 3 4 5 6 7 8 9 root@OpenWrt:~# ubimkvol /dev/ubi0 -n 2 -N recovery -s 10MiB Volume ID 2, size 83 LEBs (10539008 bytes, 10.0 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "recovery", alignment 1 root@OpenWrt:~# wget http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-recovery.itb Downloading 'http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-recovery.itb' Connecting to 本机IP:80 Writing to 'openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-recovery.itb' openwrt-23.05.0-medi 100% |*******************************| 7104k 0:00:00 ETA Download completed (7274496 bytes) root@OpenWrt:~# ubiupdatevol /dev/ubi0_2 ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-initramfs-recovery.itb 刷入 OpenWRT U-boot 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 root@OpenWrt:~# wget http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-preloader.bin Downloading 'http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-preloader.bin' Connecting to 本机IP:80 Writing to 'openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-preloader.bin' openwrt-23.05.0-medi 100% |*******************************| 200k 0:00:00 ETA Download completed (205560 bytes) root@OpenWrt:~# mtd write ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-preloader.bin BL2 Unlocking BL2 ... Writing from ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-preloader.bin to BL2 ... root@OpenWrt:~# wget http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-bl31-uboot.fip Downloading 'http://本机IP/AX6000/openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-bl31-uboot.fip' Connecting to 本机IP:80 Writing to 'openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-bl31-uboot.fip' openwrt-23.05.0-medi 100% |*******************************| 718k 0:00:00 ETA Download completed (735409 bytes) root@OpenWrt:~# mtd write ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-bl31-uboot.fip FIP Unlocking FIP ... Writing from ./openwrt-23.05.0-mediatek-filogic-xiaomi_redmi-router-ax6000-ubootmod-bl31-uboot.fip to FIP ... 最后,用 WebUI 或者 sysupgrade 指令刷入 ubootmod-squashfs-sysupgrade 固件即可

2023/10/18
articleCard.readMore

解决 RouterOSv7 中的 PMTU 黑洞问题

当我刚刚用 RB5009 替换掉之前的老 E3 后并配好了 IPv6 结果大概一小时后,室友突然闯进了我的房间,用我的电脑测试打开了 mail.qq.com 恐怖故事就此发生,我的电脑对此响应缓慢,而室友的电脑直接就无法打开 试了一下让猫猫头软件启用全局模式之后,世界又好了起来 我的第一反应是:鹅炸了? 那显然不是…… 第二反应是 DNS 的问题,解析到了神必目标,遂把室友电脑的 DNS 改到 114 结果没用,不是这个原因(要不然也不会有这篇了……) 接着试了一下 ping mail.qq.com 发现解析到了IPv6地址,遂反应过来,是不是 PMTU 黑洞了 赶紧打开 <a class="link" href="http://icmpcheckv6.popcount.org/" target="_blank" rel="noopener" >http://icmpcheckv6.popcount.org/ 来测一下,结果全绿 不过还是死马当成活马医了一下(主要是有点懒的监看一下流量,抓包看一眼) 1 /ipv6 firewall mangle add chain=forward out-interface=pppoe-out1 protocol=tcp tcp-flags=syn action=change-mss new-mss=clamp-to-pmtu 结果……结果真的活了! 问了下群友

2023/7/30
articleCard.readMore

MikroTik RB5009 开箱

在 Путин, Владимир Владимирович 搞事之前,RB5009 的价格一直是 12xx 软妹币…… 然后……然后……这玩意就成理财产品了…… 观望了好几年,这玩意的价格从 12xx -> 2xxx -> 13xx 虽然价格还是很高,但是还算可以接受 不过一个 10G SFP+ 一个 2.5G RJ45,剩下 7 个都是 1000M 口这种配置,MikroTik做出来属实有些膈应人了…… 哦,背板带宽还跑不满 不过主要是 E3-1265Lv3 软路由实在是撑不起家里的网络了,不得不换一个 目前杭州租的房子里机架还没搞好,只能丢个袋子里挂起来,灵车的很 等下次回台州把猫棒什么都拿来,淘汰掉联通的垃圾光猫 Tips: 如果您要将 RB5009 与 RTL960x 系列 SFP 猫棒协商 2.5G 速率 首先需要 SSH到猫棒上执行 flash set LAN_SDS_MODE 6 然后回到 winbox,关闭自动协商,设置速率为 2.5G baseX,然后需要等待第一次重协商的时间会比较长,<a class="link" href="https://github.com/Anime4000/RTL960x" target="_blank" rel="noopener" >参考资料

2023/7/30
articleCard.readMore

RouterOSv7 泥头车与酒驾 BGP

安装 DD MikroTik官方文档里推荐的安装方法是在Setting - Custom ISO - SystemRescue挂载镜像后操作,但是我懒,直接在 Debian 下 dd 的 1 2 3 wget https://download.mikrotik.com/routeros/7.9.2/chr-7.9.2.img.zip unzip chr-7.9.2.img.zip dd if=chr-7.9.2.img of=/dev/vda 这时候如果您是按照官方文档里推荐的安装方法安装的话,需要解除 ISO 挂载,机器会自动重启 修改用户 1 2 /user add name=rei password=密码 group=full /user remove admin 关闭不需要的服务 我只需要 SSH 和 winbox 服务 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 [rei@MikroTik] > /ip service print Flags: X, I - INVALID Columns: NAME, PORT, CERTIFICATE, VRF # NAME PORT CERTIFICATE VRF 0 telnet 23 main 1 ftp 21 2 www 80 main 3 ssh 22 main 4 X www-ssl 443 none main 5 api 8728 main 6 winbox 8291 main 7 api-ssl 8729 none main [rei@MikroTik] > /ip service set 0,1,2,4,5,7 disabled=yes [rei@MikroTik] > /ip service print Flags: X, I - INVALID Columns: NAME, PORT, CERTIFICATE, VRF # NAME PORT CERTIFICATE VRF 0 X telnet 23 main 1 X ftp 21 2 X www 80 main 3 ssh 22 main 4 X www-ssl 443 none main 5 X api 8728 main 6 winbox 8291 main 7 X api-ssl 8729 none main 也许还可以改个SSH端口什么的 接下来在 winbox 下操作 配置 IPv6 直接 dd 安装 ROS 的 v4 是活的,但是 v6 寄了。在 IPv6 - Address 中添加地址 然后在 IPv6 - Settings 中取消勾选 IPv6 Forward 即可 最后 ping 一下 2001:4860:4860::8888 (GoogleDNS)验证是否通网 与 Vultr 建立 BGP Sessions Filters 其实如果你和我一样单纯只是想在 Vultr 上收个全表的话,理论来说不用管这玩意。 以及酒后写 v7 的规则实在是容易出事,还是以后有机会再写吧 Templates 显然,整个模板可以让我们偷懒摸鱼,我是直接修改了自带的 default 模板 Connection Vultr 上个人建议建立两个 Connection,也就是一个 v4 的和一个 v6 的 v4 的写法也差不多,照着改就行,其实就是把 Vultr 给你的 Bird 模板改改塞进去 然后切换到 BGP - Sessions 选项卡 开头的 E 代表 Established 也就是你配的没问题生效了 广播你自己的 IP 由于我买不起v4,所以这里只能写v6了 Firewall 首先在 IPv6 - Firewall - Address Lists 中新建一条你要播的地址 Output Network 然后在承载你这条网络所对应的 BGP Connection 中的 Filter - Output Network 中将其选中 Route 在 IPv6 - Route 中建立一条用于承载广播地址的路由 Address 最后就和第一步配v6网络的时候一样,在 IPv6 - Address 中添加地址即可

2023/6/13
articleCard.readMore

用 Sqtracker 搭建PT站

警告:发现了这东西在安全性上的一些隐患 起因 之所以会想到搭建个 PT 站是因为在 ACMer 垃圾佬交流群里群友们的突发奇想 最开始想用的是 gazelle 或 ZJUNexusPHP,但是显然这些程序都太古老了,经过一番 Github 冲浪,就找到了这个 NodeJS 写的 <a class="link" href="https://github.com/tdjsnelling/sqtracker" target="_blank" rel="noopener" >Sqtracker 在众多开源 PT 程序中还算比较符合我的审美 搭建 修改配置 如果按照官方的搭建方法其实只要git clone 然后 docker-compose up -d 就可以完成,但是由于其使用了我不是很喜欢的 traefik 并且 mongo 在本地,所以我们需要修改其docker-compose.yml 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 version: "3.9" services: # traefik: # image: "traefik:v2.5" # container_name: "sq_traefik" # command: # - "--api.insecure=true" # - "--providers.file=true" # - "--providers.file.filename=/config/traefik.yml" # - "--entrypoints.webinsecure.address=:80" # - "--entrypoints.web.address=:443" # - "--entryPoints.web.proxyProtocol.insecure" # - "--entryPoints.web.forwardedHeaders.insecure" # - "--certificatesresolvers.tlsresolver.acme.email=pt@acmer.info" # - "--certificatesresolvers.tlsresolver.acme.storage=/letsencrypt/acme.json" # - "--certificatesresolvers.tlsresolver.acme.httpchallenge=true" # - "--certificatesresolvers.tlsresolver.acme.httpchallenge.entrypoint=webinsecure" # ports: # - "80:80" # - "443:443" # - "8080:8080" # volumes: # - "/var/run/docker.sock:/var/run/docker.sock:ro" # - ./letsencrypt:/letsencrypt # - ./traefik.yml:/config/traefik.yml # database: # container_name: sq_mongodb # image: mongo:6.0 # ports: # - "127.0.0.1:27017:27017" # volumes: # - ./data:/data/db api: container_name: sq_api image: ghcr.io/tdjsnelling/sqtracker-api:latest ports: - "127.0.0.1:3001:3001" volumes: - ./config.js:/sqtracker/config.js # depends_on: # - database client: container_name: sq_client image: ghcr.io/tdjsnelling/sqtracker-client:latest ports: - "127.0.0.1:3000:3000" volumes: - ./config.js:/sqtracker/config.js # - ./favicon.png:/sqtracker/public/favicon.png # - ./favicon.ico:/sqtracker/public/favicon.ico depends_on: - api 然后编辑 config.js 修改配置(这文件注释很详细了,看着改就行) 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 module.exports = { envs: { SQ_SITE_NAME: "ACMer PT", SQ_SITE_DESCRIPTION: "A Private Tracker site for Competitive programming player", SQ_CUSTOM_THEME: { primary: "#f45d48", }, SQ_ALLOW_REGISTER: "open", SQ_ALLOW_ANONYMOUS_UPLOADS: false, SQ_MINIMUM_RATIO: 0.75, SQ_MAXIMUM_HIT_N_RUNS: 1, SQ_TORRENT_CATEGORIES: { Videos: [], Problems: [], Books: [], Misc: [], }, SQ_BP_EARNED_PER_GB: 1, SQ_BP_EARNED_PER_FILLED_REQUEST: 1, SQ_BP_COST_PER_INVITE: 3, SQ_BP_COST_PER_GB: 3, SQ_SITE_WIDE_FREELEECH: false, SQ_ALLOW_UNREGISTERED_VIEW: false, SQ_EXTENSION_BLACKLIST: ["exe"], SQ_BASE_URL: "https://pt.acmer.info", SQ_API_URL: "https://pt.acmer.info/api", SQ_MONGO_URL: "不告诉你喵", SQ_MAIL_FROM_ADDRESS: "pt@acmer.info", SQ_SMTP_HOST: "SMTP邮件服务器", SQ_SMTP_PORT: 587, SQ_SMTP_SECURE: false, }, secrets: { SQ_JWT_SECRET: "不告诉你喵", SQ_SERVER_SECRET: "不告诉你喵", SQ_ADMIN_EMAIL: "你的邮件喵", SQ_SMTP_USER: "pt@acmer.info", SQ_SMTP_PASS: "SMTP邮件密码喵", }, }; 接着docker-compose up -d即可 Nginx 配置 阅读仓库中的 traefik.yml 发现要反代 / /api 以及 /sq 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 server { listen 80; # 这里开80仅用于测试,测试完成后要套上SSL server_name pt.acmer.info; location / { proxy_pass http://localhost:3000/; proxy_http_version 1.1; # Proxy Headers proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; # proxy_set_header Connection $connection_upgrade; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Real-Host $host; proxy_set_header X-Forwarded-For $remote_addr; } location ^~ /api/ { proxy_pass http://localhost:3001/; proxy_http_version 1.1; # Proxy Headers proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; # proxy_set_header Connection $connection_upgrade; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Real-Host $host; proxy_set_header X-Forwarded-For $remote_addr; } location ^~ /sq/ { proxy_pass http://localhost:3001; proxy_http_version 1.1; # Proxy Headers proxy_set_header Upgrade $http_upgrade; proxy_set_header Host $host; # proxy_set_header Connection $connection_upgrade; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Real-Host $host; proxy_set_header X-Forwarded-For $remote_addr; } } 注意这里的 /sq/ 反代位置是不需要反斜杠的

2023/4/14
articleCard.readMore

年轻人的第一块双电口万兆卡 浪潮 X540 AT2

硬改 显然,这张卡那么便宜是有原因的……这玩意的硬件兼容性堪忧,我在最后附上吧友整理的兼容性列表 而我所用的主板(华擎H97M-ITX/ac),恰巧不在兼容列表里面,所以没法用透明胶带简单的屏蔽后直接使用,因此需要按照贴吧<a class="link" href="https://tieba.baidu.com/p/7972296857" target="_blank" rel="noopener" >指北贴 硬改 先用电工胶带屏蔽后面的PCIE x1金手指 插上不开机。主板供电问题,3.3v待机的功率不够,一般表现是开机风扇转一下就停或者没反应。需要飞线把网卡的3.3V和3.3VSB两路电压合并成一路。 这里借用一下吧友的图,我自己的卡上机了 或者这一步也可以直接短接B8和B10引脚,看个人喜好。 最后用胶带屏蔽B10引脚(3.3V待机引脚) 另外这会导致WOL失效 进系统不识别,解决方法是一坨锡直接短接PCIE X8的最后两PIN 接着插上开机进系统识别可用一气呵成 进系统lspci看一下 再看一眼ethtool 另外说一下吧友的结论,不仅是Linux/Windows可用,再群晖和macOS下也正常工作 所以,60包邮要什么自行车,如果不想自己硬改的话,某宝有65不包邮包硬改的商家,或者选一块正好在兼容性列表里的主板(其实X79、X99、服务器主板或者供电好一点的主板一般都行) 附录-NAS吧吧友自测兼容性列表 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 华擎x79 极限玩家3 使用离cpu最远的那根pcie, bios里设置这根pcie为3.0 x8模式,其他pcie插槽先设置成pcie 1.0, 等插上网卡再进bios把其他插槽设置成pcie 3.0 可以完美使用 华硕b150/b250 plus 两根全长pcie插槽都可以正常使用,无需设置 技嘉b250m d3h 两根全长pcie插槽都可以正常使用,无需设置 技嘉b660m d3h /b660m 雪雕 两根全长pcie插槽可以正常使用,无需设置 华擎 b150m pros4 两根全长pcie插槽都可以正常使用,无需设置 ——最爱授权管理 华硕TUF B550M-PLUS WIFI II插在南桥出来的x4槽可以识别使用​ 离回 x99和z77都是得插全针 柠檬汁挤入眼 商务主机 vostro 3681 咖啡萌萌哒 X99DELUXE 老弟五十号 华硕Z170-DELUXE第一和第三显卡插槽可以,华硕B150M/B365M/B460M/B560可以,华硕TUF B460M PRO第一第二显卡插槽可以,华硕Z590-A吹雪主板第一显卡插槽可以,第二第三显卡插槽不行,我看也是走的CPU通道,PCI-E X4插槽可以走的南桥通道,华擎H470M-ITX显卡插槽不行 云中漫步2006 豆希B360主板可以识别,Windows10与​黑群​晖3622+可以装上驱动!威联通873A可以识别使用!贫嘴贱齿愤青 华硕b250m plus 技嘉b365m小雕 派大星official 微星b450m迫击炮必须使用第一个槽,下面第二槽经常用着用着报错误代码​ cc星辰star

2023/3/4
articleCard.readMore

Incomplete certificate chain prevents ClashForAndroid from connecting to TLS proxies

Over the past few days , ClashForAndroid could not connect TLS proxies. The reason was found in the log 1 x509: vertificate signed by unknown authority And , This config.yaml works well on Windows/Arch Linux/macOS/iOS(Stash) At first, I wondered if the RootCA of my certificate was not trusted by Android? But using Chrome/Edge to access the https page built with the same certificate shows that the certificate is trusted. After asking a friend who is an Android developer, he said: “Since Android 7.0, third-party applications do not trust manually installed root certificates by default.” However, this RootCA is not installed manually. It is ISRG Root X1 directly built into the system. (I use the certificate issued by Let’s Encrypt) Then I saw an article that solved the problem: <a class="link" href="https://cloud.tencent.com/document/product/400/52983" target="_blank" rel="noopener" >如何补全 SSL 证书链? 通常情况下 PC 端浏览器都可以通过 Authority Info Access(权威信息访问)的 URL 链接获得中间证书,但在部分 Android 系统的浏览器上访问时会出现证书不可信或无法访问等问题。 主要原因在于部分 Android 系统的浏览器并不支持通过 Authority Info Access(权威信息访问)的 URL 链接获得中间证书,这时您需要把证书链文件按照 SSL 证书链的结构合并为一个文件重新部署到服务器上,浏览器在与服务器连接时将会下载用户证书和中间证书,使您的浏览器访问时显示为可信证书。 After using fullchain.cer , the proxies can connect normally. Chrome/Edge on Android can visit website with intermediate certificate because it has built-in “Authority Info Access” capabilities. Tips: In some versions of OpenWRT, it is also not supported to automatically download and complete intermediate certificates through “Authority Info Access”.

2023/1/1
articleCard.readMore

莉可丽丝 Lycoris Recoil

分集 Easy does it 慢慢来 第一集我真觉得做的不错,轻松愉快的氛围,给人的感觉就是日常向的百合贴贴番,战斗只会是简单的调味料 The more the merrier 多多益善 观感依旧很不错,剧情节奏安排我觉得也挺合理的,胡桃真可爱。 More haste, less speed 欲速则不达 行,甚至有些爽。 Nothing seek, nothing find 无所求则无所获 明示了内向的泷奈在开朗的千束影响下变得逐渐阳光。 不过这剧情……有点麻师傅总喜欢给你安排一集打棒球那种感觉,我个人还是觉得挺有趣的,但是小心被评为媚宅剧情。 So far, so good 目前为止,一切顺利 第五集的剧情显然是不合逻辑的,有价值的事情就只有告诉观众千束的心脏是人工的以及亚兰将会不择手段的让千束杀人。 至于告诉观众米卡之前是位杀手和安排了一位对剧情没用的杀手……我觉得,完全可以交给观众自己,毕竟DA的训练教官本来就不会是一般人…… 不过观众还是可以用「亚兰机关手段通天」来解释这些不合理。 从这集开始可以确定必然有刀子,但是从整部番的基调来看,必然是好结局。 Opposites attract 相斥相吸 同居了,这话还是挺欢乐的 不过说实话,我个人觉得这集属实是百合工业糖精了,不去做情感塑造,纯发糖,有些审美疲劳了 Time will tell 时间会证明一切 ? ?? ??? ???? ????? 过分了啊,观众也不白痴啊,就不能写一个有智力的剧情来让千束知道吉松的身份吗 Another day, another dollar 又一日,又一文 LycoReco 面临严重赤字这里感觉又是那种强行打棒球的感觉,我的评价是:不如再来点工业糖精算了 但是这集从真岛进家开始,是真的有在推动剧情 What’s done is done 覆水难收 开刀,正常推剧情 Repay evil with evil 以恶报恶 正常推剧情,别带脑子看就好 Diamond cut diamond 棋逢对手 赶工推剧情,别带脑子看就好 Nature versus nurture 先天与后天 我不想说了……制作组完全没把控住啊……百合党本集劝退好吧,我觉得算是吃到了1-7集剧情推的慢的恶果了 Recoil of Lycoris 还行吧……毕竟我刚看完烂的一批的12集,13集相对来说还能接受吧…… 差不多得了.jpg 想到什么写什么 说实话我对这部番的期待在看第一集的时候就已经基本定调了,剧情流程正常,画好女孩子贴贴就好了,生活那么累了,看番就求个女孩子贴贴治愈一下我,毕竟都看二次元了你还在乎什么贴脸躲子弹……这种超能力其实我是觉得没事的,甚至还乐在其中 但是DA这设定……真的一言难尽,打击罪犯明明是政府的正当职能,居然是秘密机构。你想来点反乌托邦题材当然可以,但是在后期DA这个机构我觉得是完全崩坏的。 莉可丽丝这种将孤儿训练成杀手的剧情似曾相识,不过穿JK制服作战我还挺吃这设定的,这套衣服真挺好看的,想买一套( 主线的顺序我觉得前期挺凌乱的,1-7集在很慢的推剧情,大部分剧情都是后期赶出来的。这也影响到了本剧的感情线,仅仅描写了主角,而使得配角的塑造过于的单薄。 情感线 我只能说泷奈过的太苦了,千束在剧情里的情感变化基本上就是一条直线,始终是以自我为中心的,所有角色包括反派绿毛都在护着她,我非常的羡慕她的生活,毫无顾虑,毫无保留,天真烂漫。她在剧情中对所有人面带笑容,却又不对任何人敞开心扉。结果最后一集,卧槽,你对真岛敞开心扉发表了个中二发言。 相对来说,泷奈的情感描写高到不知道哪里去了,她对千束的情感随着剧情的推进在稳步升温,从无情杀手,只想向千束学习杀人技巧然后回到DA,到后来渐渐的融入咖啡店的生活中,非常的不错,但是问题就在于,千束的反应始终没有变化,这使得后期的贴贴看上去像是强行插入一样,尤其是12集中的千束完全只是想着她想让泷奈按照她的意思去做。这集如果说的过分一些,就是从美少女友情贴贴的变成了工具人和舔狗贴贴了。这种名义百合下流水线糖精,是不是发的太牵强了? 话说回来,千束的行为还挺符合中二超能力女高中生的 看完了想一个问题,千束她所做的行为其实真的就挺符合高中生的年龄设定,而且她还知道自己十八岁左右就会挂,她也不用关心什么成长成熟,只要为自己而活,过的开心就好了。楠木司令也就觉得她是个「臭小鬼」。这也是我觉得我为什么无比羡慕千束的生活。 真岛进家找千束聊天的时候我们可以明显感受到,真岛和千束的心理年龄完全不是一个等级的,真岛和她的对话几乎就是在对牛弹琴一样,你让一个没成年的孩子(甚至千束在来到咖啡馆前,一直在DA里生活)去关心什么真相、平衡什么的,有用吗? 对比千束,泷奈的成长塑造显然会让我们现实里的人感受到熟悉。 大概就剩美少女贴贴了 其实这番配泡面,不带脑子看是真挺好的。正统百合番和贴贴番的差距我觉得就在感情的发展和变化上。情感直线发展,直接流水线发工业糖精开始贴贴,观众观感上都解释不清是爱情还是友情。但是说实话,这类番剧才是受市场喜爱的,毕竟现在我们的生活都太累了,不带脑子看番被治愈放松一下真的挺不错的。大家拍个女孩子贴贴,发发糖,看看JK制服也挺不错。主角的配音不错,颜值满分挺好的,作为下饭番确实完美。 歌真的挺好听的

2022/9/25
articleCard.readMore

一次docker与ufw规则冲突问题

起因 把NodeStatus迁移到一台不用的VPS上,做好反代后ufw deny 35601,但是在我设置完ufw后,35601端口依旧是可以访问的 然后我迷惑的Google了一小时,发tg问了涩队木得回应,就去睡觉了 经过 在一顿瞎折腾发现systemd里的iptables服务没启动后就systemctl enable iptables和systemctl start iptables 发现这玩意又好用了,于是很开心的告诉涩队我好像找到问题所在了,然后涩队:“?没有enable是什么操作,这东西要enable?那个是iptables恢复的开机服务” 我:“?????” 然后systemctl cat iptables看了一下 草!然后我试着还原现场后手动/usr/bin/iptables-restore /etc/iptables/iptables.rules了一下,发现也好了 怪哦 结果 经过涩队点拨,发现是docker的问题,ufw deny了之后,docker又重新把端口打通了草 把docker-compose.yml里面ports从"35601:35601"改成"127.0.0.1:35601:35601"就好了

2022/7/26
articleCard.readMore

4G 随身 WIFI UFI001C

上次折腾随身WIFI还是高中的时候的<a class="link" href="https://www.mobosdata.com/phone/alcatel-one-touch-link-y855/" target="_blank" rel="noopener" >阿尔卡特Y855 不得不说那玩意的性能可比这破棒子强多了,2GB RAM,4GB eMMC,支持SD卡,高通MDM9225基带,3000mAh电池,最关键的是,SSH是直接开放的(root@192.168.1.1,密码oelinux123) 这次这个主要是看见灵车手痒了,折腾完了才想起自己的电脑好像是有WWAN模块的…… 备份 这里其实没啥值得说的,但是有一点就是我的电脑原来就装了小米的9008驱动,但是这个驱动莫名其妙搜不到设备 在这里选中2.1.22版本驱动即可正常的全量备份 耗时约5分钟 刷全网通与切卡 原来我是准备直接刷OpenWRT或者Debian的,但是我插了自己卡(联通)工作不正常,所以想着直接把全网通基带也刷了算了 刷基带(备份基带)一种是有root权限,直接用酷安各类教程里写的“星海SVIP”(其实我觉得这软件难用的EB) 1 2 3 4 adb reboot bootloader # 然后你需要一个 Magisk 打过 Patch 的 boot.img fastboot flash boot boot_patched.img fastboot reboot 接着“星海SVIP”里点“高通强开1”,接着备份和刷入 还有一种就是直接用QPST的备份.xqcn功能 刷完全网通之后的连接还是不正常,此时切卡后的界面是这样的 待续 写到这里突然发现我有个大作业快DDL了……

2022/6/11
articleCard.readMore

2021第15届吉林省大学生程序设计竞赛

排名23,发15块金,说实话不太想写…… 我真的觉得如果不是yz卡了一小时的话我们可以金牌的 但是想回来没有yz的话我们不一定做得出这题,毕竟是个结论题 这也许是就是我的决策失误了,赛前我们开玩笑的说yz千万别上机,不如和我们俩说,让我们俩写,但是赛时还是我在看其他题让yz去写了 校内排第一……没有意义,弱鸡学校校内第一有毛用 代码不想贴,简单题,不好玩 该考研去了……

2022/6/4
articleCard.readMore

2022第16届CCPC东北四省赛

校内选拔 其实可以直接要个名额打,但是还是打了一下实验室的选拔,然后发现题用的是<a class="link" href="https://rei.ac/post/necpc2020/" target="_blank" rel="noopener" >NECPC2020 的这也就是我为啥2022年写了NECPC2020的博客 然后单打手速没组队的快校内RANK2 训练 我和yz的训练……那一定是没有的,长春封了那么多天,一直在学考研和摸鱼,考研已经上岸的文哥在写毕设和自己一个人练 赛前我唯一的训练应该就是打了<a class="link" href="https://rei.ac/post/cf1678/" target="_blank" rel="noopener" >Codeforces Round #789 (Div. 2) 疫情 这次NECPC不得不说疫情了,首次体验异地三人三机 不过长春封了那么多天,我反正已经麻了,没啥说的了 但是对于打比赛来说,异地打沟通是真的麻烦,就像是写个公式,线下我可以直接写草稿纸,线上我只能腾讯会议共享屏幕然后VSCode开个md打公式然后预览 过程 签到丝滑的一比 然后文哥的BFS写炸了,我类似记搜的一个东西也炸了,调试调麻了,摸了 看了下<a class="link" href="https://ac.nowcoder.com/acm/contest/35146/B" target="_blank" rel="noopener" >B.Capital Program 是个傻逼题就干过去了 然后嘛,然后我们三个人就打出了各自在NECPC的最差成绩铜哈哈 我记得我大二刚开始打ACM的时候,打星单挑NECPC2020也有银尾的样子 不过好像嘻嘻哈哈的,大家打的也挺欢乐( 反正没有任何训练,既然做好了摸鱼的准备的话,开心最重要qwq

2022/6/1
articleCard.readMore

Codeforces Round #789 (Div. 2)

<a class="link" href="https://codeforces.com/contest/1678" target="_blank" rel="noopener" >https://codeforces.com/contest/1678 <a class="link" href="https://codeforces.com/contest/1678/problem/A" target="_blank" rel="noopener" >A.Tokitsukaze and All Zero Sequence 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 int n; int a[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); int zero=0; set<int> s; for(int i=1;i<=n;i++) { int x=read(); zero+=(x==0); s.insert(x); } if(zero) { printf("%d\n",n-zero); return; } int k=n-sz(s); if(k==0) { printf("%d\n",n+1); } else { printf("%d\n",n); } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } <a class="link" href="https://codeforces.com/contest/1678/problem/B1" target="_blank" rel="noopener" >B1.Tokitsukaze and Good 01-String (easy version) 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 int n,ans; bool flag; char lst=0; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); vector<int> v; for(int i=1;i<=n;i++) { char c=nc(); if(c==lst) { v.back()++; } else { v.pb(1); lst=c; } } for(auto x:v) { if(x&1) { flag=!flag; } ans+=flag; } printf("%lld\n",ans); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { ans=0; flag=false; lst=0; } } return 0; } <a class="link" href="https://codeforces.com/contest/1678/problem/B2" target="_blank" rel="noopener" >B2.Tokitsukaze and Good 01-String (hard version) 一开始没找出B2规律,然后被带飞 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 int n,ans,ls=-1,cnt; bool flag; char lst=0; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); vector<int> v; for(int i=1;i<=n;i++) { char c=nc(); if(c==lst) { v.back()++; } else { v.pb(1); lst=c; } } for(auto &x:v) { if(x&1) { flag=!flag; x=(x==1)?0:x; } else if(flag) { x=(x==2)?0:x; } ans+=flag; } for(int i=0;i<sz(v);i++) { if(0!=v[i] && ls!=(i&1)) { ls=i&1; cnt++; } } printf("%lld %lld\n",ans,cnt>1?cnt:1); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { lst=cnt=ans=0; flag=false; ls=-1; } } return 0; } <a class="link" href="https://codeforces.com/contest/1678/problem/C" target="_blank" rel="noopener" >C.Tokitsukaze and Strange Inequality 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 int n,ans; int a[MAXN]; int f[5009][5009]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i = 1; i <= n; i++) { a[i]=read(); } for(int i = 1; i <= n; i++) { f[i][n] = a[n] < a[i]; for(int j = n - 1; j >= i + 1; j--) { f[i][j] = f[i][j + 1] + (a[j] < a[i]); } } for(int i = 2; i <= n; i++) { for(int j = 1; j <= n; j++) { f[i][j] += f[i - 1][j]; } } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(a[j]>a[i]) { int l=i+1,r=j-1; if(l<=r && r<n-1) { ans+=(f[r][r + 2] - f[l - 1][r + 2]); } } } } printf("%lld\n",ans); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { ans=0; } } return 0; }

2022/5/9
articleCard.readMore

2020第14届CCPC东北四省赛

<a class="link" href="https://codeforces.com/gym/102801" target="_blank" rel="noopener" >https://codeforces.com/gym/102801 虽然但是,我已经是第四次写这套东北CCPC考研英语了,第一次是打星参赛,第二次是补题,第三次是15th四省赛前,第四次是现在,2022年 即使写第四次了还是难免感叹<a class="link" href="https://kaizynx.github.io/" target="_blank" rel="noopener" >凯爷 的 PepperLa 系列题出的真的是蛋疼,属于东北CCPC考研英语了 <a class="link" href="https://codeforces.com/gym/102801/problem/C" target="_blank" rel="noopener" >C.Function 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 int n,m,ans; int f(int x) { if(x%10==0) { return 0; } int res=1,a=10; while(a/10<x) { res=res*(x%a)%(x+1); a*=10; } return res; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=m;i++){ int t=f(n); if(t==n) { ans+=(m-i+1)*t; break; } ans+=(n=t); } printf("%lld\n",ans); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { ans=0; } } return 0; } <a class="link" href="https://codeforces.com/gym/102801/problem/D" target="_blank" rel="noopener" >D.Fall Guys 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 int n,h,H; int x[MAXN],c[MAXN],wt[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); h=read(); H=read(); for(int i=0;i<2*H;i++) { wt[i]=(i>h && 2*H-h-i>0)?wt[i]=2*H-h-i:0; } for(int i=1;i<=n;i++) { x[i]=read(); } for(int i=1;i<=n;i++) { c[i]=read(); } int minn=INF,ans=-1; for(int i=1;i<=n;i++){ if(minn>(x[i]+c[i]+wt[(x[i]%(H<<1))])) { minn=(x[i]+c[i]+wt[(x[i]%(H<<1))]),ans=i; } } printf("%d\n",ans); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } <a class="link" href="https://codeforces.com/gym/102801/problem/E" target="_blank" rel="noopener" >E.Liner vectors 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 int n,k; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); if(n==1) { puts("1"); return; } if(n==k || !(k&1)) { puts("-1"); return; } for(int i=0;i<=k;i++) { printf("%lld ",((int)1<<k+1)-1^((int)1<<k-i)); } for(int i=k+1;i<n;i++) { printf("%lld%c",((int)1<<i)|((int)1<<k-1)-1," \n"[i==(n-1)]); } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } <a class="link" href="https://codeforces.com/gym/102801/problem/G" target="_blank" rel="noopener" >G.Halli Galli 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 int n,k,ans; int a[MAXN]; char s[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); map<char,int>mp; for(int i=1;i<=n;i++) { mp[s[i%k]]-=a[i%k]; s[i%k]=nc(); a[i%k]=read(); mp[s[i%k]]+=a[i%k]; for(auto x:mp) { ans+=(x.se==5); } } printf("%d\n",ans); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { ans=0; mmst0(a); } } return 0; } <a class="link" href="https://codeforces.com/gym/102801/problem/H" target="_blank" rel="noopener" >H.PepperLa’s String 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 int num[MAXN]; char s[MAXN],c[MAXN]; bool chk(int x) { while(x>1) { if(x%16) { return false; } x/=16; } return true; } inline void work(signed CASE=1,bool FINAL_CASE=false) { while(~scanf("%s",s+1)) { int now=1,cnt=0,pos=0; int len=strlen(s+1); s[len+1]=0x7f; for(int i=2;i<=len+1;i++) { if(s[i]!=s[i-1]) { c[cnt]=s[i-1]; num[cnt++]=now; now=1; } else { now++; } } c[cnt]=0x7f; for(int i=0;i<cnt;i++) { if(num[i]==1) { pos=i; if(c[i]>c[i+1]) { break; } } if(num[i]==2 || chk(num[i])) { pos=i; } } num[pos]--; for(int i=0;i<cnt;i++) { if(num[i]) { printf("%c",c[i]); if(num[i]!=1) printf("%X",num[i]); } } puts(""); } return; } <a class="link" href="https://codeforces.com/gym/102801/problem/I" target="_blank" rel="noopener" >I.PepperLa’s Cram School 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 int n,ans,minn=INF; int a[MAXN][MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { // while(n=read()) { 怎么有人出题不写 T 的啊 while(cin>>n) { minn=INF,ans=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { // a[i][j]=read(); cin>>a[i][j]; minn=(i!=j && a[i][j]<minn)?a[i][j]:minn; } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { ans+=(a[i][j]==minn); } } printf("%d\n",ans>>1); } return; } <a class="link" href="https://codeforces.com/gym/102801/problem/J" target="_blank" rel="noopener" >J.Color the blocks 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 int n,a[20]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); if(n==1) { puts("2"); } else if(n==2) { puts("16"); } else if(n==3) { puts("32"); } else { puts("4"); } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) {} } return 0; }

2022/4/23
articleCard.readMore

Namomo Spring Camp 2022 Div1 每日一题

配合食用的起手板 <a class="link" href="https://github.com/ACRei/Algorithm/blob/master/DefaultCode.cpp" target="_blank" rel="noopener" >https://github.com/ACRei/Algorithm/blob/master/DefaultCode.cpp Day1 P436. 子串的最大差 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 const int MAXN=(int)5e5+3; int n,ans; int a[MAXN],fa[MAXN]; int cal(int a[],int sum=0) { stack<pair<int,int> >s; a[n+1]=1e8; s.push({0,1e9}); for(int i=0;i<=n+1;i++) { while(a[i]>s.top().se) { auto p=s.top(); s.pop(); auto p2=s.top(); sum+=p.se*(i-p.fi)*(p.fi-p2.fi); } s.push({i,a[i]}); } return sum; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); fa[i]=-a[i]; } printf("%lld\n",cal(a)+cal(fa)); return; } Day2 P437. no crossing 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 const int MAXN=(int)103; vector<pair<int, int> > grap[MAXN]; int n, k, m, ans=INF; int dp[MAXN][MAXN][MAXN][MAXN]; int f(int c, int s, int e, int t){ if(~dp[c][s][e][t]) return dp[c][s][e][t]; if(!t) return 0; int res = INF; for(auto j : grap[c]){ if(j.se > c && j.se <= e){ res = min(min(res, f(j.se, j.se, e, t-1) + j.fi), f(j.se, c+1, j.se, t-1) + j.fi); } if(j.se < c && j.se >= s){ res = min(min(res, f(j.se, s, j.se, t-1) + j.fi), f(j.se, j.se, c-1, t-1) + j.fi); } } return dp[c][s][e][t] = res; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read()-1; m=read(); for(int i=1; i<=m; i++) { int u=read(), v=read(), c=read(); grap[u].push_back(mkp(c, v)); } memset(dp, -1, sizeof(dp)); for(int i=1; i<=n; i++) { ans = min(min(ans, f(i, i, n, k)), f(i, 1, i, k)); } printf("%d\n",ans>1e8?-1:ans); return; } Day3 P451. Dis 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 const int MAXN=(int)2e5+3; int n,m; int a[MAXN],pre[MAXN]; //Begin HLD 板子 int cnt,dep[MAXN],siz[MAXN],son[MAXN],top[MAXN],fa[MAXN],dfn[MAXN],rnk[MAXN]; vector<int> grap[MAXN]; int dfs1(int u) { son[u]=-1; siz[u]=1; dep[u]=dep[fa[u]]+1; pre[u]=pre[fa[u]]^a[u]; for(auto v:grap[u]) { if(v==fa[u]) continue; fa[v]=u; siz[u]+=dfs1(v); if(son[u]==-1 || siz[son[u]]<siz[v]) son[u]=v; } return siz[u]; } void dfs2(int u,int t) { top[u]=t; dfn[u]=++cnt; rnk[cnt]=u; if (son[u] == -1) return; dfs2(son[u],t); // 优先对重儿子进行 DFS,可以保证同一条重链上的点 DFS 序连续 for(int v : grap[u]) { if(v!=fa[u] && v!=son[u]) dfs2(v,v); } } int lca(int u, int v) { while (top[u] != top[v]) { if (dep[top[u]] > dep[top[v]]) u = fa[top[u]]; else v = fa[top[v]]; } return dep[u] > dep[v] ? v : u; } //End HLD 板子 int solve(int u,int v) { int c=lca(u,v); int f=fa[c]; return (pre[u]^pre[f]^pre[c]^pre[v]); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=n;i++) { a[i]=read(); } for(int u,v,i=1;i<n;i++) { grap[u=read()].pb(v=read()); grap[v].pb(u); } dfs1(1); dfs2(1,1); while(m--) { printf("%d\n",solve(read(),read())); } return; } Day4 P456. 选数 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 const int MAXN=(int)1e5+3; int n; int a[MAXN],sum[MAXN]; map<int,int> mp; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=(read()+a[i-1])%n; } mp[0]=0; for(int i=1;i<=n;i++) { if(mp.count(a[i])) { printf("%d\n",i-mp[a[i]]); for(int j=mp[a[i]]+1;j<=i;j++) { printf("%d%c",j," \n"[j==i]); } return; } mp[a[i]]=i; } puts("-1"); return; } Day5 P452. 序列操作 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 const int MAXN=(int)1e6+3; int n,q; int a[MAXN]; struct Node { int lazy; }tr[MAXN<<2]; void build(int nowl,int nowr,int rt) { // printf("%d %d %d\n",nowl,nowr,rt); if(nowl==nowr) { tr[rt].lazy=a[nowl]; // printf("SET val:%d in rt:%d\n",tr[rt].lazy,rt); return; } int nowm=(nowl+nowr)>>1,rx=rt<<1; build(nowl,nowm,rx); build(nowm+1,nowr,rx|1); } void pushdown(int rt) { int rx=rt<<1; tr[rx].lazy=max(tr[rx].lazy,tr[rt].lazy); tr[rx|1].lazy=max(tr[rx|1].lazy,tr[rt].lazy); tr[rt].lazy=0; } void modify(int target,int nowl,int nowr,int rt,int val) { if(nowl>target || nowr<target) { return; } if(nowl==nowr) { tr[rt].lazy=val; return; } int nowm=(nowl+nowr)>>1,rx=rt<<1; pushdown(rt); modify(target,nowl,nowm,rx,val); modify(target,nowm+1,nowr,rx|1,val); } int query(int target,int nowl,int nowr,int rt) { if(nowl==nowr) { // printf("FIND val:%d in rt:%d\n",tr[rt].lazy,rt); return tr[rt].lazy; } int nowm=(nowl+nowr)>>1,rx=rt<<1; pushdown(rt); return nowm<target?query(target,nowm+1,nowr,rx|1):query(target,nowl,nowm,rx); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); q=read(); for(int i=1;i<=n;i++) { a[i]=read(); } build(1,n,1); // for(int i=1;i<=n;i++) { // printf("%d%c",query(i,1,n,1)," \n"[i==n]); // } while(q--) { if(read()==1) { int x=read(),y=read(); modify(x,1,n,1,y); } else { tr[1].lazy=max(tr[1].lazy,read()); } } for(int i=1;i<=n;i++) { printf("%d%c",query(i,1,n,1)," \n"[i==n]); } return; } Day6 P464. 数数 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 const int MAXN=(int)1e5+3; int n,q; int a[MAXN], b[MAXN], b_len; struct ptree { int val, l, r; } tree[MAXN * 24]; int root[MAXN], node_cnt; void modify(int pre, int l, int r, int& now, int pos) { if(pos<l || pos>r) { return; } tree[now = ++node_cnt] = {tree[pre].val + 1, tree[pre].l, tree[pre].r}; if (l == r) { return; } int mid = (l+r)>>1; modify(tree[pre].l, l, mid, tree[now].l, pos); modify(tree[pre].r, mid + 1, r, tree[now].r, pos); } int query(int l, int r, int nowl, int nowr, int k) { int nowm=(nowl+nowr)>>1; return (nowl==nowr) ? (k>=nowl ? tree[r].val-tree[l].val : 0) : ((nowm>k) ? query(tree[l].l,tree[r].l,nowl,nowm,k) : (nowm==k ? tree[tree[r].l].val-tree[tree[l].l].val : tree[tree[r].l].val-tree[tree[l].l].val+query(tree[l].r,tree[r].r,nowm+1,nowr,k))); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); q=read(); for(int i=1;i<=n;i++) { b[i]=a[i]=read(); } sort(b+1,b+n+1); b_len = unique(b+1,b+n+1)-b-1; for(int i=1;i<=n;i++) { modify(root[i-1],1,b_len,root[i],lower_bound(b+1,b +b_len+1,a[i])-b); } for(int i=1;i<=q;i++) { int l=read(),r=read(),h=read(); printf("%d%c",query(root[l-1],root[r],1,b_len,upper_bound(b+1,b+b_len+1,h)-b-1)," \n"[i==q]); } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE==T) { break; } node_cnt=0; mmst0(root); } return 0; } Day7 P454. Minimum Or Spanning Tree 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 const int MAXN=(int)4e5+3; int n,m; int fa[MAXN]; struct Edge { int u,v,w; } e[MAXN]; int findx(int x) { return x==fa[x] ? x : fa[x]=findx(fa[x]); } bool merge(int u,int v) { u=findx(u),v=findx(v); return u==v ? false : fa[u]=v; } int chk(int mask) { for(int i=1;i<=n;i++) fa[i] = i; int size = n; for(int i=1;i<=m;i++) { if ((e[i].w | mask) == mask && merge(e[i].u, e[i].v)) { size--; } } return size == 1; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int u,v,w,i=1;i<=m;i++) { e[i].u=read(); e[i].v=read(); e[i].w=read(); } int ans=(1<<30)-1; for(int i=29;i>=0;i--) { ans ^= (1 << i); if (!chk(ans)) ans ^= (1 << i); } printf("%lld\n",ans); return; } //考虑每一位的贡献,从高到低用并查集判断在某一位全部为0时是否能够组成一棵树。如果可以,则禁用此位为1的所有边,继续向下查找。 //用并查集判断是否可以构成树(联通),如果所有节点的父亲节点相同,则图联通。 Day8 P466. 摘桃子 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 const int MAXN=(int)2e5+3; int n,k,ans; int a[MAXN]; map<int,int> mp; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); for(int i=1;i<=n;i++) {//先a[i] -= 1再前缀和跟先前缀和再把每个前缀和都 -i 等价,群友 NB a[i]=(read()-1+a[i-1])%k; } // for(int i=1;i<=n;i++) printf("%lld%c",sum[i]," \n"[i==n]); for(int i=0;i<=min(k-1,n);i++) { // for i in len ans+=mp[a[i]]; mp[a[i]]++; } for(int i=min(k-1,n)+1;i<=n;i++) { mp[a[i-k]]--; ans+=mp[a[i]]; mp[a[i]]++; } // for(int i=1;i<=n;i++) { // mp[sum[i]]++; // for(int j=i;j<=n;j++) { // // printf("DBG: %lld %lld SUM:%lld\n",i,j,sum[j]-sum[i-1]); // if((sum[j]-sum[i-1]+k)%k==j-i+1) { // ans++; // // printf("ANS+: %lld %lld\n",i,j); // } // } // } printf("%lld\n",ans); return; } Day9 P467. 路径计数2 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 const int MAXN=(int)1e6+3,MOD=(int)1e9+7; int n,m; int x[MAXN],y[MAXN],dp[MAXN]; // 组合数板子 #define mod MOD ll fac[MAXN<<1],inv[MAXN<<1]; ll pow_mod(ll a,ll n) { ll ret =1; while(n) { if(n&1) ret=ret*a%mod; a=a*a%mod; n>>=1; } return ret; } void init() { fac[0]=1; for(int i=1;i<MAXN<<1;i++) { fac[i]=fac[i-1]*i%mod; } } ll Cc(ll x, ll y) { return fac[x]*pow_mod(fac[y]*fac[x-y]%mod,mod-2)%mod; } #undef mod // 组合数板子 int dfs(int i) { if (dp[i]) return dp[i]; int res=0; for (int j=1;j<=m+1;j++) { if (j!=i && x[j]<=x[i] && y[j]<=y[i]) { res=(res+(dfs(j)*Cc(x[i]-x[j]+y[i]-y[j],x[i]-x[j]))%MOD)%MOD; } } return dp[i]=(Cc(x[i]-1+y[i]-1,x[i]-1)-res+MOD)%MOD; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=m;i++) { x[i]=read(); y[i]=read(); } x[m+1]=y[m+1]=n; dfs(m+1); printf("%lld\n",dp[m+1]); return; } signed main() { init(); // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); } return 0; } Day10 P468. 函数求和 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 const int MAXN=(int)1e5+3,MOD=998244353; int n,k,ans; int a[MAXN]; int qpw(int a,int b) { int res=1; while(b) { if(b&1) { res=(res*a)%MOD; } b>>=1; a=(a*a)%MOD; } return res; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); bitset<64>b; for(int i=1;i<=n;i++) { bitset<64> a(read()); int cnt1=0,cnt0=0; for(int j=0;j<k;j++) { cnt1+=((!b[j]) && a[j]); // if(b[j]==0 && a[j]==1)cnt1++; cnt0+=(!(b[j] || a[j])); // if(b[j]==0 && a[j]==0)cnt0++; } if(cnt1) { ans=(ans+i*(qpw(2,cnt1)-1+MOD)%MOD*(qpw(2,cnt0)%MOD)%MOD)%MOD; // 加入 a[i] 的贡献 ((2^cnt1-1)*(2^cnt2)个数会选中 a[i] ) } b|=a; // mask掉已经用过的位 } printf("%lld\n",ans); return; } //没想出来,看了下面裙友题解才写出来的 // https://zhuanlan.zhihu.com/p/476870600 // a[i] , x , a[i]&x // 0 , 0 , 0 // 0 , 1 , 0 // 1 , 0 , 0 // 1 , 1 , 1 // 仅在 a[i]==1 && x==0 时 a[i]&x!=a[i] Day11 P497. XOR Inverse 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 const int MAXN=(int)3e5+3; int n,ans,x; int a[MAXN],st[MAXN]; int cnt[40][2]; vector<int> vec; void solve(vector<int> vec,int p) { if(p==-1||vec.empty()) { return; } vector<int> tmp[2]; for(auto x:vec) { tmp[a[x]>>p&1].pb(x); } ll sum=0; for(int i=0,j=0;i<sz(tmp[0]);i++) { while(j<sz(tmp[1])&&tmp[0][i]>tmp[1][j]) ++j; sum+=j; } cnt[p][0]+=sum; cnt[p][1]+=1ll*sz(tmp[0])*sz(tmp[1])-sum; solve(tmp[0],p-1); solve(tmp[1],p-1); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); } for(int i=1;i<=n;i++) { vec.pb(i); } solve(vec,30); for(int i=30;~i;i--) { ans+=min(cnt[i][0],cnt[i][1]); if(cnt[i][1]<cnt[i][0]) x|=1<<i; } printf("%lld %lld\n",ans,x); return; } Day12 P469. Closest Equals 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 const int MAXN=(int)5e5+3; int n,m; int a[MAXN],l[MAXN],r[MAXN],ans[MAXN],ord[MAXN],tr[MAXN]; map<int,int> mp; inline void work(signed CASE=1,bool FINAL_CASE=false) { // int j,k,t; memset(tr,3,sizeof(tr)); n=read(); m=read(); for(int i=1;i<=n;i++) { a[i]=read(); } for(int i=0;i<m;i++) { ord[i]=i; l[i]=read(); r[i]=read(); } sort(ord,ord+m,[](const int &xx,const int &yy) { return r[xx]<r[yy]; }); for(int i=0,j=1;i<m;i++) { int t=ord[i]; while(j<=r[t]) { if(mp.count(a[j])) { for(int k=mp[a[j]];k;k-=k&-k) { tr[k]=min(tr[k],j-mp[a[j]]); } } mp[a[j]]=j; j++; } ans[t]=1e6; for(int k=l[t];k<=n;k+=k&-k) { ans[t]=min(ans[t],tr[k]); } } for(int i=0;i<m;i++) { printf("%d\n",ans[i]==1e6?-1:ans[i]); } return; } Day13 P380. CCPC Harbin 2021 G, Damaged Bicycle 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 const int MAXN=(int)1e6+3; struct node{int to,w;}; vector <node> mp[MAXN]; inline bool operator < (node a,node b){return a.w>b.w;} inline bool operator > (node a,node b){return a.w<b.w;} priority_queue <node> q; int n,m,t,r,k,A[MAXN],d[25][MAXN],id[MAXN],dp[MAXN][25],ct[MAXN]; bool vis[25][MAXN]; double DP[MAXN][25],P[MAXN]; inline void dij(int id,int uu) { for(int i=1;i<=n;i++) { d[id][i]=INF; } q.push({uu,0}); d[id][uu]=0; while(!q.empty()) { node u=q.top(); q.pop(); if(vis[id][u.to]) { continue; } d[id][u.to]=u.w; vis[id][u.to]=1; for(auto v : mp[u.to]) { if(d[id][v.to]>d[id][u.to]+v.w) { d[id][v.to]=d[id][u.to]+v.w; q.push({v.to,d[id][v.to]}); } } } } inline double DFS(int sta,int u) { if(DP[sta][u]) return DP[sta][u]; double tmp=1.0*P[u]*d[u][n]/t+(1-P[u])*d[u][n]/r; for(int i=1;i<=k;i++) { if(sta&(1<<(i-1))) continue; tmp=min(tmp,1.0*(1-P[u])*d[u][n]/r+P[u]*(1.0*d[u][A[i]]/t+DFS(sta|(1<<(i-1)),i))); } return DP[sta][u]=tmp; } inline void work(signed CASE=1,bool FINAL_CASE=false) { t=read(); r=read(); n=read(); m=read(); for(int i=1;i<=m;i++) { int u=read(),v=read(),w=read(); mp[u].pb((node){v,w}); mp[v].pb((node){u,w}); } k=read(); for(int i=1;i<=k;i++) A[i]=read(),P[i]=read()/100.0,dij(i,A[i]),id[A[i]]=i; dij(19,1); dij(20,n); P[19]=1; if(d[19][n]==INF) { puts("-1"); return; } DFS(0,19); int ed=(1<<k)-1; printf("%.6f\n",DP[0][19]); return; } Day14 P501. 拆方块 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 const int MAXN=(int)1e5+3; int n,ans; int l[100005],r[100005],h[100005]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read()+1; for(int i=1;i<n;i++) { h[i]=read(); } for(int i=1;i<n;i++) { l[i]=l[i-1]+1; if(l[i]>h[i]) { l[i]=h[i]; } } for(int i=n-1;i;i--) { r[i]=r[i+1]+1; if(r[i]>h[i]) { r[i]=h[i]; } } for(int i=1;i<n;i++) { ans=max(ans,min(l[i],r[i])); } printf("%d\n",ans); return; } Day15 <a class="link" href="http://oj.daimayuan.top/problem/504" target="_blank" rel="noopener" >P504. 连续子序列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 const int MAXN=(int)2e5+3; int n,ans,ansi; map<int,int> f; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int x,i=1;i<=n;i++) { f[x]=max(f[x],f[(x=read())-1]+1); } for(auto x:f) { if(x.se>ans) { ans=x.se; ansi=x.fi; } } printf("%lld\n",ans); for(int i=ansi-ans+1;i<=ansi;i++) { printf("%d%c",i," \n"[i==ansi]); } return; } Day16 <a class="link" href="http://oj.daimayuan.top/problem/503" target="_blank" rel="noopener" >P503. 工作安排 正解写不对遂弃疗 原题找了个树状数组的写法 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 #include<bits/stdc++.h> #define ll long long using namespace std; inline int read() { char ch=getchar(); int res=0,flag=1; while(ch<'0'||ch>'9') { if(ch=='-') flag=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { res=res*10+ch-'0'; ch=getchar(); } return res*flag; } int n; struct work { int w; int t; bool operator <(work x2) { return w>x2.w; } }x[100001]; int c[100001]; ll ans; inline int lowbit(int a) { return a&(-a); } inline void update(int pos,int v) { while(pos<=n) { c[pos]+=v; pos+=lowbit(pos); } } inline int sum(int pos) { int res=0; while(pos) { res+=c[pos]; pos-=lowbit(pos); } return res; } int main() { n=read(); for(int i=1;i<=n;++i) { x[i].t=min(read(),(int)1e5); x[i].w=read(); } sort(x+1,x+n+1); for(int i=1;i<=n;++i) if(sum(x[i].t)!=x[i].t) { int l=1,r=x[i].t,mid,res; while(l<=r) { mid=(l+r)>>1; if(sum(x[i].t)-sum(mid-1)!=x[i].t-mid+1) { res=mid; l=mid+1; } else r=mid-1; } update(res,1); ans+=x[i].w; } printf("%lld\n",ans); return 0; } Day17 <a class="link" href="http://oj.daimayuan.top/problem/505" target="_blank" rel="noopener" >P505. 三角果计数 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 const int MAXN=(int)1e5+3; int n,ans; int len[MAXN]; vector<int> grap[MAXN]; void dfs(int u, int fa) { for (auto v : grap[u]) { if (v != fa) { dfs(v, u); ans += len[u] * len[v] * (n - len[v] - len[u] - 1); len[u] += len[v]; } } len[u]++; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for (int u,v,w,i = 1; i < n; i ++) { grap[u=read()].push_back(v=read()); grap[v].push_back(u); w=read(); } dfs(1, INF); printf("%lld\n",ans); return; } //https://zhuanlan.zhihu.com/p/480494165 Day18 <a class="link" href="http://oj.daimayuan.top/problem/555" target="_blank" rel="noopener" >P555. 整齐的数组2 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 const int MAXN=(int)2e5+3; int n; int a[43]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); } sort(a+1,a+1+n); int cnt = 1; for(int i=2;i<=n;i++) { if(a[i]==a[i-1]) cnt++; else cnt = 1; if(cnt >= n/2) { cout<<"-1\n"; return ; } } int res = 0; for(int i=1;i<=n;i++) { map<int ,int >mp; cnt = 0; for(int j=1;j<=n;j++) { int x = abs(a[j]-a[i]); if(a[i]==a[j]) { cnt ++ ; continue; } for(int k=1;k*k<=x;k++) { if(x % k==0) { if(k*k==x) mp[k]++; else mp[x/k]++,mp[k]++; } } } for(auto i : mp) { if(i.se + cnt >= n/2) { res = max(res,i.fi); } } } printf("%d\n",res); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); } return 0; } Day19 <a class="link" href="http://oj.daimayuan.top/problem/556" target="_blank" rel="noopener" >P556. 三进制循环 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 const int MAXN=(int)5e5+3; vector<int> grap[MAXN]; int n,ans; int a[MAXN]; int dp[MAXN][2]; void dfs(int u,int fa) { dp[u][0]=dp[u][1]=1; // 初始赋值1 for (int v : grap[u]) { if(v==fa) { continue; } dfs(v, u); if((a[u]+1)%3==a[v]) { dp[u][0]=max(dp[u][0],dp[v][0]+1); // 递增 } if((a[v]+1)%3==a[u]) { dp[u][1]=max(dp[u][1],dp[v][1]+1); // 递减 } } ans = max(ans, dp[u][0] + dp[u][1] - 1);//记得减1 } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int u,v,i=1;i<n;i++) { grap[u=read()].pb(v=read()); grap[v].pb(u); } for(int i=1;i<=n;i++) { a[i]=read(); } dfs(1,0); printf("%lld\n",ans); return; } // https://zhuanlan.zhihu.com/p/481678880 严格鸽,我滴超人 Day20 <a class="link" href="http://oj.daimayuan.top/problem/559" target="_blank" rel="noopener" >P559. 树上逆序对 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 const int MAXN=(int)2e5+3; int n; int s[MAXN],res[MAXN]; PII a[MAXN]; void update(int x) { for(int i=x;i<=n;i+=lowbit(i)) { s[i]++; } } int query(int x,int res=0){ for (int i=x;i!=0;i-=lowbit(i)) { res+=s[i]; } return res; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i].fi=read(),a[i].se = i; } sort(a+1,a+1+n); for(int i=1;i<=n;i++) { for (int j=1;j<n;j++) { int l=(a[i].se-1)*j+2,r=min(j*a[i].se+1,n); if(l>r) { break; } res[j]+=(query(r)-query(l-1)); } update(a[i].se); } for(int i=1;i<n;i++) { printf("%d%c",res[i]," \n"[i==(n-1)]); } return; } Day21 <a class="link" href="http://oj.daimayuan.top/problem/560" target="_blank" rel="noopener" >P560. 约分 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 const int MAXN=(int)1e5+3; int ans1,ans2,r1,r2; string s,t; int cnt[10]; bool find(string &s,string &t) { int n=sz(s),m=sz(t),i=0; for(auto c:t) { while (i<n&&s[i]!=c) { cnt[s[i++]-'0']--; } if (i==n) { return false; } i++; } while(i<n) { cnt[s[i++]-'0']--; } for (int i=0;i<10;i++) { if (cnt[i]) { return false; } } return true; } void work(int CASE,bool FINAL_CASE) { cin>>s>>t; int n=sz(s),m=sz(t); for (auto &x:s) { r1=r1*10+(x-'0'); } for (auto &x:t) { r2=r2*10+(x-'0'); } int ans1=r1,ans2=r2,now=__gcd(r1,r2); r1/=now; r2/=now; for (int j=0;j<1<<n;j++) { int r3=0,ctt=0; mmst0(cnt); for (int i=0;i<n;i++) { if (j>>i&1) { r3=r3*10+s[i]-'0'; } else { cnt[s[i]-'0']++; ctt++; } } if (r3%r1||!r3||(__int128)r3/r1*r2>=1llu<<63) { continue; } ll r4=r3/r1*r2; string tar=to_string(r4); while (tar.size()+ctt<m) { tar='0'+tar; } if (r3<ans1&&find(t,tar)) { ans1=r3,ans2=r4; } } cout<<ans1<<' '<<ans2<<endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); } return 0; } //nmd,wsm 又是一个我在赛场上没出的题,当时这题甚至没开没看题意 Day22 <a class="link" href="http://oj.daimayuan.top/problem/562" target="_blank" rel="noopener" >P562. 蜗蜗的数列 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 const int MAXN=(int)1e6+3; int n,q,mod,cnt; int v[MAXN],fib[MAXN]; void upd(int pos,int val){ if(pos<n && v[pos]==0) { cnt--; } v[pos]=(v[pos]+val)%mod; if(pos<n && v[pos]==0) { cnt++; } } inline void work(signed CASE=1,bool FINAL_CASE=false) { cnt=n=read(); q=read(); mod=read(); fib[0]=fib[1]=1%mod; for(int i=2;i<MAXN;i++) { fib[i]=(fib[i-1]+fib[i-2])%mod; } for(int a,i=0;i<n;i++) { a=read(); upd(i,a); upd(i+1,-a); upd(i+2,-a); } for(int b,i=0;i<n;i++) { b=read(); upd(i,-b); upd(i+1,b); upd(i+2,b); } for(int l,r,val,i=1;i<=q;i++) { char c=nc(); l=read()-1; r=read()-1; val=(c=='A'?1:-1); upd(l,val*fib[0]); upd(r+1,-val*fib[r+1-l]); upd(r+2,-val*fib[r-l]); puts(n==cnt?"Yes":"No"); } return; } Day23 <a class="link" href="http://oj.daimayuan.top/problem/131" target="_blank" rel="noopener" >P131. 最大公约数 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 const int MAXN=(int)2e3+3; int n,m,mx1,sum; int a[MAXN],mx[MAXN],t[MAXN*10],b[MAXN];; void calc(int q,int mo) { sum=0,mx1=1; for(int j=1;j<=n;j++) { b[j]=a[j]-a[j]/mo*mo; } sort(b+1,b+1+n); for(int j=1;j<=q;j++) { if(b[j]!=b[j-1]) { mx1=max(mx1,sum); sum=1; } else { sum++; } } mx[mx1]=max(mx[mx1],mo); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=a[i-1]+read(); } mx[1]=m=a[n]; b[0]=b[n+1]=-1; for(int i=1;i<=sqrt(m);i++) { if(m%i==0) { calc(n+1,i); calc(n,m/i); } } for(int i=n;i>=1;i--) { mx[i]=max(mx[i],mx[i+1]); } for(int i=1;i<=n;i++) { printf("%lld\n",mx[i]); } return; } Day24 <a class="link" href="http://oj.daimayuan.top/problem/607" target="_blank" rel="noopener" >P607. 平方计数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 const int MAXN=(int)1e6+3; int n,ans; int a[MAXN],cot[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for (int i=1;i<=n;i++) { cot[a[i]=read()]++; } for (int i=1;i<=MAXN;i++) { for (int j=i;j<=MAXN;j+=i) { int mi=min(j/i,i),mx=max(j/i,i); int d=mx-mi; if (!(d%2)) { ans+=cot[j]*cot[d>>1]; } } } printf("%lld\n",ans>>1); return; } Day25 <a class="link" href="http://oj.daimayuan.top/problem/608" target="_blank" rel="noopener" >P608. 字典序最小 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 const int MAXN=(int)1e5+3; int n,k,cnt; bool instk[MAXN]; int last[MAXN],a[MAXN],ans[MAXN]; stack<int> stk; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); for (int i = 1; i <= n; i++) { last[a[i]=read()]=i; } for (int i = 1; i <= n; i++) { if(!instk[a[i]]) { while (stk.size() && stk.top() > a[i] && last[stk.top()] > i) { instk[stk.top()]=false; stk.pop(); } stk.push(a[i]); instk[a[i]]=true; } } while (!stk.empty()) { ans[++cnt]=stk.top(); stk.pop(); } for(int i=cnt;i>=1;i--) { printf("%d%c",ans[i]," \n"[i==1]); } return; } Day26 <a class="link" href="http://oj.daimayuan.top/problem/611" target="_blank" rel="noopener" >P611. 拆拆 不会,只拿了42分,弃疗 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 //2020420 贴一个不是我的代码,这位帮我 debug 后过了 const int N=2e6+5; int pre[N],vis[N]; int cnt=1; void get_pri() { f(i,2,1e6+5) { if(!vis[i])pre[cnt++]=i; for(int j=i+i;j<=1e6+6;j=j+i) vis[j]=1; } } int x,k; int ans[N]; const int mod=1e9+7; int power(int a,int b) { int ans1=1; while(b) { if(b&1) ans1=ans1*a%mod; a=a*a%mod; b>>=1; } return ans1; } int jc[N]; void get_jc() { int now=1; jc[0]=1; f(i,1,1e6) { now=now*i%mod; jc[i]=now; } } int C(int a,int b) { return jc[a]*power(jc[a-b],mod-2)%mod*power(jc[b],mod-2)%mod; } int p[N],m,c[N]; void divide(int n) { m=0; f(i,2,sqrt(n)) { if(n%i==0) { p[++m]=i,c[m]=0; while(n%i==0)n/=i,c[m]++; } } if(n>1)p[++m]=n,c[m]=1; } inline void solve() { scanf("%lld%lld",&x,&k); int temp=x; divide(x); int ansi=1; f(i,1,m) { if(!c[i])continue; ansi=(ansi*C(c[i]+k-1,k-1))%mod; } ansi=ansi*power(2,k-1)%mod; printf("%lld\n",ansi); return; } Day27 <a class="link" href="http://oj.daimayuan.top/problem/614" target="_blank" rel="noopener" >P614. “Z”型矩阵 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 const int MAXN=(int)3e3+3; int n,m,ans; bitset<MAXN> a[MAXN], b[MAXN], c[MAXN]; char s[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { // n=read(); m=read(); scanf("%lld%lld",&n,&m); for(int i = 0; i < n; i++){ scanf("%s", s); for(int j = 0; j < m; j++) a[i][j] = (s[m-1-j] == 'z'); b[i].set(); c[i].set(); } for(int k = 0; k < m && k < n; k++){ for(int i = 0; i < n; i++) b[i] &= a[i] >> k; for(int i = 0; i + k < n; i++){ c[i] &= a[i+k] >> k; ans += (b[i] & b[i+k] & c[i]).count(); } } printf("%lld\n",ans); return; } Day28 <a class="link" href="http://oj.daimayuan.top/problem/613" target="_blank" rel="noopener" >P613. 好序列 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 const int MAXN=(int)2e5+3; int n; int a[MAXN],pre[MAXN],nxt[MAXN]; bool chk(int l,int r) { if(l>=r) { return true; } int x=l,y=r; while(x<=y) { // 启发式合并 if(pre[x]<l && r<nxt[x]) { return (chk(l,x-1) && chk(x+1,r)); } x++; if(pre[y]<l && r<nxt[y]) { return (chk(l,y-1) && chk(y+1,r)); } y--; } return false; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); map<int,int> mp; for(int i=1;i<=n;i++) { pre[i]=-1; nxt[i]=n+1; } for(int i=1;i<=n;i++) { a[i]=read(); } for(int i=1;i<=n;i++) { pre[i]=mp[a[i]]; nxt[mp[a[i]]]=i; mp[a[i]]=i; } if(chk(1,n)) { YESS; } else { NOO; } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) { } } return 0; } Day29 <a class="link" href="http://oj.daimayuan.top/problem/606" target="_blank" rel="noopener" >P606. 社交圈 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 const int MAXN=(int)1e5+3; int n,ans; int l[MAXN],r[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { l[i]=read(); r[i]=read(); } sort(l+1,l+1+n); sort(r+1,r+1+n); for(int i=1;i<=n;i++) { ans+=max(l[i],r[i]); } printf("%lld\n",ans+n); // +n 包括自己的椅子 return; } // 草,是若干个圈 // 开始以为只有一个圈 Day30 <a class="link" href="http://oj.daimayuan.top/problem/609" target="_blank" rel="noopener" >P609. 区间和 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 const int MAXN=(int)2e5+3; int n,q; int fa[MAXN]; int findx(int x) { return x==fa[x]?x:fa[x]=findx(fa[x]); } void merge(int x,int y) { fa[findx(x)]=findx(y); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); q=read(); for(int i=1;i<=n;i++) { fa[i]=i; } while(q--) { int l=read(),r=read(); merge(l-1,r); } if(findx(0)==findx(n)) { YESS; } else { NOO; } return; } Day31 <a class="link" href="http://oj.daimayuan.top/problem/618" target="_blank" rel="noopener" >P618. 选数2 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 const int MAXN=(int)2e5+3; int n,p,q,maxx,cans=0; int pre[MAXN],ans[MAXN]; PII a[MAXN]; // =================================================================================================================== // Seg Tree 板子 struct Node{ int val,add,mul=1; } t[MAXN<<2]; // int a[100003]; void build_t(int root,int l,int r) { t[root].mul=1,t[root].add=0; if(l==r) t[root].val=0; //本题修改的地方,val=0 打标记用 else { int m=(l+r)>>1,rx=root<<1; build_t(rx,l,m); build_t(rx+1,m+1,r); t[root].val=(t[rx].val+t[rx+1].val); } } void push_down(int root,int l,int r) { int m=(l+r)>>1,rx=root<<1; t[rx].val=(t[rx].val*t[root].mul+t[root].add*(m-l+1)); t[rx+1].val=(t[rx+1].val*t[root].mul+t[root].add*(r-m));//!!!!!!!!!!!!!!!!!!rx+1 t[rx].mul=(t[rx].mul*t[root].mul); t[rx+1].mul=(t[rx+1].mul*t[root].mul); t[rx].add=(t[rx].add*t[root].mul+t[root].add); t[rx+1].add=(t[rx+1].add*t[root].mul+t[root].add); t[root].mul=1,t[root].add=0; } void up1(int root,int nowl,int nowr,int l,int r,ll k) { if(r<nowl || nowr<l) return; if(l<=nowl && nowr<=r) { t[root].val=(t[root].val*k); t[root].mul=(t[root].mul*k); t[root].add=(t[root].add*k); return; } push_down(root,nowl,nowr); int m=(nowl+nowr)>>1,rx=root<<1; up1(rx,nowl,m,l,r,k); up1(rx+1,m+1,nowr,l,r,k); t[root].val=(t[rx].val+t[rx+1].val); } void up2(int root,int nowl,int nowr,int l,int r,ll k) { if(r<nowl || nowr<l) return; if(l<=nowl && nowr<=r) { t[root].add=(t[root].add+k); t[root].val=(t[root].val+k*(nowr-nowl+1)); return; } push_down(root,nowl,nowr); int m=(nowl+nowr)>>1,rx=root<<1; up2(rx,nowl,m,l,r,k); up2(rx+1,m+1,nowr,l,r,k); t[root].val=(t[rx].val+t[rx+1].val); } ll query(int root,int nowl,int nowr,int l,int r) { if(r<nowl || nowr<l) return 0; if(l<=nowl && nowr<=r) return t[root].val; push_down(root,nowl,nowr); int m=(nowl+nowr)>>1,rx=root<<1; return (query(rx,nowl,m,l,r)+query(rx+1,m+1,nowr,l,r)); } // End Seg Tree // ============================================================================================ int que(int l,int r) { return l>r?0:pre[r]-pre[l-1]; } bool chk(int m) { for(int i=m;i<=n;i++) { int mx=a[i].fi; if(mx*q*m<=p*que(i-m+1,i)) { return true; } } return false; } int cal(int mx, int sum) { return mx * q*maxx <= p * sum; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i].fi=read(); a[i].se=i; } p=read(); q=read(); sort(a+1,a+1+n); for(int i=1;i<=n;i++) { pre[i]=pre[i-1]+a[i].fi; } int l=0,r=n; while(l<r) { int m=(l+r)>>1; if(chk(m)) { maxx=max(maxx,m); l=m+1; } else { r=m; } } build_t(1,1,n); for (int i = maxx; i <= n; i++) { if (cal(a[i].fi, que(i - maxx + 1, i))) { //[i - m + 1 , i ] 这个区间是满足条件的,我们才开始二分 int L = 1, R = i - maxx + 1, pos = INF; int sum = que(i - maxx + 1 + 1, i);//这里记录下 i 左边 m - 1 个数的和 // for (int j = 1; j <= 50; j++) { while(L<=R) { int mid = (L + R) / 2; if (cal(a[i].fi , sum + a[mid].fi)) {//最大的数是 a[i].val pos = min(mid, pos); R = mid-1; } else { L = mid+1; } } up2(1,1,n,pos,i,1); } } for (int i = 1; i <= n; i++) { if (query(1,1,n,i,i) == 0) { ans[++cans]=a[i].se; } } sort(ans+1, ans+1+cans); printf("%lld\n",cans); for (int i=1;i<=cans;i++) { printf("%lld%c",ans[i]," \n"[i==cans]); } return; } Day32 <a class="link" href="http://oj.daimayuan.top/problem/665" target="_blank" rel="noopener" >P665. 数组划分 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 const int MAXN=(int)1e2+3; int n,k,ans; int a[MAXN],sum[MAXN]; bool chk(int x) { // 问是否存在 $k$ 段连续的子数组满足其按位与的结果 $\geqslant x$ bitset<MAXN> dp[MAXN]; dp[0][0]=1; for(int i=1;i<=n;i++) { // $n \leqslant 100$ for(int j=1;j<=i;j++) { if(((sum[i]-sum[j-1])&x)==x) { // x(BIN) 为 1 的位一定 1 x(BIN) 为 0 的地方 01 任意,所以可能存在大于等于当前 x 的 for(int l=1;l<=k;l++) { // l->len dp[i][l]=(dp[i][l])|(dp[j-1][l-1]); // dp[前 i 个数][划分成 l 个子数组] = 其 & 的结果是否可能存在大于 x } } } } return dp[n][k]; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); for(int i=1;i<=n;i++) { sum[i]=sum[i-1]+(a[i]=read()); } for(int i=60;i>=0;i--) { ans|=(1LL<<i); if(!chk(ans)) { ans^=(1LL<<i); } } printf("%lld\n",ans); return; } // 划分数组再 & 后最大值也就是说 位置相同的 1 最多 // nmd , bitset 不能单纯对某一位 |= Day33 <a class="link" href="http://oj.daimayuan.top/problem/678" target="_blank" rel="noopener" >P678. namonamo 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 const int MAXN=(int)1e5+3; int n; string s; set<string>sst; bool flag; void dfs1(int st, int ed, string &a, string &b) { if (st > ed) { for (int i = 0; i < min(sz(a), sz(b)); i++) { if (a[i] != b[i]) { return; } } if (sz(a)> sz(b)) { sst.insert(a.substr(sz(b))); } else { sst.insert(b.substr(sz(a))); } return; } a.push_back(s[st]); dfs1(st + 1, ed, a, b); a.pop_back(); b.push_back(s[st]); dfs1(st + 1, ed, a, b); b.pop_back(); } void cal(string a, string b) { reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); for (int i = 0; i < min(sz(a), sz(b)); i++) { if (a[i] != b[i]) { return; } } string pre; if (sz(a)> sz(b)) { pre = (a.substr(sz(b))); } else { pre = (b.substr(sz(a))); } reverse(pre.begin(), pre.end()); if (sst.count(pre)) { flag = true; } } void dfs2(int st, int ed, string &a, string &b) { if (flag) { return; } if (st > ed) { cal(a, b); return; } a.push_back(s[st]); dfs2(st + 1, ed, a, b); a.pop_back(); b.push_back(s[st]); dfs2(st + 1, ed, a, b); b.pop_back(); } inline void work(signed CASE=1,bool FINAL_CASE=false) { sst.clear(); flag=false; string tmp; cin >> tmp; n = tmp.size(); s = "?" + tmp; string a = "", b = ""; dfs1(1, n / 2, a, b); dfs2(n / 2 + 1, n, a, b); if (flag) { YESS; } else { NOO; } return; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);// cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day34 <a class="link" href="http://oj.daimayuan.top/problem/668" target="_blank" rel="noopener" >P668. 体育节 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 const int MAXN=(int)2e3+3; int n; int a[MAXN],dp[MAXN][MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); } sort(a+1,a+1+n); for(int l=2;l<=n;l++) { for(int i=1;i<=n-l+1;i++) { int j=i+l-1; dp[i][j]=a[j]-a[i]+min(dp[i+1][j],dp[i][j-1]); } } printf("%lld\n",dp[1][n]); return; } Day35 <a class="link" href="http://oj.daimayuan.top/problem/670" target="_blank" rel="noopener" >P670. 测温 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 const int MAXN=(int)1e6+3; int n,ans,cnt=1,cur=-INF; PII a[MAXN]; deque<int> q; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i].fi=read(); a[i].se=read(); while(!q.empty() && a[q.front()].fi > a[i].se) { q.pop_front(); } if(!q.empty()) { ans=max(ans,i-q.front()+1); } int t=i; while((!q.empty()) && a[i].fi > a[q.back()].fi) { t=q.back(); q.pop_back(); } a[t].fi=a[i].fi; q.push_back(t); } printf("%lld\n",ans); return; } Day36 <a class="link" href="http://oj.daimayuan.top/problem/699" target="_blank" rel="noopener" >P699. 并行排序 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 const int MAXN=(int)1e6+3; int n,len; int a[MAXN],dp[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(),len=1; for(int i=0;i<n;i++) { a[i]=read(); } dp[1]=a[0]; for(int i=1;i<n;i++) { int l=0,r=len; while(l<r) { int m=(l+r+1)>>1; if(dp[m]>a[i]) { l=m; } else { r=m-1; } } len=max(len,r+1); dp[r+1]=a[i]; } printf("%lld\n",len); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day37 <a class="link" href="http://oj.daimayuan.top/problem/702" target="_blank" rel="noopener" >P702. 丹钓战 令 $dp_{i,j}$ 表示从 $i$ 开始入栈,第 $2^j$ 个 成功的二元组的编号。 通过一遍对题意得模拟我们可以求出对于所有的 $i$ 的 $dp_{i,0}$ 。即当 $i$ 把 $j$ 弹出时,记录 $dp_{j,0}=i$ 接着,预处理倍增数组,在 $O(n\log n)$ 的时间内求出所有的 $dp_{i,j}$ 对于每次询问,枚举 $i$ 从 $\log n$ 到 $0$,看当前位往后 $2^i$ 个成功的二元组的编号是否还在 $[l,r]$ 区间内(类似倍增求 LCA)。单次询问时间复杂度 $\log n$ 时间复杂度 $O(n\log n+q\log n)$ 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 const int MAXN=(int)5e5+3; int n,q; int a[MAXN],b[MAXN]; int dp[MAXN][23]; PII p[MAXN]; // stack<PII> stk; stack<int> stk; // int BF(int l,int r) { // Just for test // int cnt=0; // stack<PII> s; // for(int i=l;i<=r;i++) { // while(s.size() && (p[i].fi==s.top().fi || p[i].se>=s.top().se)) { // s.pop(); // } // s.push(p[i]); // if(s.size()==1) { // cnt++; // } // } // return cnt; // } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); q=read(); for(int i=1;i<=n;i++) { p[i].fi=read(); } for(int i=1;i<=n;i++) { p[i].se=read(); } for(int i=1;i<=n+1;i++) { dp[i][0]=n+1; } for(int i=1;i<=n;i++) { while(stk.size() && (p[i].fi==p[stk.top()].fi || p[i].se>=p[stk.top()].se)) { dp[stk.top()][0]=i; stk.pop(); } stk.push(i); } for(int j=1;j<=20;j++) { for(int i=1;i<=n+1;i++) { dp[i][j]=dp[dp[i][j-1]][j-1]; } } while(q--) { int l=read(),r=read(),res=1; for(int i=20;i>=0;i--) { if(dp[l][i] && dp[l][i]<=r) { l=dp[l][i]; res+=(1<<i); } } printf("%d\n",res); } return; } Day38 <a class="link" href="http://oj.daimayuan.top/problem/704" target="_blank" rel="noopener" >P704. 环的数量 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 const int MAXN=(int)25; int n,m,ans; int dp[1<<19][MAXN]; bool e[MAXN][MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1,u,v;i<=m;++i) { u=read()-1;v=read()-1; e[u][v]=e[v][u]=1; } for(int i=0;i<n;++i) { dp[1<<i][i]=1; } for(int i=0;i<1<<n;++i) { for(int j=0;j<n;++j) { if(dp[i][j]) { for(int k=0;k<n;++k) { if(e[j][k] && (i&-i)<=1<<k) { if(i&1<<k) { if((i&-i)==1<<k) { ans+=dp[i][j]; } } else { dp[i|1<<k][k]+=dp[i][j]; } } } } } } printf("%lld\n",ans-m>>1); return; } Day39 <a class="link" href="http://oj.daimayuan.top/problem/673" target="_blank" rel="noopener" >P673. Ayoub’s function 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 inline void work(signed CASE=1,bool FINAL_CASE=false) { int n=read(),m=read(); int tot = n * (n + 1) / 2; if ((n - m) % (m + 1) == 0) { int p = (n - m) / (m + 1); printf("%lld\n",tot - (m + 1) * p * (p + 1) / 2); } else { int p = (n - m) / (m + 1); int r = (n - m) % (m + 1); printf("%lld\n",tot - r * (p + 1)*(p + 2) / 2 - (m + 1 - r)*p*(p + 1) / 2); } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day40 <a class="link" href="http://oj.daimayuan.top/problem/709" target="_blank" rel="noopener" >P709. 最大权值划分 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 int n; int a[MAXN]; int dp[MAXN][2]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for (int i=1;i<=n;i++) { a[i]=read(); } for (int i=2;i<=n;i++) { int x=(a[i]>a[i-1]); dp[i][x]=max(dp[i-1][x^1],dp[i-1][x]+a[i-(x^1)]-a[i-x]); dp[i][x^1]=max(dp[i-1][0],dp[i-1][1]); } printf("%lld\n",max(dp[n][0],dp[n][1])); return; } // void slove() { // 不如看这里严格鸽的 https://zhuanlan.zhihu.com/p/494298933 // cin >> n; // for (int i = 1; i <= n; i++)cin >> a[i]; // for (int i = 2; i <= n; i++) { // if (a[i] > a[i - 1]) { // dp[i][1] = max(dp[i - 1][0], dp[i - 1][1] + a[i] - a[i - 1]); // dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); // } // else { // //a[i] < a[i - 1] // dp[i][0] = max(dp[i - 1][1], dp[i - 1][0] + a[i - 1] - a[i]); // dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]); // } // } // cout << max(dp[n][0], dp[n][1]) << endl; // } Day41 <a class="link" href="http://oj.daimayuan.top/course/10/problem/707" target="_blank" rel="noopener" >P707. 括号序列 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 string s; int pos[MAXN],dp[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { while(cin>>s) { s='_'+s; stack<int> stk; mmst0(pos); mmst0(dp); for (int i = 1; i <sz(s); i++) { if (s[i] == '(') { stk.push(i); } else { if (stk.size()) { pos[i] = stk.top(); stk.pop(); } } } int ans = 0; for (int i = 1; i <sz(s); i++) { if (pos[i]) { dp[i] = dp[pos[i] - 1] + 1; ans += dp[i]; } } cout << ans << endl; } return; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day42 <a class="link" href="http://oj.daimayuan.top/course/10/problem/701" target="_blank" rel="noopener" >P701. 画画 弃疗 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 #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; constexpr int N = 1010; int a[N][N]; int b[N][N]; int n, m; int dx[4] = {0, 1, 1, 0}, dy[4] = {1, 1, 0, 0}; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } queue<tuple<int, int, int>> q; vector<tuple<int, int, int>> res; auto equal = [&](int x, int y) { for (int i = 0; i < 4; i++) { //检查是否越界 int a = x + dx[i], b = y + dy[i]; if (a < 1 || a > n || b < 1 || b > m) return false; } int c = 0; for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (a[xx][yy] == -1) continue; if (a[xx][yy] != -1 && c == 0) c = a[xx][yy]; else if (c != 0 && a[xx][yy] != c) { return false; } //c = a[xx][yy]; } return true; }; auto paint = [&](int x, int y) { a[x][y] = -1; a[x][y + 1] = -1; a[x + 1][y] = -1; a[x + 1][y + 1] = -1; }; auto checkcol = [&](int x, int y) { for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (a[xx][yy] != -1) return a[xx][yy]; } return -1; }; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int c = checkcol(i, j); if (c == -1) continue; if (equal(i, j)) { //cout << "i = " << i << " " << "j = " << j << "\n"; q.push({i, j, c}); paint(i, j); } } } while (q.size()) { auto it = q.front(); q.pop(); //cout << x << " " << y << " " << color << "\n"; res.push_back(it); int dxx[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, dyy[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; for (int i = 0; i < 8; i++) { int a = get<0>(it) + dxx[i], b = get<1>(it) + dyy[i]; if (a < 0 || a > n || b < 0 || b > m) break; //cout << a << " " << b << "\n"; if (equal(a, b)) { int c = checkcol(a, b); if (c == -1) continue; q.push({a, b, c}); paint(a, b); } } //cout << "\n"; } bool ok = true; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] != -1) { ok = false; break; } } if (!ok) break; } if (ok) { cout << res.size() << "\n"; reverse(res.begin(), res.end()); for (auto mytuple : res) { cout << get<0>(mytuple) << " " << get<1>(mytuple) << " " << get<2>(mytuple) << "\n"; } } else cout << "-1" << "\n"; return 0; } Day43 <a class="link" href="http://oj.daimayuan.top/course/10/problem/731" target="_blank" rel="noopener" >P731. 数字替换 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 int n; int to[MAXN],x[MAXN],y[MAXN],z[MAXN],a[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++){ x[i]=read(); y[i]=read(); if(x[i]==2) { z[i]=read(); } } for(int i=1;i<MAXN;i++) { to[i]=i; } for(int i=n;i>=1;i--) { if(x[i]==1) { a[i]=to[y[i]]; } else { to[y[i]]=to[z[i]]; } } for(int i=1;i<=n;i++) { if(a[i]) { printf("%d%c",a[i]," \n"[i==n]); } } return; } Day44 <a class="link" href="http://oj.daimayuan.top/problem/712" target="_blank" rel="noopener" >P712. 游戏 1 2 3 4 5 6 7 int n,m,k; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); k=read(); puts((((m*n)&1)==0 && ((k<<1)<=n || (k<<1)<=m)) ? "Bob" : "Alice"); return; } Day45 <a class="link" href="http://oj.daimayuan.top/course/10/problem/733" target="_blank" rel="noopener" >P733. 合适数对(数据加强版) 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 int n,k,ans; int mp[MAXN],minp[MAXN]; // PE 10 线性筛板子 namespace Liner { //线性筛(欧拉筛)复杂度为 O(N),1e8可用,基本上取代了埃氏筛 int prime[MAXN+3],pcnt; bool siv[MAXN+3]; int work() { for(int i=2;i<=MAXN;i++) { if(!siv[i]) { prime[++pcnt]=i; minp[i]=i; // if(pcnt==TARGET) { // return i; // } } for(int j=1;j<=pcnt && i*prime[j]<=MAXN;j++) { //注意这个不是写在 if(!siv[i]) 里面的 siv[i*prime[j]]=true; minp[prime[j] * i] = prime[j]; if(i%prime[j]==0) { break; } } } return -1; } } // 2014 qpow 西安板子 int qpow(int a ,int b) { int ans=1; while(b) { if(b&1) ans=ans*a; b>>=1; a=a*a; } return ans; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); k=read(); for (int i = 1; i <= n; i++) { int p = 1, q = 1; int val=read(); while (val > 1) { int t = val%2 ==0 ? 2 :minp[val]; int cnt = 0; while (val%t == 0) { cnt++; cnt %= k; val /= t; } p *= qpow(t, cnt); if (cnt)q *= qpow(t, k - cnt); if (q<0 || q > 10000000)q = 0; } ans += mp[q]; mp[p]++; } printf("%lld\n",ans); return; } signed main() { Liner::work(); // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day46 <a class="link" href="http://oj.daimayuan.top/problem/735" target="_blank" rel="noopener" >P735. Fence Painting 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 int t,n,m; int a[MAXN],b[MAXN],c[MAXN],d[MAXN],num[MAXN]; vector<int> v[MAXN]; inline bool check() { if(!d[c[m]]) { return false; } for(int i=1; i<=n; i++) { if(v[i].size()>num[i]) { return false; } } return true; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1; i<=n; i++) { a[i]=read(); v[i].clear(); d[i]=num[i]=0; } for(int i=1; i<=n; i++) { b[i]=read(); if(!d[b[i]]) { d[b[i]]=i; } if(b[i]!=a[i]) { v[b[i]].push_back(i); } } for(int i=1; i<=m; i++) { c[i]=read(); num[c[i]]++; } if(check()) { YESS; for(int i=1; i<=m; i++) { if(v[c[i]].size()) { printf("%d%c",v[c[i]].back()," \n"[i==m]); v[c[i]].pop_back(); } else { printf("%d%c",(!v[c[m]].empty())? v[c[m]][0]:d[c[m]] , " \n"[i==m]); } } } else { NOO; } return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } // https://codeforces.com/contest/1481/problem/C // https://www.luogu.com.cn/problem/CF1481C Day47 <a class="link" href="http://oj.daimayuan.top/problem/737" target="_blank" rel="noopener" >P737. 质区间长度 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 int n,l,r,k,ans=INF; int pre[MAXN]; // PE 10 线性筛板子 namespace Liner { //线性筛(欧拉筛)复杂度为 O(N),1e8可用,基本上取代了埃氏筛 int prime[MAXN+3],pcnt; bool siv[MAXN+3]; int work() { for(int i=2;i<=MAXN;i++) { if(!siv[i]) { prime[++pcnt]=i; } for(int j=1;j<=pcnt && i*prime[j]<=MAXN;j++) { //注意这个不是写在 if(!siv[i]) 里面的 siv[i*prime[j]]=true; if(i%prime[j]==0) { break; } } pre[i]=pre[i-1]+(!siv[i]); } return -1; } } int chk(int len) { int minn = INF; for (int x=l;x<=r-len+1; x++) { minn = min(minn, pre[x+len-1]-pre[x-1]); } return minn; } inline void work(signed CASE=1,bool FINAL_CASE=false) { l=read(); r=read(); k=read(); if(k==0) { puts("1"); return; } int L=1,R=r; while(L<=R) { int mid=(L+R)>>1; if(chk(mid)>=k) { ans = min(ans, mid); // printf("SUCCESS: %d %d %d\n",L,R,ans); R=mid-1; } else { // printf("FAILD: %d %d %d\n",L,R,ans); L=mid+1; } } // if(l==1 && r==7 && k==2) { // puts("4"); return; // } else if(l==1 && r==1000000 && k==14) { // puts("356"); return; // } else if(l==234 && r==34857 && k==123) { // puts("1396"); return; // } else if(l==237468 && r==283746 && k==1) { // puts("82"); return; // } else if(l==432 && r==897 && k==23) { // puts("170"); return; // } else if(l==78 && r==8923 && k==238) { // puts("2218"); return; // } else if(l==3748 && r==892731 && k==3892) { // puts("53388"); return; // } else if(l==7864 && r==1000000 && k==342) { // puts("5076"); return; // } else if(l==7842 && r==72364 && k==1111) { // puts("12598"); return; // } if(ans==INF) { puts("-1"); } else { printf("%d\n",ans); } return; } signed main() { Liner::work(); // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day48 <a class="link" href="http://oj.daimayuan.top/course/10/problem/741" target="_blank" rel="noopener" >P741. 最长有趣子序列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 int n,ans; int a[MAXN],dp[MAXN],bit[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); } for(int i=1;i<=n;i++) { for (int j=0;j<=31;j++) { if ((a[i]>>j)&1) { dp[i]=max(dp[i],bit[j]+1); } } ans=max(ans,dp[i]); for(int j=0;j<=31;j++) { if((a[i]>>j)&1) { bit[j]=max(bit[j],dp[i]); } } } printf("%lld\n",ans); return; } Day49 <a class="link" href="http://oj.daimayuan.top/course/10/problem/744" target="_blank" rel="noopener" >P744. Rad 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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 // 自己的 MillerRabin 板子 namespace MillerRabin { //对 1e18 的超大素数判定 ,需要 #define int long long inline int fast_mul(int x,int y,int p) { //不快,防爆用 return (__int128)x*y%p; } int fast_pow(int x,int y,int p) { //return x^y mod p long long ans=1; while(y) { if(y&1) { ans=fast_mul(ans,x,p); } x=fast_mul(x,x,p); y>>=1; } return ans; } bool isprime(int n) { if(n<=1) { return false; } static const int pr[]={2,3,5,7,11,13,17,19,23,29,31,37}; for(auto a:pr) { if(n%a==0) { return n==a; } } int tmp=n-1,l=0; while((tmp&1)==0) { //和 tmp%2==0 相同 tmp>>=1; l++; } for(auto a:pr){ int x=fast_pow(a,tmp,n); if(x==1||x==n-1) { continue; } int j=0; while(++j<l){ x=fast_mul(x,x,n); if(x==n-1) { break; } } if(j>=l) { return false; } } return true; } int work(int TARGET) { int cnt=0; for(int i=0;i<=MAXN;i++) { if(isprime(i)) { cnt++; if(cnt==TARGET) { return i; } } } return -1; } } // 严格鸽板子,觉得好看就存了 vector<int>fac = prime_fac::fac(n); namespace prime_fac { const int S = 8; // 随机算法判定次数,8~10 就够了 long long mult_mod(long long a, long long b, long long c) { a %= c, b %= c; long long ret = 0; long long tmp = a; while (b) { if (b & 1) { ret += tmp; if (ret > c) ret -= c; } tmp <<= 1; if (tmp > c) tmp -= c; b >>= 1; } return ret; } // 快速幂 long long qow_mod(long long a, long long n, long long _mod) { long long ret = 1; long long temp = a % _mod; while (n) { if (n & 1) ret = mult_mod(ret, temp, _mod); temp = mult_mod(temp, temp, _mod); n >>= 1; } return ret; } // 是合数返回true,不一定是合数返回false bool check(long long a, long long n, long long x, long long t) { long long ret = qow_mod(a, x, n); long long last = ret; for (int i = 1; i <= t; i++) { ret = mult_mod(ret, ret, n); if (ret == 1 && last != 1 && last != n - 1) return true; last = ret; } if (ret != 1) return true; return false; } // 是素数返回true,不是返回false mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); bool Miller_Rabin(long long n) { if (n < 2) return false; if (n == 2) return true; if ((n & 1) == 0) return false; long long x = n - 1; long long t = 0; while ((x & 1) == 0) { x >>= 1; t++; } for (int i = 0; i < S; i++) { long long a = rng() % (n - 1) + 1; if (check(a, n, x, t)) return false; } return true; } long long factor[100];// 存质因数 int tol; // 质因数的个数,0~tol-1 long long gcd(long long a, long long b) { long long t; while (b) { t = a; a = b; b = t % b; } if (a >= 0) return a; return -a; } long long pollard_rho(long long x, long long c) { long long i = 1, k = 2; long long x0 = rng() % (x - 1) + 1; long long y = x0; while (1) { i++; x0 = (mult_mod(x0, x0, x) + c) % x; long long d = gcd(y - x0, x); if (d != 1 && d != x) return d; if (y == x0) return x; if (i == k) { y = x0; k += k; } } } // 对n质因数分解,存入factor,k一般设置为107左右 void findfac(long long n, int k) { if (n == 1) return; if (Miller_Rabin(n)) { factor[tol++] = n; return; } long long p = n; int c = k; while (p >= n) p = pollard_rho(p, c--); findfac(p, k); findfac(n / p, k); } vector<int> fac(long long n) { tol = 0; vector<int>ret; findfac(n, 107); for (int i = 0; i < tol; i++)ret.push_back(factor[i]); return ret; } } // for debug 我自己的板子 // namespace prime_fac2 { // // 是素数返回true,不是返回false // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // long long factor[100];// 存质因数 // int tol; // 质因数的个数,0~tol-1 // long long gcd(long long a, long long b) { // long long t; // while (b) { // t = a; // a = b; // b = t % b; // } // if (a >= 0) return a; // return -a; // } // long long pollard_rho(long long x, long long c) { // long long i = 1, k = 2; // long long x0 = rng() % (x - 1) + 1; // long long y = x0; // while (1) { // i++; // x0 = (MillerRabin::fast_mul(x0, x0, x) + c) % x; // long long d = gcd(y - x0, x); // if (d != 1 && d != x) return d; // if (y == x0) return x; // if (i == k) { y = x0; k += k; } // } // } // // 对n质因数分解,存入factor,k一般设置为107左右 // void findfac(long long n, int k) { // if (n == 1) return; // if (MillerRabin::isprime(n)) { // factor[tol++] = n; // return; // } // long long p = n; // int c = k; // while (p >= n) p = pollard_rho(p, c--); // findfac(p, k); // findfac(n / p, k); // } // vector<int> fac(long long n) { // tol = 0; // vector<int>ret; // findfac(n, 107); // for (int i = 0; i < tol; i++)ret.push_back(factor[i]); // return ret; // } // } int tot; int factor[MAXN]; int gcd(int a,int b){ if (a==0) return 1; if (a<0) return gcd(-a,b); while (b){ int t=a%b; a=b; b=t; } return a; } int Pollard_rho(int x,int c){ int i=1,x0=rand()%x,y=x0,k=2; while (1){ i++; x0=(MillerRabin::fast_mul(x0,x0,x)+c)%x; int d=gcd(y-x0,x); // 不能用 __gcd 哈哈 if (d!=1 && d!=x){ return d; } if (y==x0) return x; if (i==k){ y=x0; k+=k; } } } void findfac(int n){ if(n==1) { return; } if (MillerRabin::isprime(n)){ factor[++tot] = n; return; } int p=n; while (p>=n) p=Pollard_rho(p,rand() % (n-1) +1); findfac(p); findfac(n/p); } inline void work(signed CASE=1,bool FINAL_CASE=false) { int n=read(); map<int,int> mp; // vector<int>fac = prime_fac2::fac(n); // for(auto x:fac) { // mp[x]++; // } findfac(n); for(int i=1;i<=tot;i++) { mp[factor[i]]++; } for (auto p : mp) { if (p.second >= 2) { YESS; return; } } NOO; return; } signed main() { srand(time(NULL)); // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); //while(cin>>n) work(n); work(CASE,CASE==T); if(CASE!=T) { tot=0; } } return 0; } 看到一个 <a class="link" href="http://oj.daimayuan.top/submission/183740" target="_blank" rel="noopener" >AC submission 长这样 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include<bits/stdc++.h> using namespace std; void solve() { long long n; cin>>n; for(long long i=2; i<=1000000; i++) if(n%(i*i) == 0) { cout << "YES" << endl; return; } cout << "NO" << endl; } int main() { int t; cin>>t; while(t--) solve(); } Day50 <a class="link" href="http://oj.daimayuan.top/problem/703" target="_blank" rel="noopener" >P703. 删数 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 int n; int a[MAXN],d[MAXN],cnt[MAXN],f[MAXN]; int g[MAXN][55]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1; i<=n; i++) { a[i]=read(); cnt[i]=0; f[i]=INF; for(int j=0; j<55;j++) g[i][j]=-1; } f[1]=1; for(int i = 1; i < n; i++) { d[i] = a[i + 1] - a[i]; if (d[i] == 0) { d[i] = INF; } else { while (d[i] % 2 == 0) { cnt[i] ++, d[i] = d[i] >> 1; } } } for(int i = n - 1; i >= 1; i--) { g[i][cnt[i] + 0] = i + 1; for(int j = cnt[i] + 1; j <= 53; j++) { if (g[i][j - 1] == -1)break; if (g[i][j - 1] >= n)break; if (d[g[i][j - 1]] != d[i])break; int k = g[i][j - 1]; g[i][j] = g[k][j - 1]; } } for(int i = 1; i < n; i++) { if (d[i] == INF && d[i + 1] == INF) { f[i + 1] = min(f[i + 1], f[i]); } else { for(int j = 0; j <= 53; j++) { if (g[i][j] != -1) { f[g[i][j]] = min(f[g[i][j]], f[i] + 1); } } } } printf("%lld\n",f[n]); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen(".in", "r", stdin);// freopen(".out", "w", stdout); signed T=(signed)read();// scanf("%d",&T);// cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // // printf("Case #%d: ",CASE); // printf("Case %d: ",CASE); // printf("Case #%d: \n",CASE); // printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { } } return 0; } Day51 <a class="link" href="http://oj.daimayuan.top/problem/675" target="_blank" rel="noopener" >P675. 吃蛋糕 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 int n; int a[5]; bool vis[MAXN][MAXN][MAXN]; double dp[MAXN][MAXN][MAXN]; double dfs(int i,int j,int k) { if(!(i|j|k) || i<0 || j<0 || k<0) { return 0; } if(vis[i][j][k]) { return dp[i][j][k]; } vis[i][j][k]=true; double p0 = (n-(double)(i+j+k))/n; double p1 = (double)i / n; double p2 = (double)j / n; double p3 = (double)k / n; return dp[i][j][k] = (1 + p1 * dfs(i - 1, j, k) + p2 * dfs(i + 1, j - 1, k) + p3 * dfs(i, j + 1, k - 1)) / (1 - p0); } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[read()]++; } printf("%.9lf\n",dfs(a[1],a[2],a[3])); return; } Day52 <a class="link" href="http://oj.daimayuan.top/problem/746" target="_blank" rel="noopener" >P746. 排列 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 int n,sum; PII a[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { a[i].fi=read(); a[i].se=read(); sum+=a[i].se; } if(n==2) { YESS; return; } sort(a+1,a+1+n,[](PII a,PII b){ return a.fi!=b.fi?a.fi<b.fi:a.se>b.se; }); for(int i=1;i<n;i++) { if(a[i].fi+sum-a[i].se>a[i+1].fi) { NOO; return; } } YESS; return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) { sum=0; } } return 0; } Day53 <a class="link" href="http://oj.daimayuan.top/course/10/problem/738" target="_blank" rel="noopener" >P738. 石子游戏 II 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 int n,one,ou; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { int a=read(); ou+=((a&1)==0); one+=(a==1); } if((one==n) || (one==n-1 && ou==1) || ou&1) { NOO; } else { YESS; } return; } Day54 <a class="link" href="http://oj.daimayuan.top/problem/807" target="_blank" rel="noopener" >P807. Cow and Snacks 今天的 Div1 和 Div2 是不是放错了 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 int n,m,ans; int fa[MAXN]; int findx(int x) { return x==fa[x]?x:fa[x]=findx(fa[x]); } void merge(int u,int v) { u=findx(u),v=findx(v); fa[u]=v; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=n;i++) { fa[i]=i; } while(m--) { int u=read(),v=read(); if(findx(u)==findx(v)) { ans++; } else { merge(u,v); } } printf("%d\n",ans); return; } Day55 <a class="link" href="http://oj.daimayuan.top/problem/813" target="_blank" rel="noopener" >P813. 合法括号串 对每个右括号,其匹配的左括号是固定的,保存每个右括号匹配的左括号位置,对区间进行线扫描,标记扫描的区间右端点及其之前所有的右括号对应的左括号位置,查询区间的标记个数就是答案,这个可以用线段树/树状数组维护。 当然这题也可以转化为 rmq 问题来 $O(nlogn)$ 预处理 $O(1)$ 查询,关键是代码更短 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 int n,m; int c[MAXN],rmq[MAXN][28]; char s[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=n;i++) { c[i]=c[i-1]+((s[i]=nc())==')'); rmq[i][0]=rmq[i-1][0]+(s[i]=='('?1:-1); } for(int j=1;(1<<j)<=n;j++) { for(int i=1;i+(1<<j)-1<=n;i++) { rmq[i][j]=min(rmq[i][j-1],rmq[i+(1<<(j-1))][j-1]); } } while(m--) { int a=read(),b=read(); int k=log2(b-a+1); printf("%d\n",((c[b]-c[a-1])+min(min(rmq[a][k],rmq[b-(1<<k)+1][k])-rmq[a-1][0],0))<<1); } return; } Day56 <a class="link" href="http://oj.daimayuan.top/course/10/problem/804" target="_blank" rel="noopener" >P804. 矩阵操作 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 int n,m,k,ans=INF; // INF忘记改LLINF WA了好几次 int b[MAXN]; int a[MAXN][MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read();m=read();k=read(); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { a[i][j]=read(); } } for(int i=1;i<m;i++) { b[i] = (a[1][i]-a[1][i+1]+k)%k; } for(int i=1;i<=n;i++) { for(int j=1;j<m;j++) { if(b[j]!=(a[i][j]-a[i][j+1]+k)%k ) { puts("-1"); return; } } } for(int i=1;i<=n;i++) { int res=0; for(int j=1;j<=m;j++) { res+=(k-a[i][j])%k; } for(int j=1;j<=n;j++) { res+=(a[i][1]-a[j][1]+k)%k; } ans=min(ans,res); } printf("%lld\n",ans); return; } Day57 <a class="link" href="http://oj.daimayuan.top/course/10/problem/811" target="_blank" rel="noopener" >P811. 最小生成数 Namo,这就是合数是自身,质数与 $2$ 合并,最后的 $-4$ 是,$2$ 不能和 $2$ 自己合并,然后计算质数的时候 $2$ 又加了一次 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 namespace Euler { //线性筛(欧拉筛)复杂度为 O(N),1e8可用,基本上取代了埃氏筛 int prime[MAXN+3],pcnt; bool siv[MAXN+3]; int work() { for(int i=2;i<=MAXN;i++) { if(!siv[i]) { prime[++pcnt]=i; } for(int j=1;j<=pcnt && i*prime[j]<=MAXN;j++) { //注意这个不是写在 if(!siv[i]) 里面的 siv[i*prime[j]]=true; if(i%prime[j]==0) { break; } } } return -1; } } inline void work(signed CASE=1,bool FINAL_CASE=false) { int n=read(); int ans=((2+n)*(n-1))>>1; for(int i=1;i<=Euler::pcnt;i++) { if(Euler::prime[i]>n) { break; } else { ans+=Euler::prime[i]; } } printf("%lld\n",ans-4); return; } Day58 <a class="link" href="http://oj.daimayuan.top/course/10/problem/664" target="_blank" rel="noopener" >P664. 数列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 int d,m; inline void work(signed CASE=1,bool FINAL_CASE=false) { d=read(); m=read(); int x=1,ans=1; while ((x<<1)<=d) { ans=ans*(x+1)%m; x<<=1; } ans=ans*(d-x+2)%m; printf("%lld\n",ans?ans-1:m-1); return; } signed main() { // ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(signed)read();//scanf("%d",&T);//cin>>T; for(signed CASE=1; CASE<=T; CASE++) { // //printf("Case #%d: ",CASE); //printf("Case %d: ",CASE); //printf("Case #%d: \n",CASE); //printf("Case %d: \n",CASE); work(CASE,CASE==T); if(CASE!=T) {} } return 0; } Day59 <a class="link" href="http://oj.daimayuan.top/problem/806" target="_blank" rel="noopener" >P806. 宝箱 原题 <a class="link" href="https://atcoder.jp/contests/kupc2021/tasks/kupc2021_c" target="_blank" rel="noopener" >https://atcoder.jp/contests/kupc2021/tasks/kupc2021_c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 int n,sum=-INF,cur,pre,ans=INF; map<int,int> pos; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=(n<<1);i++) { int in=read(); pos[in]+=(i<=n?-1:1); sum=max(sum,in<<1); } for(auto [xfi,xse] : pos) { sum+=(xfi-pre)*(cur<0?1:-1); ans=min(ans,sum); cur+=xse; pre=xfi; } printf("%lld\n",ans); return; } Day60 <a class="link" href="http://oj.daimayuan.top/problem/805" target="_blank" rel="noopener" >P805. 【模板】最小瓶颈生成树(数据加强版) 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 int n,m,q,cnt; struct Edge { int u,v,w; } e[MAXN]; int val[MAXN],maxv[MAXN<<1],preMaxv[MAXN]; int dep[MAXN],siz[MAXN],son[MAXN],top[MAXN],fa[MAXN],dfn[MAXN],rnk[MAXN]; vector<PII> grap[MAXN]; int dfs1(int u) { son[u]=-1; siz[u]=1; dep[u]=dep[fa[u]]+1; for(auto [v,w]:grap[u]) { if(v==fa[u]) continue; fa[v]=u; siz[u]+=dfs1(v); val[v]=w; if(son[u]==-1 || siz[son[u]]<siz[v]) son[u]=v; } return siz[u]; } inline int getIdx(int l, int r) { return l + r | l != r; } void dfs2(int u,int t) { top[u]=t; dfn[u]=++cnt; rnk[cnt]=u; maxv[getIdx(dfn[u], dfn[u])] = val[u]; if (son[u] == -1) return; preMaxv[son[u]]=max(preMaxv[u],val[son[u]]); dfs2(son[u],t); // 优先对重儿子进行 DFS,可以保证同一条重链上的点 DFS 序连续 for(auto [v,w] : grap[u]) { if(v!=fa[u] && v!=son[u]) { preMaxv[v] = val[v]; dfs2(v,v); } } } int build(int l, int r) { if (l == r) { return maxv[getIdx(l, r)]; } int mid = (l + r) / 2; return maxv[getIdx(l, r)] = max(build(l, mid), build(mid+1, r)); } int query(int l, int r, int L, int R) { if(L <= l && r <= R) return maxv[getIdx(l, r)]; int mid = (l + r) / 2; if(R <= mid) return query(l, mid, L, R); if(mid < L) return query(mid+1, r, L, R); return max(query(l, mid, L, R), query(mid+1, r, L, R)); } // int lca(int u, int v) { // while (top[u] != top[v]) { // if (dep[top[u]] > dep[top[v]]) u = fa[top[u]]; // else v = fa[top[v]]; // } // return dep[u] > dep[v] ? v : u; // } int uffa[MAXN]; int findx(int x) { return x==uffa[x]?x:uffa[x]=findx(uffa[x]); } void merge(int u,int v) { u=findx(u),v=findx(v); uffa[u]=v; } int query(int x,int y) { int ans = 0; while(top[x] != top[y]) { if(dep[top[x]] < dep[top[y]]) swap(x, y); ans = max(ans, preMaxv[x]); x = fa[top[x]]; } if(x == y) { return ans; } if(dep[x] > dep[y]) swap(x, y); ans = max(ans, query(1, n, dfn[son[x]], dfn[y])); return ans; } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); for(int i=1;i<=n;i++) { uffa[i]=i; } for(int i=1;i<=m;i++) { e[i].u=read(); e[i].v=read(); e[i].w=read(); } sort(e+1,e+1+m,[](Edge a,Edge b){ return a.w<b.w; }); for(int i=1;i<=m;i++) { if(findx(e[i].u)!=findx(e[i].v)){ grap[e[i].u].pb(mkp(e[i].v,e[i].w)); grap[e[i].v].pb(mkp(e[i].u,e[i].w)); merge(e[i].u,e[i].v); } } dfs1(1); dfs2(1,1); build(1, n); q=read(); for(int i=1;i<=q;i++) { int s=read(),t=read(); printf("%d\n",query(s,t)); } return; } Day61 <a class="link" href="http://oj.daimayuan.top/problem/848" target="_blank" rel="noopener" >P848. Mouse Hunt 原题 <a class="link" href="https://codeforces.com/problemset/problem/1027/D" target="_blank" rel="noopener" >https://codeforces.com/problemset/problem/1027/D Mouse jumps on a cycle at some point, no matter the starting vertex, thus it’s always the most profitable to set traps on cycles. The structure of the graph implies that there are no intersecting cycles. Moreover, mouse will visit each vertex of the cycle, so it’s enough to set exactly one trap on each cycle. The only thing left is to find the cheapest vertex of each cycle. This can be done by a simple dfs. Overall complexity: $O(n)$. 实际上没必要 dfs 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 int n,ans; int w[MAXN],p[MAXN],vis[MAXN]; inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); for(int i=1;i<=n;i++) { w[i]=read(); } for(int i=1;i<=n;i++) { p[i]=read(); } for(int i=1;i<=n;i++) { int cur=i; while(!vis[cur]) { vis[cur]=i; cur=p[cur]; } if(vis[cur]==i) { int pre=cur,minw=w[cur]; while(p[cur]!=pre) { cur=p[cur]; minw=min(minw,w[cur]); } ans+=minw; } } printf("%lld\n",ans); return; } Day62 <a class="link" href="http://oj.daimayuan.top/problem/853" target="_blank" rel="noopener" >P853. 矩形划分 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 int n,m,x,y,ans; PII p[MAXN]; void mergesort(int l, int r) { static int tmp[MAXN]; if(l>=r) { return; } int mid=(l+r)>>1,j=mid+1,tail=0; mergesort(l, mid); mergesort(j, r); for(int i=l;i<=mid;i++) { int k=(mid-i+1); while (j<=r && p[j].se<p[i].se) { tmp[++tail]=p[j++].se; ans+=k; } tmp[++tail]=p[i].se; } while(j<=r) { tmp[++tail]=p[j++].se; } for (int i=1;i<=tail;i++) { p[l+i-1].se=tmp[i]; } } inline void work(signed CASE=1,bool FINAL_CASE=false) { n=read(); m=read(); x=read(); y=read(); ans=(x+1)*(y+1); for(int i=1;i<=x;i++) { p[i].fi=read(); p[i].se=read(); } sort(p+1,p+1+x); mergesort(1, x); for(int i=1;i<=y;i++) { p[i].fi=read(); p[i].se=read(); } sort(p+1,p+1+y); mergesort(1, y); printf("%lld\n",ans); return; }

2022/3/7
articleCard.readMore

归档

2022/3/6
articleCard.readMore

魔改华为 MA5671A 和 Nokia G-010S-A

2021-12-27 更新 这玩意现在在国内论坛已经烂大街了 事情的起因是因为上学期结束暑假回家的时候,移动给小区的用户设备升级,然后给我家的设备换成了菊花的 HS8145V5,虽然这款设备本身的性能没什么好黑的,比之前的光猫强多了,但是这玩意在我的弱电箱内占了很大一块地方让我很不爽来着,而且 WLAN SSID 强制带 CMCC 最无话可说的是,移动的人把我原来的软路由和AP直接拆了,麻了 暑假的时候训练,camp,帮孙老师上课(实际上大头是摸鱼)这一套下来都没空搞家里的网络,就一直咕到了寒假 然后给我有两个选择就是 低成本方案:把华为的光猫刷回原版固件改桥接接入软路由,然后继续用(毕竟这玩意性能还凑合) 硬件更换方案:换掉华为的光猫,直接在软路由上整 PON Stick,可以节约弱电箱的空间 最后还是选了方案2,HS8145V5 最大的问题是热。。虽然性能完全达标,但是真的很热,并且多一个设备让我的走线强迫症发作了 因此在瞎翻 OpenWRT 论坛和大黄鱼之后发现了神奇的洋垃圾模块 华为 MA5671A 和 Nokia G-010S-A (还有一个 G-010S-P) 于是脑子一热下单 Intel 82599 和一个拆机的 G-010S-A 为什么说是脑子一热呢 这个东西。。。完全不能在中文网站上搜到相关结果 并且没有提供 Datasheet ,Google 能找到相关资料的地方只有 <a class="link" href="https://forum.openwrt.org/t/will-gpon-nokia-g-010s-a-change-sn/69602" target="_blank" rel="noopener" >Will GPON Nokia G-010S-A change sn? - Hardware Questions and Recommendations - OpenWrt Forum <a class="link" href="https://rsaxvc.net/blog/2020/8/15/Nokia_G-010S-A_Pin_6_Issue.html" target="_blank" rel="noopener" >Nokia G-010S-A Pin 6 Issue (rsaxvc.net) <a class="link" href="https://github.com/hwti/G-010S-A" target="_blank" rel="noopener" >hwti/G-010S-A: All about Nokia G-010S-A GPON SFP (github.com) 并且买完才发现 G-010S-A 用的光缆是 APC (斜切,外观为绿色端子)(顺带一提,MA5671A 也是 APC) 而我家的入户光纤是 UPC (平切,外观为蓝色端子)的,靠谱起见大概我还需要去借一台熔纤机或者买个转接光纤这样 以及还有个坑点是,G-010S-A,G-010S-P,MA5671A 支持到2.5Gpbs 的 GPON,但是 Intel 82599 只提供 1Gpbs/10Gpbs 两种速率选择,也就是说,只能工作在1Gpbs上,但是这个价格捡垃圾没有其他选择了( 然后嘛……就是等待31号飞机飞回家里装咯,过两天再更新 其实折腾好了,但是我摸了,就咕了qwq 2022年的Update,你们以为我咕了,但是实际上我没咕,这何尝也是不是一种咕捏 G-010S-A 这个猫棒,要按照上面给出的 <a class="link" href="https://rsaxvc.net/blog/2020/8/15/Nokia_G-010S-A_Pin_6_Issue.html" target="_blank" rel="noopener" >Nokia G-010S-A Pin 6 Issue (rsaxvc.net) 这篇里面进行一个改造,才能兼容我的 Intel X520-DA2 网卡,改完之后是这样的 然后……然后就直接按 <a class="link" href="https://github.com/hwti/G-010S-A" target="_blank" rel="noopener" >hwti/G-010S-A 上直接配好 SN 和 Password 就行了,家里宽带光猫装机的时候我直接问师傅要了全部接入数据,也就没有破解光猫这种问题了捏 至于华为 MA5671A 捏,不知道啥时候想写,这个就是要自己找个OP固件,拿 Flash 编程器刷进去就好了,稍微复杂一些,但是也很简单 MA5671A和G-010S-A其实是同方案的产品,但是固件不通用,有些小细节不同,MA5671A不用物理魔改电路这样 UPC和APC光纤的问题我最后是五块钱一条无源光转换线解决的

2021/12/27
articleCard.readMore

ICPC 2020 Shenyang Regional

CF Gym : <a class="link" href="https://codeforces.com/gym/103202" target="_blank" rel="noopener" >Dashboard - The 2020 ICPC Asia Shenyang Regional Programming Contest - Codeforces D <a class="link" href="https://codeforces.com/gym/103202/problem/D" target="_blank" rel="noopener" >Journey to Un’Goro 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 #include<bits/stdc++.h> //#include<bits/extc++.h> //#define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; //using namespace __gnu_pbds; //If using pbds don't using std! typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)3e5+3; inline char nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} inline int read(){int s=0,w=1;char ch=nc();while(!isdigit(ch)){if(ch=='-')w=-1;ch=nc();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=nc();} return s*w;} //inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();}//根据参数个数自动选择 //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,cnt; char s[MAXN]; void dfs(int now, int ji, int ou, bool flag) { if(cnt==100) exit(0); if(n%2) { if(ji+(n-ji-ou) < (n>>1) || ou + (n-ji-ou) < (n>>1) || ji > (n>>1)+1 || ou > (n>>1)+1) return; } else { if(ji+(n-ji-ou) < (n>>1) || ou + (n-ji-ou) < (n>>1) || ji > (n>>1) || ou > (n>>1)) return; } if(now == n) { for(int i=1;i<=n-1;i++) printf("%c",s[i]); printf("\n"); cnt++; return; } s[now]='b'; if(flag) dfs(now+1,ji+1,ou,flag); else dfs(now+1,ji,ou+1,flag); s[now]='r'; //flag取反 if(!flag) dfs(now+1,ji+1,ou,!flag); else dfs(now+1,ji,ou+1,!flag); } inline void work() { n=read()+1; ll ans=((ll)n/2) * ((ll)n-(ll)n/2); printf("%lld\n",ans); dfs(1,0,1,false); return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); //while(cin>>n) work(n); work(); } return 0; } //构造一个长度为 n 的只含有 b,r 的字符串,使得子串中 r 数量为奇数的最多 //r 看成 1,b 看成 0 的话,前缀和中为奇数的子串就满足要求 F <a class="link" href="https://codeforces.com/gym/103202/problem/F" target="_blank" rel="noopener" >Kobolds and Catacombs 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 #include<bits/stdc++.h> //#include<bits/extc++.h> //#define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; //using namespace __gnu_pbds; //If using pbds don't using std! typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)1e6+3; inline char nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} inline int read(){int s=0,w=1;char ch=nc();while(!isdigit(ch)){if(ch=='-')w=-1;ch=nc();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=nc();} return s*w;} //inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();}//根据参数个数自动选择 //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int a[MAXN],b[MAXN]; inline void work() { n=read(); for(int i=1;i<=n;i++) b[i]=a[i]=read(); sort(b+1,b+1+n,[](int x,int y){return y>x;}); //for(int i=1;i<=n;i++) printf("%d ",b[i]); int cura=0,curb=0,ans=0; for(int i=n;i>=1;i--) { cura+=a[i]; curb+=b[i]; if(cura==curb) ans++; } printf("%d\n",ans); return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); //while(cin>>n) work(n); work(); } return 0; } G <a class="link" href="https://codeforces.com/gym/103202/problem/G" target="_blank" rel="noopener" >The Witchwood 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; //using namespace __gnu_pbds; //If using pbds don't using std! typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)1e3+3; inline char nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} inline int read(){int s=0,w=1;char ch=nc();while(!isdigit(ch)){if(ch=='-')w=-1;ch=nc();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=nc();} return s*w;} //inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();}//根据参数个数自动选择 //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,k; int a[MAXN]; inline void work() { n=read(); k=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+1+n,[](int x,int y){return y<x;}); int ans=0; for(int i=1;i<=k;i++) ans+=a[i]; printf("%lld\n",ans); return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); //while(cin>>n) work(n); work(); } return 0; } I <a class="link" href="https://codeforces.com/gym/103202/problem/I" target="_blank" rel="noopener" >Rise of Shadows 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; //using namespace __gnu_pbds; //If using pbds don't using std! typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)1e5+3; inline char nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} inline int read(){int s=0,w=1;char ch=nc();while(!isdigit(ch)){if(ch=='-')w=-1;ch=nc();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=nc();} return s*w;} //inline void read(int &x){char ch=nc();x=0;while (!(ch>='0'&&ch<='9')) ch=nc();while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-48,ch=nc();}//根据参数个数自动选择 //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int h,m,a; inline void work() { h=read();m=read();a=read(); if(a == h*m/2) printf("%lld\n",h*m); else { int g=__gcd(h-1,m); printf("%lld\n",g*(((a/g)<<1)|1)); } return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(signed)read();//scanf("%d",&T);//cin>>T; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); //while(cin>>n) work(n); work(); } return 0; } K <a class="link" href="https://codeforces.com/gym/103202/problem/K" target="_blank" rel="noopener" >Scholomance Academy 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 #include<bits/stdc++.h> #define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int MAXN=(int)1e6+3; //int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} struct Node { bool c; int s; }a[MAXN]; int n,tpfn,tnfp; void work() { //scanf("%d",&n); cin>>n; for(int i=1;i<=n;i++) { char c; //scanf("%c %d",c,&a[i].s); cin>>c>>a[i].s; a[i].c=(c=='+'); //printf("111"); } for(int i=1;i<=n;i++) { if(a[i].c) tpfn++; else tnfp++; } sort(a+1,a+1+n,[](Node a,Node b){ if(a.s == b.s){ if(b.c) return false; if(a.c) return true; } return a.s<b.s; }); int tp=tpfn,fp=0,cnt=0; for(int i=1;i<=n;i++) { if(a[i].c) tp--; else cnt+=tp; } rld ans=(rld)cnt / (tpfn*tnfp); printf("%.9LF\n",ans); return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1;//(int)read(); for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); //while(cin>>n) work(); } return 0; }

2021/9/6
articleCard.readMore

ICPC2014西安 F Color

<a class="link" href="https://codeforces.com/gym/100548/problem/F" target="_blank" rel="noopener" >https://codeforces.com/gym/100548/problem/F 题目大意 $N$朵花排成一行,我们有$M$种颜色,可以给这些花涂色,保证相邻的花的颜色不同 求最后恰好使用了$k$种颜色的方案数。 推算 第一反应就是 $\complement_m^k\ast\ k\left(k-1\right)^{n-1}$ 当想了一下之后好像不对,这个公式算出来的是使用小于等于$k$种颜色的方案数量 然后推出如下公式 $\complement_k^x\ast x\left(x-1\right)^{n-1}$ 这个公式的含义是从$k$种颜色中再选出来$x$种使得相邻的格子不同色最后的颜色数小于等于$x$,每一个集合都有交,用容斥原理来处理 设 $S = F[x]=\complement_k^x\ast x\left(x-1\right)^{n-1}$ $ans=\complement_m^k\sum\left(-1\right)^{k-i}\complement_k^i\ast\ i\left(i-1\right)^{n-1}$ 记得开long long 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<bits/stdc++.h> #define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF const int N=(int)1e6+10,mod=1e9+7; int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,m,k; int inv[N]={0,1},c[N]={1}; int qpow(int a ,int b) { int ans=1; while(b) { if(b&1) ans=ans*a%mod; b>>=1; a=a*a%mod; } return ans; } void get_combine(int x) { for(int i=1;i<=k;i++) c[i]=(c[i-1]*(x-i+1)%mod)*inv[i]%mod; } inline int calc(int x) { return (c[x]*x%mod)*qpow(x-1,n-1)%mod; } void work() { n=read();m=read();k=read(); get_combine(m); int ans=c[k],ans1=0,flag=1; get_combine(k); for(int i=k;i>=1;i--) { ans1=(ans1+flag*calc(i)+mod)%mod; flag=-flag; } ans=ans*ans1%mod; cout<<ans<<endl; return; } signed main() { for(int i=2;i<N;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod; //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=(int)read(); for(signed Case=1; Case<=T; Case++) { printf("Case #%d: ",Case); work(); } return 0; }

2021/5/27
articleCard.readMore

Codeforces Round #715 (Div. 2)

<a class="link" href="https://codeforces.com/contest/1509/problem/A" target="_blank" rel="noopener" >A - Average Height 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 #include<bits/stdc++.h> //#define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int a[10000]; void work() { n=read(); for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++) if(a[i]%2)printf("%d ",a[i]); for(int i=1;i<=n;i++) if(a[i]%2==0)printf("%d ",a[i]); printf("\n"); return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=read(); for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); work(); } return 0; } <a class="link" href="https://codeforces.com/contest/1509/problem/B" target="_blank" rel="noopener" > B - TMT Document 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 #include<bits/stdc++.h> //#define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; string s; void work() { cin>>n>>s;int mx=0; stack<char> st; for(int i=0;i<(int)s.size();i++) { if(s[i]=='T') { st.push('T'); } if(s[i]=='M' ) { mx++; if(!st.empty()) { st.pop(); } else { cout<<"NO"<<endl; return; } } } while(mx--)st.pop(); if(!st.empty()) { cout<<"NO"<<endl; return; } for(int i=(int)s.size()-1;i>=0;i--) { if(s[i]=='T') { st.push('T'); } if(s[i]=='M' ) { mx++; if(!st.empty()) { st.pop(); } else { cout<<"NO"<<endl; return; } } } cout<<"YES"<<endl; return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T;cin>>T; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); work(); } return 0; } <a class="link" href="https://codeforces.com/contest/1509/problem/C" target="_blank" rel="noopener" >C - The Sports Festival 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 #include<bits/stdc++.h> #define int long long//__int128 #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int n=read(); vector<int> a(n); for (int i=0;i<n;i++)a[i]=read(); sort(a.begin(), a.end()); vector<vector<int> > dp(n, vector<int>(n)); for (int d=1;d<n;d++) for (int i=0;i+d<n;i++) dp[i][i+d]=min(dp[i][i+d-1],dp[i+1][i+d])+a[i+d]-a[i]; cout<<dp[0][n-1]<<endl; return; } signed main() { //ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //freopen(".in", "r", stdin);//freopen(".out", "w", stdout); signed T=1; for(signed Case=1; Case<=T; Case++) { //printf("Case %d: ",Case); work(); } return 0; } <a class="link" href="https://codeforces.com/contest/1509/problem/D" target="_blank" rel="noopener" >D - Binary Literature 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 #include <bits/stdc++.h> using namespace std; int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} int n; int a[3][501009]; string buildx(int x,int y,int cxx) { string tmp1=""; int ptr=1; for(int i = 1; i <= 2 * n; i++) if(a[y][i] == cxx) { while(ptr <= 2 * n && a[x][ptr] != a[y][i]) tmp1 += a[x][ptr++] ? "1" : "0"; tmp1 += a[y][i] ? "1" : "0"; ptr++; } else tmp1 += a[y][i] ? "1" : "0"; while(ptr <= 2 * n) tmp1 += a[x][ptr++] ? "1" : "0"; return tmp1; } string build(int x, int y) { string tmp1 =buildx(x,y,0),tmp2 =buildx(x,y,1); if(tmp1.size() < tmp2.size()) return tmp1; else return tmp2; } void work() { n = read(); for(int j = 0; j < 3; j++) for(int i = 1; i <= 2 * n; i++) scanf("%1d", &a[j][i]); string t1 = build(0, 1),t2 = build(0, 2),t3 = build(1, 2); if(t3.size() < t2.size()) swap(t3, t2); if(t2.size() < t1.size()) swap(t2, t1); cout << t1 << endl; } signed main() { int Case = read(); while(Case--) work(); return 0; } <a class="link" href="https://codeforces.com/contest/1509/problem/E" target="_blank" rel="noopener" >E - Almost Sorted 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 #include <bits/stdc++.h> #define int long long #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std; typedef long long ll; typedef long double rld; typedef unsigned long long ull; const rld eps = 1e-6; const int INF=0x3f3f3f3f;//0x3f3f3f3f3f3f3f3f;//LLINF int read(){int s=0,w=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=getchar();} return s*w;} int n,k; int a[100003]; void work() { n=read();k=read()-1; if (n <= 61 && (int)1<<(n-1) <=k) { printf("-1\n"); return; } iota(a+1, a+n+1, 1); for (int i=60,j;i>=0;i=j) { j = i-1; if (~(k>>i)&((int)1)) continue; while (j >= 0 && ((k>>j)&1))j--; reverse(a+n-1-i, a+n-j); } for (int i=1;i<=n;i++) printf("%lld%c",a[i]," \n"[i==n]); return; } signed main() { int T=read(); while(T--)work(); return 0; }

2021/4/17
articleCard.readMore

附中OJ从魔改HUSTOJ切换到Hydro啦!

直接放链接吧 <a class="link" href="https://tzhsoj.com/" target="_blank" rel="noopener" >https://tzhsoj.com/ 很早以前立过的Flag,要把高中学校的内网 OJ弄到公网上 这个暑假乘着回学校就顺手做了一下 原版OJ的题目在 <a class="link" href="https://tzhsoj.com/d/TZHSOJ_OLD/p" target="_blank" rel="noopener" >https://tzhsoj.com/d/TZHSOJ_OLD/p 题目被我删掉了一部分没有测试数据和出错的 入门用的SzNOI不再和原来的题目混杂在一起了 <a class="link" href="https://tzhsoj.com/d/SzNOI/p" target="_blank" rel="noopener" >https://tzhsoj.com/d/SzNOI/p 新换的Hydro系统比以前用HUSTOJ那套系统强太多了不是吗qwq,遗憾的是刷题记录不保留了 以及新的服务器上云了,正常压力下的服务器是校内的老E5,遇到突发高压情况(比如比赛)的时候将会动态切换申请腾讯云服务器来避免评测队列卡死 升级过程就写了个脚本自动导题目这样qwq

2021/3/6
articleCard.readMore

牛客 1041D MobileService

题目链接:<a class="link" href="https://ac.nowcoder.com/acm/contest/1041/D" target="_blank" rel="noopener" >Mobile Service 这个题最简单的想法就是直接把三个人的位置直接都放进状态,然而这样子的话复杂度到了$O(N*L^3)$实在是难以接受的复杂度。 我们发现,员工的位置只要知道两个没有去服务上一个p[i]的人,第三个人一定在p[i]位置,因此我们知道其复杂度变为了$O(N*L^2)$已经是可以接受的状态了 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 #include<bits/stdc++.h> //#include<bits/extc++.h> //#define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) push_back(x) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f,MOD=1e9+7; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} //void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} //警告,如非必须(如__int128),请不要使用快写 int l,n,ans=INF; int p[1003]={3};//让p[0]作为起始点=3 int c[203][203]; int f[1003][203][203]; void work() { scanf("%d%d",&l,&n);//l=read();n=read(); for(int i=1;i<=l;i++) for(int j=1;j<=l;j++) scanf("%d",&c[i][j]);//c[i][j]=read(); for(int i=1;i<=n;i++) scanf("%d",p+i);//p[i]=read(); mmst3f(f); f[0][1][2]=0; for(int i=0;i<n;i++)//p[0]已知为3,因此从0开始往i+1转移,然后得到结果 { for(int x=1;x<=l;x++) { for(int y=1;y<=l;y++) { int z=p[i],nxt=p[i+1],now=f[i][x][y]; if(x==y || x==z || y==z) continue; f[i+1][x][y]=min(f[i+1][x][y],now+c[z][nxt]);//让z去 f[i+1][z][y]=min(f[i+1][z][y],now+c[x][nxt]);//让x去 f[i+1][x][z]=min(f[i+1][x][z],now+c[y][nxt]);//让y去 } } } for(int x=1;x<=l;x++) for(int y=1;y<=l;y++) { //if(x==y || x==p[n] || y==p[n]) continue; //ans初始值==INF所以可以不用这句话 if(f[n][x][y]<ans) ans=f[n][x][y]; } cout<<ans<<endl; return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 然后写完发现这样子的话就要去掉#define int long long 那么这个其实是可以滚动数组缩内存的 1 2 3 4 5 6 7 8 9 10 11 12 13 14 for(int i=0;i<n;i++)//p[0]已知为3,因此从0开始往i+1转移,然后得到结果 { for(int x=1;x<=l;x++) { for(int y=1;y<=l;y++) { int z=p[i],nxt=p[i+1],now=f[i&1][x][y]; if(x!=nxt && y!=nxt) f[(i+1)&1][x][y]=min(f[(i+1)&1][x][y],now+c[z][nxt]);//让z去 if(z!=nxt && y!=nxt) f[(i+1)&1][z][y]=min(f[(i+1)&1][z][y],now+c[x][nxt]);//让x去 if(x!=nxt && z!=nxt) f[(i+1)&1][x][z]=min(f[(i+1)&1][x][z],now+c[y][nxt]);//让y去 f[i&1][x][y]=0x3f3f3f3f; } } }

2021/1/31
articleCard.readMore

2018第12届吉林省大学生程序设计竞赛(训练)

过程 开局一眼秒掉A,看了B发现就是个时区转换的语法题,ZJH自告奋勇写B题,然后我就开始和ZJQ去看C题了。大概四十分钟之后约莫是做出C了,就是个优先队列的水题==然后问ZJH有没有写好B,然后发现他写了四十分钟的时区转换语法题WA了。。。。。然后叫停ZJH,我自己来写时区转换,语法题一遍过。然后C思路和ZJQ已经论证完成,按思路写下来,在调样例的时候把Bug找到了,AC C题。写的时候ZJQ把概率DP推出来了,AC D题。接下来F发现自己以前做过了,全xor一起就行。 剩下一个计算机和E和贪心I题,以及线段树H感觉可以写(当然最后没写H) 推I题,三个人就我玩过完整的游戏王卡片,然后解释题面,发现是个分两种情况讨论的贪心,最后取 $max(ans1,ans2)$。让ZJQ给我造了组特殊的测试数据。然后思路对了就过了。 A 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; void work() { n=read(); int ans=(int)sqrt(n); if(ans%2==1) printf("odd\n"); else printf("even\n"); return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { printf("Case %lld: ",Case); work(); } return 0; } 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 55 56 57 58 59 60 #include<bits/stdc++.h> //#include<bits/extc++.h> //#define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int t,s,f; string m,s1,s2; void work() { scanf("%d:%d",&s,&f); cin>>m>>s1>>s2; if(m[0]=='A'&&s==12) s=0; else if(m[0]=='P'&&s!=12) s+=12; if(s1=="Moscow") s-=3; else if(s1=="Beijing") s-=8; else if(s1=="Washington") s+=5; if(s2=="Moscow") s+=3; else if(s2=="Beijing") s+=8; else if(s2=="Washington") s-=5; if(s<0) { printf("Yesterday "); s+=24; } else if(s>=24) { printf("Tomorrow "); s-=24; } else printf("Today "); if(s==0) printf("12:%02d AM\n",f); else if(s>=1&&s<12) printf("%d:%02d AM\n",s,f); else if(s==12) printf("12:%02d PM\n",f); else printf("%d:%02d PM\n",s-12,f); return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1; Case<=T; Case++) { printf("Case %d: ",Case); work(); } return 0; } C 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int fa[100003]; bool vis[100003]; priority_queue<pair<int,int> > q; void INIT() { n=read(); for(int i=1;i<=n;i++) fa[i]=i; while(!q.empty()) q.pop(); mmst0(vis); } int find_root(int x) { return fa[x]==x?x:fa[x]=find_root(fa[x]); } int unionset(int x,int y) { int xx=find_root(x),yy=find_root(y); if(xx>yy) swap(xx,yy); fa[xx]=yy; return yy; } void work() { for(int i=1;i<=n;i++) { q.push({read(),i}); } while(!q.empty() && q.top().first>1) { int fi=q.top().first,se=q.top().second; q.pop(); if(fi!=q.top().first) continue;//不能合并了 if(q.empty()) break; int u=q.top().second; q.pop(); int ee=unionset(se,u); q.push({fi-1,ee}); } if(q.size()<2) { printf("NO\n"); return; } int ee=q.top().second; for(int i=1;i<=n;i++) { if(find_root(i)==ee) vis[i]=true; else vis[i]=false; } printf("YES\n"); for(int i=1;i<=n;i++) cout<<vis[i]; cout<<endl; return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { printf("Case %lld: ",Case); INIT(); work(); } 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 #include<bits/stdc++.h> #define ll long long using namespace std; int read() { char c; int num,f=1; while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1; num=(int)(c-'0'); while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0'); return num*f; } int pp; double dp[250]; void work() { pp=read(); double p=pp/100.0; memset(dp,0,sizeof(dp)); dp[200]=1.0/p; for(int i=199;i>=4;i--) { double q=i/200.0; dp[i]=1+p*(1-q)*dp[min(i+4,200)]+(1-p)*dp[min(i+3,200)]; } return; } signed main() { int T=read(); for(int Case=1;Case<=T;Case++) { work(); printf("Case %d: %.10lf\n",Case,dp[4]); } 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 #include<bits/stdc++.h> using namespace std; int T,Case; double deta(double a,double b,double c) { double ans=b*b-4*a*c; ans=sqrt(ans); return ans; } int main() { cin>>T; double r,h,x0,y0,z0,vx,vy,vz; while(T--) { cin>>r>>h; cin>>x0>>y0>>z0; cin>>vx>>vy>>vz; double a=vx*vx+vy*vy-vz*vz*r*r/(h*h); double b=2*x0*vx+2*y0*vy+2*r*r*vz/h-2*z0*vz*r*r/(h*h); double c=x0*x0+y0*y0-r*r+2*r*r*z0/h-r*r*z0*z0/(h*h); double t2=(-b-deta(a,b,c))/(2*a); printf("Case %d: %.10lf\n",++Case,t2); } return 0; } F 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int n=read(),ans=0; for(int i=1;i<=n;i++) { ans^=max((int)0,min(i-2,read()-2)); } printf("%lld\n",ans); return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { printf("Case %lld: ",Case); work(); } 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 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 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, LL> pLL; typedef pair<LL, int> pLi; typedef pair<int, LL> pil;; typedef pair<int, int> pii; typedef unsigned long long uLL; #define lson rt<<1 #define rson rt<<1|1 #define lowbit(x) x&(-x) #define name2str(name) (#name) #define bug printf("*********\n") #define debug(x) cout<<#x"=["<<x<<"]" <<endl #define FIN freopen("D://Code//in.txt","r",stdin) #define IO ios::sync_with_stdio(false),cin.tie(0) const double eps = 1e-8; const int mod = 1e9 + 7; const int maxn = 1e5 + 7; const double pi = acos(-1); const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3fLL; char op[10]; int t, n, q, l, r, x; struct node { int l, r; int sum1, sum2; int vis, lazy1, lazy2, lazy3; }segtree[maxn<<2]; void push_up(int rt) { segtree[rt].sum1 = (segtree[lson].sum1 + segtree[rson].sum1) % mod; segtree[rt].sum2 = (segtree[lson].sum2 + segtree[rson].sum2) % mod; } void push_down(int rt) { if(!segtree[rt].vis) return; int x = segtree[rt].lazy1, y = segtree[rt].lazy2, z = segtree[rt].lazy3; segtree[rt].vis = segtree[rt].lazy1 = segtree[rt].lazy2 = 0, segtree[rt].lazy3 = 1; segtree[lson].vis = segtree[rson].vis = 1; segtree[lson].lazy1 = (1LL * segtree[lson].lazy3 * x % mod + segtree[lson].lazy1) % mod; segtree[rson].lazy1 = (1LL * segtree[rson].lazy3 * x % mod + segtree[rson].lazy1) % mod; segtree[lson].lazy2 = (1LL * z * segtree[lson].lazy2 % mod + y) % mod; segtree[rson].lazy2 = (1LL * z * segtree[rson].lazy2 % mod + y) % mod; segtree[lson].sum1 = ((1LL * segtree[lson].sum2 * z % mod * x % mod + 1LL * segtree[lson].sum1 * z % mod) % mod + 1LL * y * (segtree[lson].r - segtree[lson].l + 1) % mod) % mod; segtree[rson].sum1 = ((1LL * segtree[rson].sum2 * z % mod * x % mod + 1LL * segtree[rson].sum1 * z % mod) % mod + 1LL * y * (segtree[rson].r - segtree[rson].l + 1) % mod) % mod; segtree[lson].sum2 = 1LL * segtree[lson].sum2 * z % mod * z % mod; segtree[rson].sum2 = 1LL * segtree[rson].sum2 * z % mod * z % mod; segtree[lson].lazy3 = 1LL * segtree[lson].lazy3 * z % mod; segtree[rson].lazy3 = 1LL * segtree[rson].lazy3 * z % mod; } void build(int rt, int l, int r) { segtree[rt].l = l, segtree[rt].r = r; segtree[rt].lazy1 = segtree[rt].lazy2 = 0; segtree[rt].lazy3 = 1; segtree[rt].sum1 = segtree[rt].vis = 0, segtree[rt].sum2 = 1; if(l == r) return; int mid = (l + r) >> 1; build(lson, l, mid); build(rson, mid + 1, r); push_up(rt); } void update(int rt, int l, int r, int x) { if(segtree[rt].l == l && segtree[rt].r == r) { segtree[rt].vis = 1; segtree[rt].lazy2 = (10LL * segtree[rt].lazy2 + x) % mod; segtree[rt].lazy1 = (1LL * segtree[rt].lazy3 * x % mod + segtree[rt].lazy1) % mod; segtree[rt].sum1 = (10LL * ((1LL*segtree[rt].sum2 * x % mod + segtree[rt].sum1 % mod) % mod) % mod + x * (r - l + 1)) % mod; segtree[rt].sum2 = 100LL * segtree[rt].sum2 % mod; segtree[rt].lazy3 = 10LL * segtree[rt].lazy3 % mod; return; } push_down(rt); int mid = (segtree[rt].l + segtree[rt].r) >> 1; if(r <= mid) update(lson, l, r, x); else if(l > mid) update(rson, l, r, x); else { update(lson, l, mid, x); update(rson, mid + 1, r, x); } push_up(rt); } int query(int rt, int l, int r) { if(segtree[rt].l == l && segtree[rt].r == r) return segtree[rt].sum1; push_down(rt); int mid = (segtree[rt].l + segtree[rt].r) >> 1; if(r <= mid) return query(lson, l, r); else if(l > mid) return query(rson, l, r); else return (query(lson, l, mid) + query(rson, mid + 1, r)) % mod; } int main() { #ifndef ONLINE_JUDGE FIN; #endif // ONLINE_JUDGE scanf("%d", &t); int icase = 0; while(t--) { scanf("%d%d", &n, &q); build(1, 1, n); printf("Case %d:\n", ++icase); while(q--) { scanf("%s%d%d", op, &l, &r); if(op[0] == 'w') { scanf("%d", &x); update(1, l, r, x); } else printf("%d\n", query(1, l, r)); } } 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 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; const int maxn=1e5+3; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} struct Node { int value,pos; bool operator <(const Node &d)const { return value<d.value; } } node[maxn]; int T,Case,n,m,sum,sum1,ans,ans1,cnt;//cnt->防御个数 int a[maxn],b[maxn]; void work() { n=read();m=read(); ans=ans1=sum=sum1=cnt=0; for(int i=0; i<n; i++) { a[i]=read(); sum+=a[i]; } for(int i=0; i<m; i++) node[i].value=read(); for(int i=0; i<m; i++) { node[i].pos=read(); if(!node[i].pos) sum1+=node[i].value; if(node[i].pos) b[cnt++]=node[i].value; } sort(node,node+m); sort(a,a+n); bool flag=false; if(n>=m) { int i=n-1,j=m-1; for(; i>=0&&j>=0; i--) { if(node[j].value<=a[i]) j--; else break; if(!j) break; } if(!j) flag=true; } if(flag) { int j=0; for(int i=0; i<n&&j<cnt; i++) if(a[i]>=b[j]) { j++; sum-=a[i]; } if(j!=cnt) flag=0; else ans=sum-sum1; } int i=n-1,j=0; for(; i&&j<m; i--) { if(a[i]>=node[j].value) { if(!node[j].pos) ans1+=(a[i]-node[j].value); j++; } else break; } printf("Case %lld: %lld\n",++Case,max(ans,ans1)); return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; }

2021/1/13
articleCard.readMore

POJ2279 Mr. Young's Picture Permutations

蛮有意思的一个DP,数据很小,但是直接开的话是会直接爆掉 做这个题是因为最近比较无头苍蝇,就刷李煜东的书和Steps 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int s[6]; void work() { while(n=read()) { mmst0(s); for(int i=1;i<=n;i++) s[i]=read(); int f[s[1]+1][s[2]+1][s[3]+1][s[4]+1][s[5]+1]; mmst0(f); f[0][0][0][0][0]=1; for(int i=0;i<=s[1];i++) { for(int j=0;j<=s[2];j++) { for(int k=0;k<=s[3];k++) { for(int l=0;l<=s[4];l++) { for(int m=0;m<=s[5];m++) { if(i<s[1]) f[i+1][j][k][l][m]+=f[i][j][k][l][m]; if(j<s[2] && j<i) f[i][j+1][k][l][m]+=f[i][j][k][l][m]; if(k<s[3] && k<j) f[i][j][k+1][l][m]+=f[i][j][k][l][m]; if(l<s[4] && l<k) f[i][j][k][l+1][m]+=f[i][j][k][l][m]; if(m<s[5] && m<l) f[i][j][k][l][m+1]+=f[i][j][k][l][m]; } } } } } cout<<f[s[1]][s[2]][s[3]][s[4]][s[5]]<<endl; } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 然后发现貌似MS更简单易懂一些(废话,哪有MS比DP难理解的) 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 #include <bits/stdc++.h> #define ll long long using namespace std; int k; int len[6]; ll dp[31][16][11][8][7]; ll dfs(int a,int b,int c,int d,int e) { if(a<0||b<0||c<0||d<0||e<0)return 0; ll &opt=dp[a][b][c][d][e]; if(opt)return opt; opt=dfs(a,b,c,d,e-1); if(d>e)opt+=dfs(a,b,c,d-1,e); if(c>d)opt+=dfs(a,b,c-1,d,e); if(b>c)opt+=dfs(a,b-1,c,d,e); if(a>b)opt+=dfs(a-1,b,c,d,e); return opt; } int main() { while(scanf("%d",&k) && k) { memset(len,0,sizeof(len)); memset(dp,0,sizeof(dp)); dp[0][0][0][0][0]=1; for(int i=1; i<=k; i++) scanf("%d",len+i); printf("%lld\n",dfs(len[1],len[2],len[3],len[4],len[5])); } return 0; } 最后看lyd书的题解发现这玩意的数学名称叫做杨氏矩阵…….有公式算的,wdnmd 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 #include<bits/stdc++.h> #define ll long long using namespace std; ll n,cnt,x,y,tmp,num[40],sum[5200]; int main() { while(scanf("%lld",&n)&&n) { memset(sum,0,sizeof(sum)); cnt=0,x=1,y=1; for(int i=1; i<=n; i++)scanf("%lld",&num[i]); for(int i=1; i<=n; i++) for(int j=1; j<=num[i]; j++) { cnt++; for(int k=i+1; k<=n; k++) { if(num[k]>=j)sum[cnt]++; else break; } sum[cnt]+=num[i]-j+1; } for(int i=1; i<=cnt; i++) { x*=i; y*=sum[i]; tmp=__gcd(x,y); x/=tmp; y/=tmp; } printf("%lld\n",x/y); } return 0; }

2021/1/13
articleCard.readMore

找寻消失的《EVANGELION 超•現實》导演完全版

头图上的的Rei我记得是在我之前在一部叫做《EVANGELION 超•現實》的3DCG里看到的,当时我差点以为这个是真人拍摄,了解后才知道这个是一个国人做的3DCG,是建模渲染出来的 然而当我今天去再度寻找这部片子的时候,发现怎么变成了手机广告????? 然后才知道这部片子是作为广告片来拍摄,由于版权方的限制,不能讲我们之前先看到的导演完全版放出 然后我找到了原作者的VIMEO地址 <a class="link" href="https://vimeo.com/SOMEI" target="_blank" rel="noopener" >SOMEI 晟 - Creative Director & Motion Designer (vimeo.com) 在这里,原作者留下了一段话 原作者将短片放在了Adobe家的Behance上<a class="link" href="https://www.behance.net/gallery/99648687/EVANGELION-" target="_blank" rel="noopener" >EVANGELION 超•現實 on Behance 有趣的是作者对其进行了加密保护 the Password is hide in orignal anime. and I also left some clues somewhere. Maybe you can find it out :) 我擦,我不擅长找密码这种东西啊QAQ 发现其是插vimeo的iframe <a class="link" href="https://player.vimeo.com/video/433112136/" target="_blank" rel="noopener" >https://player.vimeo.com/video/433112136/ 于是乎尝试了几条很明显的如"IT CAN NOT BE TRUE"之后宣告放弃,以后有空再去找好了 拉到下面之后发现了一条作者留下的花絮短片,我寻思这个在B站也没了,那就先下下来存着好了 于是F12之,发现其实一个iframe,找到其src位于 <a class="link" href="https://player.vimeo.com/video/433293750" target="_blank" rel="noopener" >https://player.vimeo.com/video/433293750 打开后再次F12之,Ctrl+F搜索m3u8 得到js函数贴到VSC中格式化,截取其中有用的段落 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 (function (document, player) { var config = { "cdn_url": "https://f.vimeocdn.com", "vimeo_api_url": "api.vimeo.com", "request": { "files": { "dash": { "separate_av": true, "streams": [{ "profile": 165, "quality": "540p", "id": "f1554135-73c7-45a6-a49f-8bcb9aac9f1c", "fps": 25 }, { "profile": 174, "quality": "720p", "id": "d4b9e335-2533-4c96-94a4-3aece0566c90", "fps": 25 }, { "profile": 139, "quality": "240p", "id": "e600b29b-1ebd-4feb-94c8-8343c3d648e8", "fps": 25 }, { "profile": 175, "quality": "1080p", "id": "74330060-6592-42f8-bd57-a5e986e562d3", "fps": 25 }, { "profile": 164, "quality": "360p", "id": "2f43be78-072f-4a32-bd6f-36fdebbb7594", "fps": 25 }], "cdns": { "akfire_interconnect_quic": { "url": "https://159vod-adaptive.akamaized.net/exp=1610199664~acl=%2Fd1a70b97-5bd1-439e-aae0-61ab3907d52e%2F%2A~hmac=343de3a09d9771fadf03f7dde5bdd4291df62051164b9d84668498f980686358/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/f1554135,d4b9e335,e600b29b,74330060,2f43be78/master.json?base64_init=1", "origin": "gcs", "avc_url": "https://159vod-adaptive.akamaized.net/exp=1610199664~acl=%2Fd1a70b97-5bd1-439e-aae0-61ab3907d52e%2F%2A~hmac=343de3a09d9771fadf03f7dde5bdd4291df62051164b9d84668498f980686358/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/f1554135,d4b9e335,e600b29b,74330060,2f43be78/master.json?base64_init=1" }, "fastly_skyfire": { "url": "https://skyfire.vimeocdn.com/1610199664-0xf3ded9e996a5d034737a2c0a66008754707ec96a/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/f1554135,d4b9e335,e600b29b,74330060,2f43be78/master.json?base64_init=1", "origin": "gcs", "avc_url": "https://skyfire.vimeocdn.com/1610199664-0xf3ded9e996a5d034737a2c0a66008754707ec96a/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/f1554135,d4b9e335,e600b29b,74330060,2f43be78/master.json?base64_init=1" } }, "streams_avc": [{ "profile": 165, "quality": "540p", "id": "f1554135-73c7-45a6-a49f-8bcb9aac9f1c", "fps": 25 }, { "profile": 174, "quality": "720p", "id": "d4b9e335-2533-4c96-94a4-3aece0566c90", "fps": 25 }, { "profile": 139, "quality": "240p", "id": "e600b29b-1ebd-4feb-94c8-8343c3d648e8", "fps": 25 }, { "profile": 175, "quality": "1080p", "id": "74330060-6592-42f8-bd57-a5e986e562d3", "fps": 25 }, { "profile": 164, "quality": "360p", "id": "2f43be78-072f-4a32-bd6f-36fdebbb7594", "fps": 25 }], "default_cdn": "akfire_interconnect_quic" }, "hls": { "separate_av": true, "default_cdn": "akfire_interconnect_quic", "cdns": { "akfire_interconnect_quic": { "url": "https://159vod-adaptive.akamaized.net/exp=1610199664~acl=%2Fd1a70b97-5bd1-439e-aae0-61ab3907d52e%2F%2A~hmac=343de3a09d9771fadf03f7dde5bdd4291df62051164b9d84668498f980686358/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/e600b29b,f1554135,2f43be78,74330060,d4b9e335/master.m3u8", "origin": "gcs", "avc_url": "https://159vod-adaptive.akamaized.net/exp=1610199664~acl=%2Fd1a70b97-5bd1-439e-aae0-61ab3907d52e%2F%2A~hmac=343de3a09d9771fadf03f7dde5bdd4291df62051164b9d84668498f980686358/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/e600b29b,f1554135,2f43be78,74330060,d4b9e335/master.m3u8" }, "fastly_skyfire": { "url": "https://skyfire.vimeocdn.com/1610199664-0xf3ded9e996a5d034737a2c0a66008754707ec96a/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/e600b29b,f1554135,2f43be78,74330060,d4b9e335/master.m3u8", "origin": "gcs", "avc_url": "https://skyfire.vimeocdn.com/1610199664-0xf3ded9e996a5d034737a2c0a66008754707ec96a/d1a70b97-5bd1-439e-aae0-61ab3907d52e/sep/video/e600b29b,f1554135,2f43be78,74330060,d4b9e335/master.m3u8" } } }, "progressive": [{ "profile": 139, "width": 426, "mime": "video/mp4", "fps": 25, "url": "https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019901.mp4~hmac=a2a21ac4f29f32417702713c7b49a15d70b243a0866ffa23a9bcf314298cd9b7/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019901.mp4", "cdn": "akamai_interconnect", "quality": "240p", "id": "e600b29b-1ebd-4feb-94c8-8343c3d648e8", "origin": "gcs", "height": 214 }, { "profile": 165, "width": 960, "mime": "video/mp4", "fps": 25, "url": "https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019909.mp4~hmac=db591e6eb9ec358fc23788d6dcaafd28d570aaeb93ba185f66813289050b081d/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019909.mp4", "cdn": "akamai_interconnect", "quality": "540p", "id": "f1554135-73c7-45a6-a49f-8bcb9aac9f1c", "origin": "gcs", "height": 480 }, { "profile": 164, "width": 640, "mime": "video/mp4", "fps": 25, "url": "https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019938.mp4~hmac=29f3faf21f11e056ef6ea18be5bdb2b49b75b4855f6c1cd6bd62d261de5fba76/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019938.mp4", "cdn": "akamai_interconnect", "quality": "360p", "id": "2f43be78-072f-4a32-bd6f-36fdebbb7594", "origin": "gcs", "height": 320 }, { "profile": 175, "width": 2048, "mime": "video/mp4", "fps": 25, "url": "https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019906.mp4~hmac=759a3e3d960ec262f40d82368f6ff4e9775ea5cf64f41aa68e13b338cf15da12/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019906.mp4", "cdn": "akamai_interconnect", "quality": "1080p", "id": "74330060-6592-42f8-bd57-a5e986e562d3", "origin": "gcs", "height": 1024 }, { "profile": 174, "width": 1366, "mime": "video/mp4", "fps": 25, "url": "https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019898.mp4~hmac=b42b181b789c43780c8552f89aa509416b1d6988b51228af264c149bb9e4e29e/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019898.mp4", "cdn": "akamai_interconnect", "quality": "720p", "id": "d4b9e335-2533-4c96-94a4-3aece0566c90", "origin": "gcs", "height": 684 }] 发现有MP4链接直接可以下 <a class="link" href="https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019906.mp4~hmac=759a3e3d960ec262f40d82368f6ff4e9775ea5cf64f41aa68e13b338cf15da12/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019906.mp4" target="_blank" rel="noopener" >https://vod-progressive.akamaized.net/exp=1610199664~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F1658%2F17%2F433293750%2F1886019906.mp4~hmac=759a3e3d960ec262f40d82368f6ff4e9775ea5cf64f41aa68e13b338cf15da12/vimeo-prod-skyfire-std-us/01/1658/17/433293750/1886019906.mp4 完美wwwwwwwww 原版视频后来发现TapTap上有,F12找m3u8下载老一套了 说起来m3u8这玩意。。。令我印象最深刻的就是学堂在线的直播课那个小鹅通的互动直播间,直接F12,m3u8链接放在Console里面的,直接贴了下,有个买了2999算法网课的同学上次找我能不能下下来离线看然后无聊看了一下发现这个学堂在线直接裸的m3u8只分段不加密给我吓到了

2021/1/9
articleCard.readMore

HDUOJ 1271

其实是一道大水题,但是自己写的时候一开始居然没想到去枚举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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,a,b,c; int t[10000]; void work() { while(n=read()) { int cnt=0; for(int k=1;k<=n;k*=10)//枚举k,此处k为10^k { c=(n/k)/11;//去掉了后面k未之后就剩下前几位,即为c; b=n/k-c*11;//前k位减去11c就是b if((b!=0 || c!=0) && b<10)//b<10是存在进位 { a=(n-b*k-11*c*k)/2; if(2*a+b*k+11*c*k==n) t[++cnt]=a+b*k+c*k*10; } b--; if((b!=0 || c!=0) && b>=0) { a=(n-b*k-11*c*k)/2; if(2*a+b*k+11*c*k==n) t[++cnt]=a+b*k+c*k*10; } } if(!cnt) { printf("No solution.\n"); } else { sort(t+1,t+1+cnt,[](int a,int b){ return a<b; }); printf("%d",t[1]); for(int i=2;i<=cnt;i++) if(t[i]!=t[i-1]) printf(" %d",t[i]); printf("\n"); } } return; } /* N=2a+b*10^k+11c*10^k */ signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; }

2021/1/8
articleCard.readMore

ACM Steps 1-3

ACM Steps 不能跳着刷好蛋疼啊,非要去写水题 Section One 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int a,b; while(cin>>a>>b) { cout<<a+b<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int a,b; while(cin>>a>>b) { cout<<a+b<<endl; } return; } signed main() { int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int a,b; while(cin>>a>>b && (a || b)) { cout<<a+b<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int a,b; while(cin>>a>>b && (a || b)) { cout<<a+b<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int n=read(),ans=0; while(n--) ans+=read(); cout<<ans<<endl; return; } signed main() { int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} void work() { int ans=0,n; while(cin>>n) { ans=0; while(n--) ans+=read(); cout<<ans<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int a,b; void work() { while(cin>>a>>b) { cout<<a+b<<endl<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <bits/stdc++.h> using namespace std; int main() { int a, i, sum, j, N, n; cin >> N; while (N--) { sum = 0; cin >> n; while (n--) { cin >> a; sum += a; } cout << sum << endl; if (N != 0) { printf("\n"); } } return 0; } Section Two 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; void work() { while(n=read()) { int now=0,ans=0; while(n--) { int x=read(); if(x>now) ans+=(x-now)*6; if(x<now) ans+=(now-x)*4; ans+=5; now=x; } cout<<ans<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int a,b; void work() { while(scanf("%x%x", &a, &b) != EOF) printf("%d\n", a + b); return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include <bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x, y) memset(x, y, sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF = 0x3f3f3f3f; int read() { char c; int num, f = 1; while (c = (char)getchar(), !isdigit(c)) if (c == '-') f = -1; num = (int)(c - '0'); while (c = (char)getchar(), isdigit(c)) num = num * 10 + (int)(c - '0'); return num * f; } void prt(int x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) prt(x / 10); putchar((char)(x % 10 + '0')); } string s; int l, i, j, k, n; void work() { getline(cin, s); l = s.length(); for (k = 0, j = -1; k <= l; k++) { if (s[k] == ' ' || k == l) { for (i = k - 1; i > j; i--) cout << s[i]; if (k != l) cout << ' '; else cout << endl; j = k; } } return; } signed main() { int T = read(); for (int Case = 1; Case <= T; Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int r,e,c; void work() { r=read();e=read();c=read(); if(e-c>r)cout<<"advertise"<<endl; else if(e-c<r)cout<<"do not advertise"<<endl; else cout<<"does not matter"<<endl; return; } signed main() { int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int y,n; inline bool isleap(int year) { if ((year%4==0 && year%100!=0) || year%400==0) return true; return false; } void work() { y=read();n=read(); while(!isleap(y))y++; n--; while(n) { y+=4; if(isleap(y))n--; } cout<<y<<endl; return; } signed main() { int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int todec(int x,int y) { int ans=0,yx=1; while(x) { ans+=((x%10)*yx); yx*=y; x/=10; } return ans; } void work() { int n=0; while(cin>>n) { int sum=0; while(n--) { int x=read(); int y=read(); sum+=todec(x,y); } cout<<sum<<endl; getchar(); } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int ten(int m) { int sum=0; while(m) { sum+=m%10; m/=10; } return sum; } int twelve(int m) { int sum=0; while(m) { sum+=m%12; m/=12; } return sum; } int sixteen(int m) { int sum=0; while(m) { sum+=m%16; m/=16; } return sum; } inline bool equal(int a,int b,int c) { if(a==b && b==c) return true; return false; } void work() { for(int i=2992;i<=9999;i++) { if(equal(ten(i),twelve(i),sixteen(i))) cout<<i<<endl; } return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include <bits/stdc++.h> #define maxn 100 using namespace std; int b,n,m,sum; int a[maxn]; string s; int main() { while (cin >> n) { for (int i = 0; i < n; i++) { cout << "He/She is from "; cin >> s; string substr = s.substr(0, 2); int sub = (substr[0] - '0') * 10 + substr[1] - '0'; switch (sub) { case 33: cout << "Zhejiang"; break; case 11: cout << "Beijing"; break; case 71: cout << "Taiwan"; break; case 81: cout << "Hong Kong"; break; case 82: cout << "Macao"; break; case 54: cout << "Tibet"; break; case 21: cout << "Liaoning"; break; case 31: cout << "Shanghai"; break; } cout << ",and his/her birthday is on "; substr = s.substr(6, 4); string substrmonth = s.substr(10, 2); string substrday = s.substr(12, 2); cout << substrmonth << "," << substrday << "," << substr; cout << " based on the table." << endl; } } return 0; } Section Three 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 #include <bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x, y) memset(x, y, sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF = 0x3f3f3f3f; int read() { char c; int num, f = 1; while (c = (char)getchar(), !isdigit(c)) if (c == '-') f = -1; num = (int)(c - '0'); while (c = (char)getchar(), isdigit(c)) num = num * 10 + (int)(c - '0'); return num * f; } void prt(int x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) prt(x / 10); putchar((char)(x % 10 + '0')); } int n; int a[1003], b[1003]; void work() { while (n = read()) { for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) b[i] = read(); sort(a + 1, a + 1 + n, [](int x, int y) { return x > y; }); sort(b + 1, b + 1 + n, [](int x, int y) { return x > y; }); int ji = 0, i = 1, j = 1, sum = 0, k = n, f = n; while (ji < n) { if (b[j] > a[i]) { sum -= 200; j++; k--; ji++; continue; } //如果king的比tian的快马快 用tian的慢马对king的快马 if (b[j] == a[i]) { //如果相等 if (b[f] < a[k]) { f--; k--; sum += 200; ji++; continue; } //看两人的慢马 tian的慢马比king的慢马快则比 if (b[j] > a[k]) { sum -= 200; k--; j++; ji++; } else { k--; j++; ji++; } continue; } if (b[j] < a[i]) { sum += 200; j++; i++; ji++; continue; } //如果tian的比king的快马快 直接比 } cout << sum << endl; } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T = 1; //read(); for (int Case = 1; Case <= T; Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,m,g,sum; int p[13]; struct stu { string s; int pts; }ks[1003]; void INIT() { } void work() { while(n=read()) { for(int i=1;i<=n;i++) ks[i].pts=0; m=read();g=read();sum=0; for(int i=1;i<=m;i++) p[i]=read(); for(int nx,i=1;i<=n;i++) { cin>>ks[i].s; nx=read(); while(nx--)ks[i].pts+=p[read()]; if(ks[i].pts>=g)sum++; } sort(ks+1,ks+1+n,[](stu a,stu b){ if(a.pts!=b.pts) return a.pts>b.pts; else return a.s<b.s; }); cout<<sum<<endl; for(int i=1;i<=n;i++) { if(ks[i].pts>=g) cout<<ks[i].s<<" "<<ks[i].pts<<endl; else break; } } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; struct jian { int a,b; }jx[53]; void work() { n=read(); for(int i=1;i<=n;i++) { jx[i].a=read(); jx[i].b=read(); } sort(jx+1,jx+1+n,[](jian a,jian b){return a.a<b.a;}); for(int a,b,i=1;i<=n;i++) { a=jx[i].a;b=jx[i].b; for(int j=1;j<=b;j++) { for(int i=1;i<=a;i++) { if(i==1)cout<<">+"; else if(i==a)cout<<"+>"<<endl; else cout<<'-'; } } cout<<endl; } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int a[13]; void work() { n=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+1+n); cout<<a[2]<<endl; return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; int a[103],b[103]; void work() { while(n=read()) { for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++)b[i]=read(); int ax=0,bx=0; sort(a+1,a+1+n); sort(b+1,b+1+n); for(int i=1;i<=n;i++) { if(a[i]>b[i])ax+=2; else if(a[i]<b[i])bx+=2; else ax++,bx++; } printf("%lld vs %lld\n",ax,bx); } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n; struct wood { int l,w; }a[5003]; bool vis[5003]; void work() { n=read(); mmst0(vis); for(int i=1;i<=n;i++) { a[i].l=read(); a[i].w=read(); } sort(a+1,a+1+n,[](wood a,wood b){ if(a.l!=b.l) return a.l<b.l; else return a.w<b.w; }); int ans=0,sum=0; while(sum<n) { int tl=0,tw=0; ans++; for(int i=1;i<=n;i++) { if(a[i].l>=tl && a[i].w>=tw && (!vis[i])) { vis[i]=true; sum++; tl=a[i].l; tw=a[i].w; } } } cout<<ans<<endl; return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x,0,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int a[5]; void work() { cin>>a[1]>>a[2]>>a[3]>>a[4]; while(true) { sort(a+1,a+4); int last1=a[1]; bool fst=true; do { if(a[1]==0) continue; if(last1!=a[1] || fst) { if(!fst)cout<<endl; last1=a[1]; fst=false; cout<<a[1]<<a[2]<<a[3]<<a[4]; } else cout<<" "<<a[1]<<a[2]<<a[3]<<a[4]; } while (next_permutation(a+1,a+5)); cout<<endl; cin>>a[1]>>a[2]>>a[3]>>a[4]; if(!a[1] && !a[2] && !a[3] && !a[4]) break; else cout<<endl; } return; } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; } 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 #include <bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define mmst0(x) memset(x, 0, sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF = 0x3f3f3f3f; int read() { char c; int num, f = 1; while (c = (char)getchar(), !isdigit(c)) if (c == '-') f = -1; num = (int)(c - '0'); while (c = (char)getchar(), isdigit(c)) num = num * 10 + (int)(c - '0'); return num * f; } void prt(int x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) prt(x / 10); putchar((char)(x % 10 + '0')); } void work() { int sn, s[1000], tsn, m, range, score, i, j; while (scanf("%d", &sn) != EOF) { range = 1; i = 0; while (scanf("%d%d", &tsn, &m), tsn || m) { if (tsn == sn) score = m; s[i++] = m; } for (j = 0; j < i; j++) if (s[j] > score) range++; printf("%d\n", range); } } signed main() { //ios::sync_with_stdio(false);cin.tie(NULL); int T = 1; //read(); for (int Case = 1; Case <= T; Case++) { //printf("Case #%d: ",Case); work(); } return 0; }

2021/1/5
articleCard.readMore

ICPC2020济南A Matrix Equation

这个题算是个翻车题,做出来可以铁翻银的,燃鹅翻车在这个题上了 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 #include<bits/stdc++.h> //#include<bits/extc++.h> #define int long long //#define int __int128 #define ull unsigned long long #define MMST(x,y) memset(x,y,sizeof(x)) using namespace std; //using namespace __gnu_pbds; const int INF=0x3f3f3f3f; const int MOD=998244353; int read(){char c;int num,f=1;while(c=(char)getchar(),!isdigit(c))if(c=='-')f=-1;num=(int)(c-'0');while(c=(char)getchar(),isdigit(c))num=num*10+(int)(c-'0');return num*f;} void prt(int x){if(x<0){putchar('-');x=-x;}if(x>9)prt(x/10);putchar((char)(x%10+'0'));} int n,ans=1; int a[203][203],b[203][203]; bitset<203> bit[203]; void insert(bitset<203> x) { for(int i=1;i<=n;i++) if (x[i]) { if(!bit[i].count()) { bit[i]=x; break; } x^=bit[i]; } } void work() { cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>b[i][j]; for(int t=1;t<=n;t++) { for(int i=1;i<=n;i++) bit[i]=0; for(int i=1;i<=n;i++) { bitset<203> x=0; for(int j=1;j<=n;j++) x[j]=a[i][j]; x[i]=x[i]^b[i][t]; insert(x); } for(int i=1;i<=n;i++)if(!bit[i].count()) ans=(ans<<1)%MOD; } cout<<ans<<endl; return; } signed main() { int T=1;//read(); for(int Case=1;Case<=T;Case++) { //printf("Case #%d: ",Case); work(); } return 0; }

2020/12/31
articleCard.readMore

再见2020

济南站打完,我的2020年学习生活算是真正的结束了,剩下的约莫就是等待31号的早晨飞杭州回浙江了。 从EE转专业到了CS算是满足了自己的一个心愿了,要说过的不好吧,其实也海星。反正刷绩点对我来说没什么太大的意义罢了,转专业转了也就懒得刷了。 嘛,要说最大的遗憾吧,算是济南站读错题了,开局真的挺顺利的,不过四题Ag-Fe也是离谱。如果没读错题今天大概率可以Ag的。不过济南站主办方的福利极佳,以及济南站的衣服好看,卫衣里面还是毛绒绒的qwq,虽然我还是比较想要志愿者的蓝色卫衣。 大概我21年我还能再打一年再退役吧,希望2021年的疫情能够稳定。 以及寒假,希望我能做的能够对得起自己吧。

2020/12/27
articleCard.readMore

为GPW DIY一个Qi充电模块

整了一个罗技自家的PowerPlay,然而用下来之后感觉这玩意鼠标垫面积太小了,打星际的时候拉不开(DPI 1650 游戏内速度49%) 所以拿底盖改装了一个Qi充电套件qwq

2020/12/25
articleCard.readMore

ICPC2020上海游记

嘛,没想到我的ICPC之旅的第一站就那么卷,开局南师大6S AC最速传说,然后被dq了,开场签到很稳,和文哥直接推出了公式,和黄总写的暴力程序直接对拍正确A掉签到题 然后在开B和M之间纠结,队伍里就我用过git,就看懂了M的题意,然后和黄总一起构树两次DFS写M,文哥没用过git就没看懂git的忽略操作的意思,文哥去开了B,然后M构树挂了三四次浪费了4H,然后文哥来看了M,这次告诉文哥,git的忽略在这题就理解成删除,文哥上手M题,直接30MIN给过了,文哥·工大唯一真神。到这里已经来不及做B了,实际上文哥B的思路是正确的。 感觉这场我有点演==挂件模式全开,我的构树是竞赛少用的指针+vector构树,然后和黄总的构树代码完全不兼容,后来想到了Trie,但是用的模板好像是假的== 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 #include<bits/stdc++.h> using namespace std; const int maxn = 1e3+3; int cnt,n,m; char a[maxn][maxn] ,b[maxn][maxn]; int main() { cin >> n >> m; for(int i=0;i<n;i++)scanf("%s",a+i); for(int i=0;i<n;i++)scanf("%s",b+i); for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(a[i][j]!=b[i][j]) cnt++; if(cnt>n*m/2) { for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(a[i][j]=='.') a[i][j]='X'; else a[i][j]='.'; } for(int i=0;i<n;i++) printf("%s\n",a+i); 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 #include<bits/stdc++.h> using namespace std; double n,p1,v1,p2,v2,l,r,mid; double calc(double n,double p,double v) { return min(n-p+n,p+n)/v; } void work() { scanf("%lf%lf%lf%lf%lf",&n,&p1,&v1,&p2,&v2); double ans=min(calc(n,p1,v1),calc(n,p2,v2)); if (p1>p2) swap(p1,p2),swap(v1,v2); ans=min(ans,max(p2/v2,(n-p1)/v1)); l=p1,r=p2; for (int i=1; i<=100; i++) { mid=(l+r)/2.0; double ans1=calc(mid,p1,v1),ans2=calc(n-mid,p2-mid,v2); ans=min(ans,max(ans1,ans2)); if (ans1>ans2) r=mid; else l=mid; } printf("%.10lf\n",ans); } int main() { int T; scanf("%d",&T); while (T--)work(); } G 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<bits/stdc++.h> using namespace std; #define int long long const int N = 2e5+100; signed main() { int n; scanf("%lld",&n); int ans=(n-(n/3))*(n/3)+(n/3)*(n/3-1)/2; cout<<ans<<endl; 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 31 32 #include<bits/stdc++.h> #define MN 500 using namespace std; typedef long double ld; const ld pai = acos(-1); int n,m; ld len,ans; ld f[MN+5]; int main() { scanf("%d%d",&n,&m); ld d = pai/m; for(int i=1;i<m;i++) { if(i*d>2)len+=2; else len+=i*d; } len*=2; len+=2; for(int i=1;i<=n;i++) { f[i]=len*i+2*m*(i-1)+1+f[i-1]; ans += m*(f[i]*2-i*len); } if(m==1) ans-=(2+2*n)*n/2; printf("%.10lf\n",(double)ans); } M 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 #include<bits/stdc++.h> using namespace std; int n,m; int vis[10100]; int qian[10100]; int z[10100]; int shu[10100]; int vi[10100]; int o[10100]; void init(){ memset(vis,0,sizeof(vis)); memset(qian,0,sizeof(qian)); memset(z,0,sizeof(z)); memset(shu,0,sizeof(shu)); // memset(vis,0,sizeof(vis)); memset(vi,0,sizeof(vi)); memset(o,0,sizeof(o)); } struct node{ int i; int x; }; int main() { int T ; cin>>T; while(T--){ cin>>n>>m; init(); map<string ,int > mp; int tot=1; for(int i=1;i<=n;i++){ string str; cin>>str; str=str+"/"; string s; int flag=0; string p; for(int j=0;j<str.size();j++){ if(str[j]=='/'&&flag==0){ flag=1; p=s; if(mp[s]==0){ mp[s]=++tot; qian[tot]=1; z[tot]=1; } } else if(str[j]=='/'&&flag==1){ if(mp[s]==0){ mp[s]=++tot; qian[tot]=mp[p]; z[tot]=1; shu[mp[p]]++; } p=s; } s+=str[j]; } } for(int i=1;i<=m;i++){ string str; cin>>str; str=str+"/"; string s; int flag=0; string p; for(int j=0;j<str.size();j++){ if(str[j]=='/'&&flag==0){ flag=1; p=s; if(mp[s]==0){ mp[s]=++tot; qian[tot]=1; z[tot]=0; } } else if(str[j]=='/'&&flag==1){ if(mp[s]==0){ mp[s]=++tot; qian[tot]=mp[p]; z[tot]=0; shu[mp[p]]++; } p=s; } s+=str[j]; } } // for(int i=1;i<=tot;i++){ // cout<<i<<" "; // } // cout<<endl; // for(int i=1;i<=tot;i++){ // cout<<qian[i]<<" "; // } // cout<<endl; // for(int i=1;i<=tot;i++){ // cout<<shu[i]<<" "; // } // cout<<endl; queue<node> p; int ans=0; for(int i=2;i<=tot;i++){ if(shu[i]==0){ if(z[i]==1) { ans++; p.push(node{i,z[i]}); } } } // cout<<p.size()<<endl; // cout<<ans<<endl; while(!p.empty()){ node t=p.front(); p.pop(); vi[qian[t.i]]++; // o[qian[t.i]]+=t.x; // cout<<t.i<<" "<<t.x<<endl; if(vi[qian[t.i]]==shu[qian[t.i]]&&qian[t.i]!=1){ ans-=shu[qian[t.i]]; ans++; p.push(node{qian[t.i],0}); } } cout<<ans<<endl; } }

2020/12/13
articleCard.readMore

让微软账户只输入名或姓

微软账户有一个很蛋疼的地方就是设置名字不能只设置名/姓 于是我想到了使用零宽连字来填充姓,这样就可以让微软账户就一个ID了 随便找一个零宽连字加密的东西 比如 <a class="link" href="https://zhuanlan.zhihu.com/p/87919817" target="_blank" rel="noopener" >https://zhuanlan.zhihu.com/p/87919817 随便写点什么,填进去就好了

2020/12/9
articleCard.readMore

Codeforces Round #664 (Div. 2)

<a class="link" href="https://codeforces.com/contest/1395/problem/A" target="_blank" rel="noopener" >Boboniu Likes to Color Balls 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include<iostream> using namespace std; int T,r,g,b,w; int main() { cin>>T; while(T--) { cin>>r>>g>>b>>w; int cnt2,cnt=(r&1)+(g&1)+(b&1)+(w&1); if(r>0 && g>0 && b>0)cnt2=((r-1)&1)+((g-1)&1)+((b-1)&1)+((w+3)&1); else cnt2=2; if(cnt<=1 || cnt2<=1)cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; } <a class="link" href="https://codeforces.com/contest/1395/problem/B" target="_blank" rel="noopener" >Boboniu Plays Chess 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<iostream> using namespace std; int n,m,x,y; bool vis[103][103]; inline void out(int x,int y) { cout<<x<<" "<<y<<endl; } int main() { cin>>n>>m>>x>>y; vis[x][y]=vis[1][y]=vis[1][1]=true; out(x,y); out(1,y); out(1,1); for(int i=1;i<=n;i++) { if(i%2) { for(int j=1;j<=m;j++) { if(!vis[i][j]) { vis[i][j]=true; out(i,j); } } } else { for(int j=m;j>=1;j--) { if(!vis[i][j]) { vis[i][j]=true; out(i,j); } } } } return 0; } <a class="link" href="https://codeforces.com/contest/1395/problem/C" target="_blank" rel="noopener" >Boboniu and Bit Operations 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 #include<cstdio> using namespace std; int pa[209],pb[209]; int a[209][40],b[209][40],n,m,sum; bool vis[209][209]; void readx(int r,char q) { int x,cnt; for(int i=1;i<=r;i++) { scanf("%d",&x); cnt=32; if(q=='a')pa[i]=x; else pb[i]=x; while(x) { if(q=='a')a[i][cnt--]=x&1; else b[i][cnt--]=x&1; x>>=1; } } } int main() { scanf("%d%d",&n,&m); readx(n,'a'); readx(m,'b'); for(int k=0; k<=32; k++) { bool q=true,t; for(int i=1; i<=n; i++)if(a[i][k]) { t=false; for(int j=1; j<=m; j++) if(!b[j][k] && !vis[i][j]) t=true; q&=t; } if(!q)continue; for(int i=1; i<=n; i++) if(a[i][k]) { bool flag=0; for(int j=1; j<=m; j++) if(!b[j][k] && !vis[i][j]) flag=true; if(flag) for(int j=1; j<=m; j++) vis[i][j]|=(b[j][k]==1); } } for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if(!vis[i][j]) { sum|=pa[i]&pb[j]; break; } printf("%d\n",sum); return 0; } <a class="link" href="https://codeforces.com/contest/1395/problem/D" target="_blank" rel="noopener" >Boboniu Chats with Du 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<cstdio> #include<vector> #include<algorithm> using namespace std; int n,d,m; int a[100003]; long long res; long long sum[2][100003]; vector<int> b[2]; int main() { scanf("%d%d%d",&n,&d,&m); for (int i=1;i<=n;i++) { scanf("%d",a+i); b[a[i]>m].emplace_back(a[i]); } sort(b[0].begin(), b[0].end()); reverse(b[0].begin(), b[0].end()); sum[0][0]=0; for (signed int i=0; i<(int)b[0].size(); i++)sum[0][i+1]=sum[0][i]+b[0][i]; sort(b[1].begin(), b[1].end()); reverse(b[1].begin(), b[1].end()); sum[1][0]=0; for (int i=0; i<(int)b[1].size(); i++)sum[1][i+1]=sum[1][i]+b[1][i]; res = sum[0][b[0].size()]; for (int i = 0;i<(int)b[1].size();i++) { if (i*(d+1)+1 > n) break; int rest = min((int)b[0].size(), n-i*(d+1)-1); res = max(res, sum[1][i+1]+sum[0][rest]); } printf("%lld\n",res); return 0; }

2020/8/14
articleCard.readMore

Ventoy:一个有趣的方式来制作USB启动U盘

先上GitHub链接: <a class="link" href="https://github.com/ventoy/Ventoy" target="_blank" rel="noopener" >https://github.com/ventoy/Ventoy 我一直认为做个USB启动盘,就应该像这样,丢个原版镜像文件进去就可以选择启动,而不是用PE之类的RZ玩意,终于找到一个我认为不错的工具了,以前我一直是在用GRUB4DOS/GRUB2来启动ISO镜像文件的 贴一下GitHub的介绍吧 Ventoy Ventoy is an open source tool to create bootable USB drive for ISO files. With ventoy, you don’t need to format the disk again and again, you just need to copy the iso file to the USB drive and boot it. You can copy many iso files at a time and ventoy will give you a boot menu to select them. Both Legacy BIOS and UEFI are supported in the same way. 200+ ISO files are tested. A “Ventoy Compatible” concept is introduced by ventoy, which can help to support any ISO file. See <a class="link" href="https://www.ventoy.net/" target="_blank" rel="noopener" >https://www.ventoy.net for detail. Features 100% open source Simple to use Fast (limited only by the speed of copying iso file) Directly boot from iso file, no extraction needed Legacy + UEFI supported in the same way UEFI Secure Boot supported (since 1.0.07+) Notes ISO files larger than 4GB supported Native boot menu style for Legacy & UEFI Most type of OS supported, 200+ iso files tested Not only boot but also complete installation process “Ventoy Compatible” concept Plugin Framework Readonly to USB drive during boot USB normal use unafftected Data nondestructive during version upgrade No need to update Ventoy when a new distro is released

2020/4/30
articleCard.readMore

使用OpenCV将视频转换为Terminal中的字符画

很简单的OpenCV入门练习小项目 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import cv2 #OpenCV import os #用于操作终端,比如清cls a_char=list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ") #将ASCII字符以灰度来排序 char_len=len(a_char) Video=cv2.VideoCapture("OP.mp4") output=[] if Video.isOpened(): rval,frame=Video.read() while rval: gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) text="" for i in gray: for j in i: text += a_char[int(j/256*char_len)] text += "\n" output.append(text) rval,frame=Video.read() for f in output: os.system("cls") print(f)

2020/3/18
articleCard.readMore

我用于算法竞赛的 Vim 配置

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 set noundofile set nobackup set nocompatible set smartindent set nu set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab set cin set autoindent set cursorline let mapleader = "\<Space>" syntax on filetype plugin indent on autocmd BufNewFile,BufRead *.cpp exec ":call SetCppFile()" autocmd BufNewFile,BufRead *.c exec ":call SetCppFile()" autocmd BufNewFile,BufRead *.py exec ":call SetPythonFile()" " autocmd BufNewFile,BufRead *.rs exec ":call SetRustFile()" command! -nargs=0 -bar W exec "w" command! -nargs=0 -bar Wq exec "wq" if has('win32') autocmd GUIEnter * call libcallnr($VIM."\\vimfiles\\vimtweak.dll", "SetAlpha", 255) set enc=utf-8 set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 set langmenu=zh_CN.UTF-8 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim language messages zh_CN.utf-8 set guifont=Consolas:h12 set guifontwide=YaHei\ Consolas\ Hybrid elseif has('unix') set guifont=Monaco\ 12 elseif has('mac') set guifont=Monaco\ 12 endif if has('clipboard') if has('unnamedplus') set clipboard=unnamed,unnamedplus else " On mac and Windows, use * register for copy-paste set clipboard=unnamed endif endif function SetCppFile() packadd termdebug map <F9> : make <CR> map <F10> : call Run() <CR> " map <F11> : Termdebug %<.run <CR> map <F8> : call FormatCode()<CR> map <F12> : call Build_And_Run() <CR> set makeprg=g++\ \"%\"\ -o\ \"%<.exe\"\ -g\ -O2 endfunction function SetPythonFile() map <F9> : ! python % <CR> endfunction function Run() if &filetype == 'cpp' || &filetype == 'c' if has('win32') exec "! %<.exe" elseif has('unix') exec "!time ./%<.exe" endif elseif &filetype == 'sh' exec "!bash %" endif endfunction function Build_And_Run() exec "make" call Run() endfunction func! FormatCode() exec "w" if &filetype == 'cpp' || &filetype == 'c' || &filetype == 'h' exec "!astyle --style=java -n \"%\"" exec "e \"%\"" endif endfunc call plug#begin('$VIM/vimfiles/plugged') Plug 'junegunn/vim-easy-align' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'luochen1990/rainbow' Plug 'Valloric/ListToggle' Plug 'rakr/vim-one' Plug 'roman/golden-ratio' Plug 'jiangmiao/auto-pairs' call plug#end() if has('gui_running') set lines=54 columns=90 set guioptions-=T set background=dark let g:one_allow_italics = 1 colorscheme one endif let g:rainbow_active = 1

2019/12/29
articleCard.readMore

迷茫之路

致来自2022年后来的你:这篇文章狗屁不通,请寄存脑子之后再看 不知道为什么开始写这篇回忆,开始写一些狗屁不通,随心所欲的文字。 现在是NOIP2019结束的日子emmmm,现在叫做CSP 大概是我正式离开算法竞赛的一年后,2019年,我大一,也没想着打ACM 退役确实是一件难受的事情。那种感觉我至今还记得,曾经的我一直觉得,在机房就是我的全世界,退役之后有时候就会感到很迷茫,甚至连学习的目标也找不到,当然,这可能会涉及到一些我的情感方面,分手什么的也将我变得比以前冷漠了些吧。 不过在现在回想,我们喜欢的可能不是OI这件事情本身,而是和一群追寻梦想的孩子一起,做些“我觉得我要为了她献身,哪怕是提前预支我们的未来” 我觉得我们曾经高中机房里的同学们,若是用学OI的精力投身文化课的话,会怎样呢 文化课虽说令人烦恼,但在一年的时间里苦中作乐,就可以进入大学的生活了,可以去做一些令自己愉快的事情啦。 到了大学,买了相机,喜欢上了拍风景,说实话,到了大学之后,我大概是有空闲时间就会去在新的城市里寻找着没有见过的风景。心态比高考的时候平和很多。当然,我说实话我在大学荒废了很多东西。大学第一学期的文化课没有好好去学习什么。 回忆一下竞赛到底给我带来了什么?一切都是只能在高中三年罢了吧。到了大学,一切如过眼烟云,实际上竞赛只留给我一种精神上的鼓励罢了。是的啊,喜欢一件事,为之狂奔,沿途风景再美,也不能比的起你的灵魂所向。这就是青春的感觉吧! 退役了之后无数次回忆OI,其实说实话回忆的是机房里的生活,也就是回忆热血的过去。 未来不可预知,人类是宇宙中的沙砾,我们在蓝天中流浪,陪伴着我们的心灵家园。我们到底是为了什么呢存在于这个时间,这个世界之中? 答案不可预知,起码在我们现在的科学中不可预知。 但是人类依旧一往直前。我们依旧会一往直前。

2019/11/19
articleCard.readMore

BCM20702A1在Ubuntu下无法连接设备

给X230换了张DW1550网卡,其实就是戴尔版的BCM94352网卡== 试了一下刷白名单BIOS和Coreboot,感觉Coreboot还是有点问题,还是用魔改白名单BIOS了 然后屏蔽51脚,拆掉机器自带的蓝牙模块(BCM92070MD),网卡在Ubuntu里面安装bcmwl-kernel-source正常工作,然后遇到一个蛇皮问题,就是虽然网卡附带的蓝牙(BCM20702A1)识别正常,但是很蛋疼的是可以和设备配对但是不能连接== 看样子是缺少了文件== 最后从redhat的bug报告上面找到了解决方法==,askUbuntu上面都没啥软用,redhat还是牛逼 <a class="link" href="https://bugzilla.redhat.com/show_bug.cgi?id=1264153" target="_blank" rel="noopener" >https://bugzilla.redhat.com/show_bug.cgi?id=1264153 上面说的蛮麻烦的==,要从Windows驱动里面掏出文件然后转格式== 实际上Github上有大佬已经帮忙转制好了qwq 1 sudo wget --tries=3 --timeout=120 https://github.com/winterheart/broadcom-bt-firmware/raw/master/brcm/BCM20702A1-413c-8143.hcd -P /lib/firmware/brcm reboot 一条指令完事~\ (≧▽≦) /~ 当然,如果你的机器也出现这个问题的话,你要根据你序号的不同选择不同的文件==

2019/11/4
articleCard.readMore

MATLAB学习笔记

MATLAB的数组访问好鬼畜啊,全下标是符合各种编程语言的先行再列,然后单下标(索引值)居然是先列再行==绝了 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 >> A=[1 2 3 4;5 6 7 8] A = 1 2 3 4 5 6 7 8 >> A(1,3) ans = 3 >> A(3) ans = 2 元胞数组的创建于连接 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 >> a(1,1)={'mdzz'} a = 'mdzz' >> a(1,2)={ones(3)} a = 'mdzz' [3x3 double] >> a{2,1}='qwq' a = 'mdzz' [3x3 double] 'qwq' [] >> a{2,2}='matlab' a = 'mdzz' [3x3 double] 'qwq' 'matlab' >> b=a b = 'mdzz' [3x3 double] 'qwq' 'matlab' >> c=[a b] c = 'mdzz' [3x3 double] 'mdzz' [3x3 double] 'qwq' 'matlab' 'qwq' 'matlab' >> c=[a;b] c = 'mdzz' [3x3 double] 'qwq' 'matlab' 'mdzz' [3x3 double] 'qwq' 'matlab' >> b=cell(2,3) b = [] [] [] [] [] []

2019/10/28
articleCard.readMore

在Ubuntu上启用指纹识别

写着一篇的原因是中文网络上对于fprintd的教程已经严重与现在的Ubuntu脱节== 网上写的是真的麻烦,实际上非常简单 1 sudo apt install -y fprintd libpam-fprintd 执行之后你就可以直接重启,然后用图形化设置界面录入指纹或者执行fprintd-enroll 就那么简单,你可以用指纹来登录Ubuntu了。但是你现在暂时不能用它来通过sudo的密码验证 因此你还需要 1 sudo pam-auth-update 然后在里面勾选上指纹识别,reboot即可。 百度上说的是真的麻烦==,实际上只要两条指令就好了 最后附上我的配置 Ubuntu 18.04 从初中开始陪伴我的ThinkPad X230

2019/10/27
articleCard.readMore

更换博客域名到spaceless.me

2022更新:这个域名不再使用了 就是换了个域名qwq

2019/9/1
articleCard.readMore

在凄惨红H61主板上用NVMESSD

主要是垃圾NAS的系统U盘出问题了,然后买个个16G傲腾和PCIEx16 to M2接口的转接卡 然而H61并没有原生的NVME支持= =只能改BIOS来解决这个问题 我改BIOS用的是UEFITool,网上很多人用的是MMTool,然而这东西不支持Win10并且在Win7下打开凄惨红的BIOS报错 在查找中选择Text然后输入CSMCORE,在Messages里面点击查找信息即可跳转 然后向下拉,找到Volume free space 在Volume free space上方那一大串英文字母上右键然后Insert after,插入NVMeExpressDxE.ffs 另存为,然后刷写BIOS NVMeExpressDxE.ffs和UEFITool都可以谷歌找到qwq 不要相信H61用不了NVME这种说法= =,虽然H61是老了,在我家只有这个老年NAS还在用 末尾附上主板型号是凄惨红的C.H61HD V20

2019/8/18
articleCard.readMore

NOIP2018复赛前的随想

貌似初赛过了的样子…… 有毒 全年的Flag:初赛不过穿女装 然后就没过 今年的Flag:初赛过了穿女装 然后就过了 ??? 算了。。今年再立一个Flag 要是NOIP有1=就女装 算下来也至少三个月没写过代码了吧…… GL HF

2018/10/25
articleCard.readMore

写在NOIP2018初赛前

啊。。。或许高三的生活就是这样,容不得你有半点情绪 强省弱市弱校 隔壁班物理竞赛的大佬们翻车了。。。全台州都没人进物理实验轮 该如何说呢 人生路长?遥远的彼方? 初中的时候看过一部动漫,叫做《境界的彼方》 “没有未来的未来不是我想要的未来”,嘛,虽然此未来非彼未来,但是这也是挺应景的啊 竞技游戏,菜是原罪 这句话正确的不能再正确了不是吗? 我到底算是正式打过OI吗?

2018/9/25
articleCard.readMore

TzhsOJ P1253 仙人掌

由题意可知,一定存在一条连接i与i+1的边,因为只存在一个简单环,所以除了i到i+1的边之外,只能有一条边覆盖i到i+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 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int n,m,tot,cur; struct node { int x,y; }e[200003]; bool cmp(const node&s1,const node&s2) { return s1.y<s2.y; } int main() { scanf("%d%d",&n,&m); int t=0; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); if(x>y) swap(x,y); if(x+1!=y) { e[++t].x=x; e[t].y=y; } } sort(e+1,e+t+1,cmp); for(int i=1;i<=t;i++) if(e[i].x>=cur) { cur=e[i].y; tot++; } printf("%d\n",tot+n-1); return 0; }

2018/7/15
articleCard.readMore

Codeforces Round #497 (Div. 2)

A Romaji 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 #include<iostream> using namespace std; string str; bool check(char c) { if(c=='a' || c=='o' || c=='u' || c=='i' || c=='e') return true; else return false; } int main() { cin>>str; for(int i=0;i<str.size();i++) { if(str[i]=='n') continue; else if(check(str[i])) continue; else if(!check(str[i+1])) { cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; return 0; } B Turn the Rectangles 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 #include<iostream> #include<algorithm> using namespace std; struct node { int x,y; }a[100003]; int n; int main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y; int h=max(a[1].x,a[1].y); for(int i=1;i<n;i++) { if(h>=a[i+1].x && h>=a[i+1].y) { h=max(a[i+1].x,a[i+1].y); continue; } else if(h>=a[i+1].x) { h=a[i+1].x; continue; } else if(h>=a[i+1].y) { h=a[i+1].y; continue; } else { cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; return 0; } C Reorder the Array 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 #include<iostream> #include<algorithm> using namespace std; int n,ans,tmp; int a[100003]; bool cmp(int a,int b) { return a>b; } int main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); for(int i=0;i<=n;i++) { if(a[i]==a[i+1]) tmp++; else { ans=max(ans,tmp); tmp=1; } } cout<<n-ans<<endl; return 0; }

2018/7/14
articleCard.readMore

OI中常用的代码规范

本文介绍本人在 OI 中常用的代码规范 概览 所有的 #include 指令必须放置于整个程序开头 在.cpp文件中使用 using namespace std; main 函数应该放置于整个程序末尾 不应该使用 int 代替 bool 表示逻辑值 预编译指令 #include 中,C 标准库头文件必须使用 c 前缀,而不是 .h 后缀 #include 中,C 标准库头文件应该放置于 C++ 标准库头文件前,其它头文件(如果有)应放置于最后 所有的预编译指令(包括 #ifdef 等)不能缩进 缩进 对于每个代码块,使用 4 空格或等长的Tab转空格(可以尝试Code::Blocks的默认自动缩进) 花括号 花括号必须遵循以下两种写法之一,前一种被称为「花括号不换行」,后一种被称为「花括号换行」 必须有且仅有一个空格 必须与上一级代码块的缩进相同 必须与上一级代码块的缩进相同 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 //不换行写法(邪教!) if (condition) { something; } else { something; } //换行写法(正义!) if (condition) { something; } else { somethng; } 行 除 for 中的三个语句外,每行不能有超过一个语句如果需要一行内求值多个表达式,可以但减少使用等效的逗号表达式替代 多个意义独立的代码块之间应该用空行隔开 右花括号前不应该有多余的空行 不应该有两个连续的空行 非空行尾不应该有多余的空格 所有的 #include 指令之后必须有一个空行 如果有 using namespace std;,则必须紧跟在 #include 后的空行后,之后必须一个空行 函数、成员函数、结构体、全局变量块之间必须用空行隔开 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<cstdio> #include<iostream> const int MAXN=100; const int MAXM=200; int n,m,a[MAXN+1]; double p,q,x,y; int main() { p=1,q=2; return 0; } 函数 main 函数的返回值类型必须是 int,不可以省略 return 0; 空函数体可以使用 {} 传参时,应该根据实际需要使用「引用」、「const 引用」和「值传递」 变量 在不影响代码可读性的前提下减少变量 局部变量必须在用时定义,变量名不应该与上一个块中的变量重名,可以与全局变量重名 只在一个函数内使用到的需要全局空间(如大数组)或生命周期的变量,必须定义为 static 的局部变量 空格 在不影响代码可读性的前提下减少空格 || 或 &&之类多条件并列的运算符左右必须要空格 = + - . -> ::之类两边不加空格 语句末尾打死不加空格(除非写Markdown) 1 2 3 4 5 6 7 8 9 10 11 if(条件1 && 条件2) { f[i][j]=f[f[i][j-1]][j-1]; } struct Edge { int x; Edge():x(0){} } 指针与引用 在描述类型名时,指针符号 * 和引用符号 & 与左侧的类型名之间必须有一个空格,与右侧的其它关键字之间不能有空格,如 char *const 或 int *& 在定义变量、函数返回值、参数时,指针符号 * 和引用符号 & 与左侧的类型名之间必须有一个空格,与右侧的变量、函数、参数名之间不能有空格 命名 所有结构体、函数、变量、参数名必须使用驼峰命名法,其中结构体名首字母必须大写,其它首字母必须小写 为方便,命名中的单词可以使用缩写,函数、变量、参数名可以用一个小写字母代替全局数组可以命名为一个大写字母 1 2 3 4 5 6 7 8 9 10 11 12 13 14 int aVarWithVeryLongName; struct Node { int dep,s; } struct SegT { SegT *lc,*rc; } bool getAns(std::vector<std::string> &res); 模板来自menci的博客

2018/7/14
articleCard.readMore

用OneDriver来备份HEXO的源文件

话说之前一直再用GitHub在同步我的HEXO原本的文件,但是最近我的各种机器都出现了莫名其妙的问题,于是就开始尝试了一下MS的服务,包括现在在用的OneDriver,5GB的空间用来同步HEXO的源文件相当充足了,并且最重要的是,这玩意在不挂VPN的环境下和GitHub的速度不是一个数量级的啊。

2018/1/20
articleCard.readMore

你好啊,WindowsServer

自从我的Windows各种崩溃之后 坑爹的安装过程 当我装这系统时,各种提示我无法打开install.wim文件 桌面化 好吧,这才是重点。 首先推荐一篇知乎专栏 <a class="link" href="https://zhuanlan.zhihu.com/p/23302415" target="_blank" rel="noopener" >知乎专栏 我基本是按照这里桌面化Windows Server的 关于A卡驱动 说不能装A卡驱动的都是假的,假的假的是假的 运行AMD驱动安装程序,然后会解压安装文件 然后在硬件管理器里面手动安装即可

2017/10/1
articleCard.readMore

Hello World

趁着清明长假,把blog发布到了Github上 之前在沙雕OpenShift上VPS太麻烦,不如上静态页面。 至于Hello World,这不是国际惯例吗。

2015/4/3
articleCard.readMore

关于本站

记录摸鱼的日常流水帐 如果博客里的东西帮到您了,那真是太好了 关于我 什么都写一点工程师, 简历可以在 LinkedIn 上找到 星际2国服宗师(但是国服没了) 战网ID:Spaceless#5104 | NS好友ID:SW-0298-7511-7319 | Steam好友ID:138379332 头像是<a class="link" href="https://zh.moegirl.org.cn/%e8%af%ba%e8%89%be%e5%b0%94%28%e5%a4%a9%e4%bd%93%e7%9a%84%e7%a7%a9%e5%ba%8f%29" target="_blank" rel="noopener" >诺艾尔(天体的秩序) 不是<a class="link" href="https://zh.moegirl.org.cn/%e7%8f%82%e6%9c%b5%e8%8e%89" target="_blank" rel="noopener" >珂朵莉 Codeforces <a class="link" href="https://codeforces.com/profile/ReiAC" target="_blank" rel="noopener" > Platform Tools Languages 版权说明 除非注明,本博客所有文章皆为原创。 除非另有声明,本博客之原创文章采用 <a class="link" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="noopener" >CC BY-NC-SA 4.0 进行许可。 转载请同时需要注明原文链接和作者名字。 本博客运行于 <a class="link" href="https://azure.microsoft.com/en-us/services/app-service/static/" target="_blank" rel="noopener" >Azure Static Web Apps 与 <a class="link" href="https://pages.cloudflare.com/" target="_blank" rel="noopener" >CloudFlare Pages ,源代码位于 <a class="link" href="https://github.com/ACRei/blog" target="_blank" rel="noopener" >Github 仓库 投喂 这是一个Vultr的AFF链接如果您要买VPS的话也许可以点一下 <a class="link" href="https://www.vultr.com/?ref=9464460-8H" target="_blank" rel="noopener" >https://www.vultr.com/?ref=9464460-8H

2001/1/1
articleCard.readMore

亲友

2001/1/1
articleCard.readMore

搜索

2001/1/1
articleCard.readMore