当前位置: 首页 > news >正文

2024.7.8

2024.7.8 【追逐影子的人,自己就是影子 —— 荷马】

Monday 六月初三


讲的根本听不懂好吧!

目前只写了三道题(但是黑色

确实是没见过这么抽象的数据结构

Gregor and the Two Painters
Number of Components
Equal LCM Subsets

这个lcm确实让我印象深刻,

第一次把一个数学+数据结构写成这样

//2024.7.8
//by wite_ice
//Equal LCM Subsets
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
typedef pair<int, int> p;
typedef __int128 ll;int T, n, m;
int c[2], sz[2];
ll a[2][N], d[2][N];inline ll read(){ll ans = 0;char ch = getchar();while (ch < '0' || ch > '9')ch = getchar();while (ch >= '0' && ch <= '9'){ans = ans * 10 + (ch ^ 48);ch = getchar();}return ans;
}void write(ll n){if (n >= 10) write(n / 10);putchar(n % 10 + '0');}struct tree{ll s[N * 4], sum;void build(int x, int l, int r, ll a[]) {if(l == r) {s[x] = sum / __gcd(sum, a[l]);return ;}int mid = (l + r) >> 1;build(x << 1, l, mid, a);build(x << 1 | 1, mid + 1, r, a);s[x] = __gcd(s[x << 1], s[x << 1 | 1]);}void change(int x, int l, int r, int p) {if(l == r) {s[x] = 0;return ;}int mid = (l + r) >> 1;if(p <= mid) change(x << 1, l, mid, p);else change(x << 1 | 1, mid + 1, r, p);s[x] = __gcd(s[x << 1], s[x << 1 | 1]);}ll work() {return s[1];}
}t[2][N];int main() {cin >> T;while(T--) {cin >> n >> m;for(int i = 1; i <= n; ++i)a[0][i] = read(), d[0][i] = 0;for(int i = 1; i <= m; ++i)a[1][i] = read(), d[1][i] = 0;c[0] = c[1] = 0, sz[0] = n, sz[1] = m;queue <p> q;for(int k = 0; k <= 1; ++k) for(int i = 1; i <= sz[k]; ++i) {t[k][i].sum = a[k][i], t[k][i].build(1, 1, sz[k ^ 1], a[k ^ 1]);if(t[k][i].work() > 1) q.push({k, i}), d[k][i] = 1, ++c[k];}while(q.size()) {p x = q.front(); q.pop();int f = (x.first) ^ 1;for(int i = 1; i <= sz[f]; ++i) {if(!d[f][i]) {t[f][i].change(1, 1, sz[f ^ 1], x.second);if(t[f][i].work() > 1) q.push({f, i}), d[f][i] = 1, ++c[f];}}}if(c[0] == sz[0] || c[1] == sz[1]) cout << "NO" << endl;else {cout << "YES" << endl << sz[0] - c[0] << ' ' << sz[1] - c[1] << endl;for(int i = 1; i <= n; ++i) if(!d[0][i]) write(a[0][i]), putchar(' ');cout << endl;for(int i = 1; i <= m; ++i)if(!d[1][i]) write(a[1][i]), putchar(' ');cout << endl;}}
}

不过对线段树的理解加深了不少,理解了很多之前未曾设想的用法

理解了一些方法,比如钦定某个点为代表元,之后向四周遍历

或者使用类似染色的思想,简化问题

http://www.lryc.cn/news/395274.html

相关文章:

  • Spring 外部jar包Bean自动装配
  • 2通道音频ADC解码芯片ES7243L、ES7243E、ES7243,用于低成本实现模拟麦克风转换为IIS数字话筒
  • uniapp跨域问题解决
  • [C++][ProtoBuf][Proto3语法][一]详细讲解
  • 千古雄文《渔樵问对》原文、译文、解析
  • uniapp 开发备忘录-防坑指南
  • Simple_ReAct_Agent
  • window wsl安装ubuntu
  • postmessage()在同一域名下,传递消息给另一个页面
  • 初始redis:在Ubuntu上安装redis
  • 生物素结合金纳米粒子(Bt@Au-NPs ) biotin-conjugated Au-NPs
  • LeetCode热题100刷题9:25. K 个一组翻转链表、101. 对称二叉树、543. 二叉树的直径、102. 二叉树的层序遍历
  • PyJWT,一个基于JSON的轻量级安全通信方式的python库
  • Golang | Leetcode Golang题解之第223题矩形面积
  • 新手怎么使用GitLab?
  • 表情包原理
  • 技术难点思考SpringBoot如何集成Jmeter开发
  • 如何快速使用C语言操作sqlite3
  • 网络模型介绍
  • Codeforces Round #956 (Div. 2) and ByteRace 2024
  • 域名、网页、HTTP概述
  • Redisson分布式锁、可重入锁
  • 适合宠物饮水机的光电传感器有哪些
  • 『Python学习笔记』Python运行设置PYTHONPATH环境变量!
  • 2024年06月CCF-GESP编程能力等级认证Python编程三级真题解析
  • 代码随想录算法训练营:20/60
  • Apache Seata应用侧启动过程剖析——RM TM如何与TC建立连接
  • Origin 的使用
  • MySQL相关知识点
  • 第4章 Vite模块化与插件系统(二)