当前位置:网站首页>[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;
}
边栏推荐
- 用列表初始化你的vector&&initializer_list简介
- Spreadjs 15.1 CN and spreadjs 15.1 en
- rsync远程同步
- 保研笔记四 软件工程与计算卷二(8-12章)
- Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
- Rasa 3. X learning series -rasa x Community Edition (Free Edition) changes
- Use CAS instead of synchronized
- Make a short video clip number of we media film and television. Where can I download the material?
- Rsync remote synchronization
- How to get all the values stored in localstorage
猜你喜欢
同事悄悄告诉我,飞书通知还能这样玩
[classical control theory] summary of automatic control experiment
GFS distributed file system
成为程序员的你,后悔了吗?
用列錶初始化你的vector&&initializer_list簡介
Senparc.Weixin.Sample.MP源码剖析
98. Verify the binary search tree ●●
Neural structured learning - Part 3: training with synthesized graphs
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
GFS分布式文件系统
随机推荐
C# 反射与Type
698. 划分为k个相等的子集 ●●
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
Make a short video clip number of we media film and television. Where can I download the material?
Qcombox (rewrite) + qcompleter (auto completion, auto loading the drop-down options of qcombox, setting the background color)
Difference between out of band and in band
开源crm客户关系统管理系统源码,免费分享
用列表初始化你的vector&&initializer_list简介
带外和带内的区别
C reflection and type
2022.6.20-6.26 AI industry weekly (issue 103): new little life
2022.6.20-6.26 AI行业周刊(第103期):新的小生命
Rsync remote synchronization
Laser slam learning record
Fiddler Everywhere 3.2.1 Crack
15 MySQL-存储过程与函数
Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
XML配置文件(DTD详细讲解)
Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration