牛客网暑期ACM多校训练营(第一场)菜鸟补题QAQ
签到题 J Different Integers(树状数组)
题目大意:给一个长为n的数组,每一个询问给两个数字i, j ,询问1~i, j~n这两个区间中有多少不同的数字,真的像是莫队裸题,但是两个区间是分隔的,所以可以考虑将数组延长一倍,即num[i] = num[i+n],这样就可以变成一段区间中查询了,不过这样会T.....参考了题解的做法还是比较好用的,写法非常巧妙。记录数字i第一次和最后一次出现的位置分别为first[i], last[i],按每个询问的rhs从小到大排序后,遍历num数组。遍历序号为i,每次遍历处理询问和维护一个树状数组,①只有当某个询问的 rhs == i 时处理该询问②维护树状数组,首先我们可以想到假如某个数x,当last[x] == i 时,下个遍历时下个询问的rhs必然会大于这个last[x](因为是从1~n遍历),所以当这次遍历过后,剩下的询问rhs全部大于last[x],所有右边区间rhs~n已经没有x了,这个时候只要看前面lhs是不是小于first[x]就知道这个数在不在询问区间了,这个时候就可以维护一个前缀和,sum[i]表示表示有多少个数的first值是在1~i内的。
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a,LL b) { return a>b?a:b; }
inline LL LMin(LL a,LL b) { return a>b?b:a; }
inline int Max(int a,int b) { return a>b?a:b; }
inline int Min(int a,int b) { return a>b?b:a; }
inline int gcd( int a, int b ) { return b==?a:gcd(b,a%b); }
inline int lcm( int a, int b ) { return a/gcd(a,b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e4+;
const int maxn = 1e5+; int n, q, tot;
int first[maxn], last[maxn];
int num[maxn], ans[maxn], _count[maxn]; struct node {
int lhs, rhs, id;
}p[maxn]; void add( int x, int d )
{
while ( x > )
{
_count[x] += d;
x -= lowbit(x);
}
} int sum(int x)
{
int s = ;
while ( x <= n )
{
s += _count[x];
x += lowbit(x);
}
return s;
} bool cmp(const node& a, const node &b)
{ return a.rhs < b.rhs; } void init()
{
tot = ;
memset(first, -, sizeof(first));
memset(last, -, sizeof(last));
memset(_count, , sizeof(_count)); for (int i = ; i <= n; i++)
{
scanf("%d", &num[i]);
if (first[num[i]] == -)
{ tot++; first[num[i]] = i;}
last[num[i]] = i;
} for (int i = ; i <= q; i++)
{
scanf("%d %d", &p[i].lhs, &p[i].rhs);
p[i].id = i;
}
sort(p+, p++q, cmp);
} int main()
{
while (~scanf("%d %d", &n, &q))
{
init(); for (int i = , k = ; i <= n; i++)
{ //如果有边界到达了某一点i,则可以开始处理左边界
while (k <= q && p[k].rhs == i)
{
ans[p[k].id] = tot - sum(p[k].lhs);
k++;
} if (last[num[i]] == i)
add(first[num[i]]-, );
} for ( int i = ; i <= q; i++ )
printf("%d\n", ans[i]);
} return ;
}
签到题? D Two Graphs
题目大意:给两个简单图G1(V, E1), G2(V,E2) ,问有多少个G2的子图与G1是同构的,想了好多骚操作,,结果hash去重就可以了
#include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a,LL b) { return a>b?a:b; }
inline LL LMin(LL a,LL b) { return a>b?b:a; }
inline int Max(int a,int b) { return a>b?a:b; }
inline int Min(int a,int b) { return a>b?b:a; }
inline int gcd( int a, int b ) { return b==?a:gcd(b,a%b); }
inline int lcm( int a, int b ) { return a/gcd(a,b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 1e4+;
const int maxn = 1e5+; struct edge2 {
int x, y;
}edge[];
int v, e1, e2;
int g1[][], g2[][], num[]; void init()
{
memset(g1, , sizeof(g1));
memset(g2, , sizeof(g2));
for ( int i = ; i <= v; i++ )
num[i] = i; int x, y;
for ( int i = ; i <= e1; i++ )
{ scanf("%d %d", &x, &y); g1[x][y] = ; g1[y][x] = ; }
for ( int i = ; i <= e2; i++ )
{
scanf("%d %d", &x, &y); g2[x][y] = ; g2[y][x] = ;
edge[i].x = x;
edge[i].y = y;
} } int main()
{
while (~scanf("%d %d %d", &v, &e1, &e2))
{
init(); set<long long> ss;
do {
int cnt = ;
long long has = ;
for (int i = ; i <= e2; i++)
{
if (g1[num[edge[i].x]][num[edge[i].y]])
{
has = has* + i;
has %= mod;
cnt++;
}
} if (cnt == e1)
ss.insert(has); }while(next_permutation(num+, num++v)); printf("%zd\n", ss.size());
} return ;
}
牛客网暑期ACM多校训练营(第一场)菜鸟补题QAQ的更多相关文章
- 牛客网暑期ACM多校训练营 第九场
HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...
- 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
- 牛客网暑期ACM多校训练营(第五场):F - take
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学
牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...
- 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)
牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
- 牛客网暑期ACM多校训练营(第七场)Bit Compression
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...
- 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)
链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...
- 牛客网暑期ACM多校训练营(第九场) A题 FWT
链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...
随机推荐
- BCZM : 1.6
https://blog.csdn.net/kabini/article/details/2311946 题目大意: 水房能容纳饮料的总量是V,有一批饮料,每种饮料单个容量都是2的方幂,每种饮料信息如 ...
- eclipse总结source folder和Deployment Assembly部署
在src下创建多级目录 然后右键build path-->use as source folder 就可以直接将多级普通文件夹转换成source folder build path下也可以直接n ...
- [转]Ubuntu安装rabbitMq
笔者ubuntu版本为Ubuntu 15.10,查看ubuntu当前版本命令:cat /etc/issue. 由于rabbitMq需要erlang语言的支持,在安装rabbitMq之前需要安装erla ...
- ios 中倒计时计算,时间戳为NaN
// 倒计时 daojishi(params) { let _this = this; let datetemp = this.servertimes; let lasttime = Date.par ...
- JQUERY 效果 遍历 事件
效果 隐藏与显示 hide() 和 show() 淡入淡出 fadeIn(speed,callback).fadeOut(speed,callback). fadeToggle() 方法可以在 f ...
- 登录操作(方法二:for与else搭配)
登录操作(方法二:for与else搭配) user_name="star"passwoed='123' count=0for i in range(3): u_username=i ...
- LUOGU P2860 [USACO06JAN]冗余路径Redundant Paths (双联通,缩点)
传送门 解题思路 刚开始是找的桥,后来发现这样不对,因为一条链就可以被卡.后来想到应该缩点后找到度数为1 的点然后两两配对. #include<iostream> #include< ...
- 尚学linux课程---6、linux命令介绍
尚学linux课程---6.linux命令介绍 一.总结 一句话总结: linux中命令的一般格式:命令关键字 选项 参数1 参数2 1.linux基本原则? 一切皆文件 配置文件保存为纯文本格式 2 ...
- PyCharm中批量查找及替换
选中需要操作的字符 Ctrl + R 替换 Ctrl + Shift + F 全局查找 Ctrl + Shift + R 全局替换 源自: PyCharm中批量查找及替换 - Ella_Wu - 博客 ...
- 06_mybatis关系映射
1.数据库表分析 表与表之间的业务关系: 在分析表与表之间的业务关系时需要建立 在某个业务意义基础上去分析; 先分析数据级别之间有关系的表之间的业务关系; usre和orders: use ...