签到题 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的更多相关文章

  1. 牛客网暑期ACM多校训练营 第九场

    HPrefix Sum study from : https://blog.csdn.net/mitsuha_/article/details/81774727 k较小.分离x和k. 另外的可能:求a ...

  2. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  3. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  4. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  5. 牛客网 暑期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 ,问你 ...

  6. 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)

    牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...

  7. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  8. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

  9. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  10. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

随机推荐

  1. swagger.yaml转换为swagger.json文件

    方法一 swagger-editor页面 官方的 swagger-editor Live Demo (在线直接使用,就是访问的有点慢)或者将swagger-editor Download 下载到本地然 ...

  2. CF930E Coins Exhibition

    题意:平面上一共有k个硬币(k<=1e9),给你n个区间这些区间中至少有一个硬币反面朝上,m个区间中至少有一个硬币正面朝上.问有多少种硬币放置方案?n,m<=100005. 标程: #in ...

  3. Nlog 日志框架简单教程

    安装 Nuget获取 配置寻找 会自动寻找在应用程序目录下的NLog.config(大小写敏感) 如何配置config <?xml version="1.0" encodin ...

  4. input、textarea等输入框输入中文时,拼音在输入框内会触发input事件的问题

    监听文本输入框的input事件,在拼写汉字(输入法)但汉字并未实际填充到文本框中(选词)时会触发input事件,如图: 但是在很多情况下,只需要输入到输入框的中文字符. 解决办法: 通过查阅资料得知在 ...

  5. Kunbernetes从私有仓库nexus拉取镜像

    1.docker登陆认证 [root@master ~]# vim /etc/docker/daemon.json { "insecure-registries": [" ...

  6. 洛谷 P2114 [NOI2014]起床困难综合症

    题目描述 21世纪,许多人得了一种奇怪的病:起床困难综合症,其临床表现为:起床难,起床后精神不佳.作为一名青春阳光好少年,atm一直坚持与起床困难综合症作斗争.通过研究相关文献,他找到了该病的发病原因 ...

  7. tomcat下文件路径

    第一种:复制要访问的文件a.txt至tomcat安装路径下的webapps/ROOT文件夹下: 访问路径为:localhost:8080/a.txt 或者在webapps文件夹下新建一个文件夹(tes ...

  8. linux大神

    http://blog.csdn.net/skykingf/article/category/780616

  9. HTML <body>的常用属性

    bgColor : 网页背景色  如 <body bgColor="red"> Background : 网页背景图片的地址 如 <body background ...

  10. Tomcat点击项目名称,加载一个action请求

    <meta http-equiv="refresh" content="0;url=index.action">