当前位置:网站首页>[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;
}
边栏推荐
- 【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
- Rsync remote synchronization
- Golang code checking tool
- What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
- 做自媒体影视短视频剪辑号,在哪儿下载素材?
- PADS ROUTER 使用技巧小记
- 20220703 周赛:知道秘密的人数-动规(题解)
- 哪些偏门项目可以做到?自媒体做到月赚一万以上很难吗?
- Tips for using pads router
- 零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
猜你喜欢

动态规划 之 打家劫舍

TVS管 与 稳压二极管参数对比

Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration

Attacking technology Er - Automation

《牛客刷verilog》Part III Verilog企业真题

保研笔记二 软件工程与计算卷二(13-16章)

总结了 800多个 Kubectl 别名,再也不怕记不住命令了!

4点告诉你实时聊天与聊天机器人组合的优势

保研笔记四 软件工程与计算卷二(8-12章)

el-cascader的使用以及报错解决
随机推荐
成为程序员的你,后悔了吗?
Brushless drive design -- on MOS drive circuit
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
[day39 literature extensive reading] a Bayesian perspective on magnetic estimation
Go language introduction detailed tutorial (I): go language in the era
Use CAS instead of synchronized
How to get all the values stored in localstorage
Redis high availability - master-slave replication, sentinel mode, cluster
Opencvsharp (C openCV) shape detection and recognition (with source code)
Why use weak pointers for delegation- Why use weak pointer for delegation?
98. 验证二叉搜索树 ●●
idea 连接mysql ,直接贴配置文件的url 比较方便
4 points tell you the advantages of the combination of real-time chat and chat robots
Tips for using pads router
2022.6.20-6.26 AI industry weekly (issue 103): new little life
C reflection and type
20.移植Freetype字体库
开源crm客户关系统管理系统源码,免费分享
Bao Yan notebook IV software engineering and calculation volume II (Chapter 8-12)
如何让同步/刷新的图标(el-icon-refresh)旋转起来