当前位置:网站首页>[Luogu p3295] mengmengda (parallel search) (double)
[Luogu p3295] mengmengda (parallel search) (double)
2022-07-05 23:49:00 【SSL_ TJH】
adorable
Topic link :luogu P3295
The main idea of the topic
Give you a big number , Then there are some restrictions if we treat this number as a string , Several pairs of substrings with the same length are the same .
Then ask how many numbers you have meet the conditions .
Ideas
It can be found that it has nothing to do with numbers , The only thing is that the first one cannot be 0 0 0.
Then you will find that both positions are the same number , Then you consider how many numbers are irrelevant , If it is n u m num num, The answer is 9 ∗ 1 0 n u m − 1 9*10^{num-1} 9∗10num−1.
Then violence merges one by one n 2 n^2 n2 Of , But the inquiry is just n n n, Let's consider whether we can neutralize .
First consider how to turn the operation into log n \log n logn, It's not difficult to think that it can be disassembled into log n \log n logn Intervals , You can multiply it or put it on the line segment tree .
But because you have to correspond one by one , You don't look very good on the tree .
Then we consider using the method of multiplication , Then look at the inquiry .
We find that we get and search the set inside the doubled block , Each point of it can be disassembled and multiplied by two , But it can't be connected with all the points in the search set .
I found it redundant , Let's think about efficiency , Observing you and looking up sets are actually connected in the form of trees , We can connect with our father directly .
( Take apart the two sides and connect the two sides separately )
Then you can .
Code
#include<cstdio>
#define ll long long
#define mo 1000000007
using namespace std;
const int N = 1e5 + 100;
int n, m, fa[21][N];
ll ksm(ll x, ll y) {
ll re = 1; while (y) {
if (y & 1) re = re * x % mo; x = x * x % mo; y >>= 1;} return re;
}
int find(int now) {
return fa[(now - 1) / n][now - (now - 1) / n * n] == now ? now : fa[(now - 1) / n][now - (now - 1) / n * n] = find(fa[(now - 1) / n][now - (now - 1) / n * n]);}
void merge(int x, int y) {
int X = find(x), Y = find(y); if (X != Y) fa[(X - 1) / n][X - (X - 1) / n * n] = Y;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i <= 20; i++) for (int j = 1; j + (1 << i) - 1 <= n; j++)
fa[i][j] = i * n + j;
for (int i = 1; i <= m; i++) {
int l1, r1, l2, r2; scanf("%d %d %d %d", &l1, &r1, &l2, &r2);
for (int j = 20; j >= 0; j--)
if (l1 + (1 << j) - 1 <= r1) {
merge(j * n + l1, j * n + l2);
l1 = l1 + (1 << j); l2 = l2 + (1 << j);
}
}
for (int i = 20; i > 0; i--)
for (int j = 1; j + (1 << i) - 1 <= n; j++) {
if (fa[i][j] != i * n + j) {
int fi = (fa[i][j] - 1) / n, fj = fa[i][j] - fi * n;
merge((i - 1) * n + j, (fi - 1) * n + fj);
merge((i - 1) * n + j + (1 << (i - 1)), (fi - 1) * n + fj + (1 << (fi - 1)));
}
}
int num = 0;
for (int i = 1; i <= n; i++) {
if (fa[0][i] == i) num++;
}
printf("%lld", 9ll * ksm(10, num - 1) % mo);
return 0;
}
边栏推荐
- Spire. PDF for NET 8.7.2
- Scala concurrent programming (II) akka
- 【LeetCode】5. Valid Palindrome·有效回文
- 【LeetCode】5. Valid palindrome
- VBA fast switching sheet
- Spire.PDF for NET 8.7.2
- How to rotate the synchronized / refreshed icon (EL icon refresh)
- 4点告诉你实时聊天与聊天机器人组合的优势
- Online yaml to CSV tool
- Dynamic planning: robbing families and houses
猜你喜欢
The use of El cascader and the solution of error reporting
CIS基准测试工具kube-bench使用
Fiddler Everywhere 3.2.1 Crack
用列表初始化你的vector&&initializer_list简介
Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
Spreadjs 15.1 CN and spreadjs 15.1 en
698. Divided into k equal subsets ●●
Neural structured learning - Part 2: training with natural graphs
《牛客刷verilog》Part III Verilog企业真题
Online yaml to CSV tool
随机推荐
What is a humble but profitable sideline?
Rethinking about MySQL query optimization
15 MySQL-存储过程与函数
Laser slam learning record
PV静态创建和动态创建
Do you regret becoming a programmer?
带外和带内的区别
Latex multiple linebreaks
转:未来,这样的组织才能扛住风险
Biased sample variance, unbiased sample variance
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
yate. conf
How to rotate the synchronized / refreshed icon (EL icon refresh)
How to enable relationship view in phpMyAdmin - how to enable relationship view in phpMyAdmin
C# Linq Demo
14 MySQL view
Opencvsharp (C openCV) shape detection and recognition (with source code)
如何让同步/刷新的图标(el-icon-refresh)旋转起来
Neural structured learning - Part 2: training with natural graphs
Xinyuan & Lichuang EDA training camp - brushless motor drive