Pluto_Rabbit's Blog

蒟蒻妹纸一枚,轻拍

【Training Contest】2016.04.22 HNOI2016 DAY2

Jacinth posted @ 2016年4月22日 22:58 in ZHOJ with tags Contest bzoj 2016 , 543 阅读

深切理解湖南人民的苦难

可是泥萌一个个都170什么意思啊QAQ

T1. 序列

Description
给定长度为n的序列:a1,a2,…,an,记为a[1:n]。类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,…,ar-1,ar。若1≤l≤s≤t≤r≤n,则称a[s:t]是a[l:r]的子序列。现在有q个询问,每个询问给定两个数l和r,1≤l≤r≤n,求a[l:r]的不同子序列的最小值之和。
例如,给定序列5,2,4,1,3,询问给定的两个数为1和3,那么a[1:3]有6个子序列a[1:1],a[2:2],a[3:3],a[1:2],a[2:3],a[1:3],这6个子序列的最小值之和为
Input 输入文件的第一行包含两个整数n和q,分别代表序列长度和询问数。接下来一行,包含n个整数,以空格隔开,第i个整数为ai,即序列第i个元素的值。接下来q行,每行包含两个整数l和r,代表一次询问。
Output
对于每次询问,输出一行,代表询问的答案。
Sample Input
5 5 
5 2 4 1 3 
1 5 
1 3 
2 4 
3 5 
2 5  
Sample Output
28 
17 
11 
11 
17 
Data Range 1 ≤N,Q ≤ 100000,|Ai| ≤ 10^9

传送门: http://www.lydsy.com/JudgeOnline/problem.php?id=4540

标算是莫队辣

为什么有这么多的分块题。。这次T3又是莫队QAQ。。

加上上次的T1。简直分块训练营(大雾)

湖南真是个神奇的地方

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x3f3f3f3f
#define NN 100010
#define LL long long
using namespace std;
struct Query
{
	int l,r,id;
}q[NN];
int st[NN],a[NN],l[NN],r[NN],f[NN][20],n,m,top=0,block,Log[NN];
LL ans[NN],now,ld[NN],rd[NN];
bool cmp1(Query xx,Query yy)
{
	if (xx.l/block==yy.l/block) return xx.r<yy.r;
	else return xx.l/block<yy.l/block;
}
int read()
{
	int xx; bool f=0; char CH;
	for (CH=getchar();CH<'0'||CH>'9';CH=getchar()) if (CH=='-') f=1;
	for (xx=0;CH>='0';CH=getchar()) xx=xx*10+CH-'0'; if (f) xx=-xx;
	return xx;
}
int Q(int x,int y)
{
	int tmpp=(int)log2(y-x+1);
	if (a[f[x][tmpp]]<a[f[y-(1<<tmpp)+1][tmpp]]) return f[x][tmpp];
	else return f[y-(1<<tmpp)+1][tmpp];
}
void L_(int x,int y,LL t)
{
	int tmp=Q(x,y);
	now+=t*a[tmp]*(y-tmp+1)+t*(rd[x]-rd[tmp]);
}
void R_(int x,int y,LL t)
{
	int tmp=Q(x,y);
	now+=t*a[tmp]*(tmp-x+1)+t*(ld[y]-ld[tmp]);
}
void pre()
{
	for (int i=1;i<=n;++i)
	{
		while (top && a[st[top]]>a[i]) r[st[top--]]=i;
		if (a[st[top]]==a[i]) l[i]=l[st[top]]; else l[i]=st[top];
		st[++top]=i;
	}
	while (top) r[st[top--]]=n+1;
	for (int i=1;i<=n;++i) ld[i]=ld[l[i]]+1ll*(i-l[i])*a[i];
	for (int i=n;i>=1;--i) rd[i]=rd[r[i]]+1ll*(r[i]-i)*a[i];
	for (int i=1;i<=n;++i) f[i][0]=i;
	for (int i=1;(1<<i)<=n;++i)
		for (int j=1;j<=n-(1<<i)+1;j++)
		{
			if (a[f[j][i-1]]<a[f[j+(1<<(i-1))][i-1]]) f[j][i]=f[j][i-1];
			else f[j][i]=f[j+(1<<(i-1))][i-1];
		}
}
int main()
{
	n=read(), m=read();
	block=(int)sqrt(n);
	for (int i=1;i<=n;++i) a[i]=read();
	pre();
	for (int i=1;i<=m;++i) q[i].l=read(), q[i].r=read(), q[i].id=i;
	sort(q+1,q+1+m,cmp1);
	int x=1,y=1;
	now=a[1];
	for (int i=1;i<=m;++i)
	{
		if (q[i].r>y) while (y!=q[i].r) y++, R_(x,y,1);
		if (q[i].l>x) while (x!=q[i].l) L_(x,y,-1), x++;
		if (q[i].l<x) while (x!=q[i].l) x--, L_(x,y,1);
		if (q[i].r<y) while (y!=q[i].r) R_(x,y,-1), y--;
		ans[q[i].id]=now;
	}
	for (int i=1;i<=m;++i) printf("%lld\n",ans[i]);
	return 0;
}

T2. 矿区

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4541

彩蛋:输出k个“1 1”就可以10分走人咯

T3. 大数

Description 小 B 有一个很大的数 S,长度达到了 N 位;这个数可以看成是一个串,它可能有前导 0,例如00009312345。小B还有一个素数P。现在,小 B 提出了 M 个询问,每个询问求 S 的一个子串中有多少子串是 P 的倍数(0 也是P 的倍数)。例如 S为0077时,其子串 007有6个子串:0,0,7,00,07,007;显然0077的子串007有6个子串都是素数7的倍数。
Input 第一行一个整数:P。第二行一个串:S。第三行一个整数:M。接下来M行,每行两个整数 fr,to,表示对S 的子串S[fr…to]的一次询问。注意:S的最左端的数字的位置序号为 1;例如S为213567,则S[1]为 2,S[1…3]为 213。N,M<=100000,P为素数
Output 输出M行,每行一个整数,第 i行是第 i个询问的答案。
Sample Input
11 
121121 
1 6 
1 5 
1 4 
Sample Output
5
3
2
Hint 第一个询问问的是整个串,满足条件的子串分别有:121121,2112,11,121,121。
Data Range
对于 30%的数据,N,M<=1000;
对于 60%的数据,N<=10000,M<=1000;
对于 100%的数据,N,M<=100000,P 为素数。

传送门: http://www.lydsy.com/JudgeOnline/problem.php?id=4542

你觉得我考试的时候还真的有时间写么

好吧QAQ(现在年轻人一言不合就写暴力

暴力30分的挣扎

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
char s[1010];
LL mod;
int m,ans,l,r;
LL xx;
int main()
{
	scanf("%lld%s%d",&mod,s,&m);
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",&l,&r); l--,r--;
		ans=0;
		for (int j=l;j<=r;++j)
		{
			xx=0ll;
			for (int k=j;k<=r;++k)
			{
				xx=xx*10ll%mod+s[k]-'0';
				if (xx%mod==0) ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

 

标算是Scarlet大爷的

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rpt(i,l,r) for(int i=l;i<=r;i++)
#define rpd(i,r,l) for(int i=r;i>=l;i--)
#define N 100005
long long P;
char s[N];
int n,m,d,nl,nr;
int dv[N];
long long temp;
long long a[N],dict[N];
int b[N],c[N];
struct query{
    int l,r,x;
}q[N];
inline bool cmp(query a,query b){
    return dv[a.l]==dv[b.l]?a.r<b.r:dv[a.l]<dv[b.l];
}
long long ans_,ans[N];
int main(){
    std::cin>>P;
    scanf("%s",s+1);
    n=strlen(s+1);
       
    if(P==2||P==5){
        rpt(i,1,n) if((s[i]-'0')%P==0) a[i]=i,b[i]=1;
        a[0]=0;rpt(i,1,n) a[i]+=a[i-1];
        b[0]=0;rpt(i,1,n) b[i]+=b[i-1];
        scanf("%d",&m);
        while(m--){
            scanf("%d%d",&nl,&nr);
            printf("%lld\n",a[nr]-a[nl-1]-1LL*(b[nr]-b[nl-1])*(nl-1));
        }
    }
    else{
           
    a[n+1]=0;temp=1;
    rpd(i,n,1) a[i]=((s[i]-'0')*temp+a[i+1])%P,(temp*=10)%=P;
    n++;rpt(i,1,n) dict[i]=a[i];
    std::sort(dict+1,dict+n+1);
    rpt(i,1,n) b[i]=std::lower_bound(dict+1,dict+n+1,a[i])-dict;
       
    scanf("%d",&m);
    rpt(i,1,m) scanf("%d%d",&q[i].l,&q[i].r),q[i].r++,q[i].x=i;
    d=int(sqrt(n));rpt(i,1,n) dv[i]=i/d;
    std::sort(q+1,q+m+1,cmp);
       
    memset(c,0,sizeof(c));
    nl=1;nr=0;ans_=0;
    rpt(i,1,m){
        if(nr<q[i].r){
            rpt(j,nr+1,q[i].r) ans_+=c[b[j]]++;
            nr=q[i].r;
        }
        if(nl>q[i].l){
            rpd(j,nl-1,q[i].l) ans_+=c[b[j]]++;
            nl=q[i].l;
        }
        if(nr>q[i].r){
            rpt(j,q[i].r+1,nr) ans_-=--c[b[j]];
            nr=q[i].r;
        }
        if(nl<q[i].l){
            rpd(j,q[i].l-1,nl) ans_-=--c[b[j]];
            nl=q[i].l;
        }
        ans[q[i].x]=ans_;
    }
    rpt(i,1,m) printf("%lld\n",ans[i]);
       
    }
}
Avatar_small
10thmodelquestionpa 说:
2023年7月07日 00:09

Initiative of professional writers who have come together for dedicated news coverage of latest happenings around the country (India). Our team comprises of professional writers & citizen journalists with diverse 10thmodelquestionpaper.in range of interest in Journalism who are passionate about publishing the Education Updates with transparency in general public interest is a initiative of professional writers who have come together for dedicated news coverage of latest happenings around the country.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter