玄学报错求助
查看原帖
玄学报错求助
398310
hundunqidian楼主2023/6/8 12:11

样例能过,但提交爆零

下载样例1测试后,对比输出文件与标准输出显示“找不到差异”

另:使用out()快速输出后,反而出现了4个点TLE

???

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
inline ll rd(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch-48),ch=getchar();
    return x*f;
}
inline void out(ll x){
	if(x>9) out(x/10);
	putchar(x%10+'0');
	return ;
}
int const X=6e4+100;
char ch;
ll n,m,a[X],cnt[(1<<26)+10],res,sq,pre[X],ans[X];
struct node{
	ll l,r,id;
};
node q[X];
bool cmp(node a,node b){
	if(a.l/sq==b.l/sq) return a.r<b.r;
	return a.l/sq<b.l/sq;
}
void add(ll x){
	res+=cnt[x];
	cnt[x]++;
	for(ll i=0;i<26;i++){
		res+=cnt[x^(1<<i)];
	}
	return ;
}
void del(ll x){
	cnt[x]--;
	res-=cnt[x];
	for(ll i=0;i<26;i++){
		res-=cnt[x^(1<<i)];
	}
	return ;
}
int main(){
	//freopen("0.txt","w",stdout);
	n=rd(); m=rd(); 
	sq=pow(n,0.666);
	for(ll i=1;i<=n;i++){
		ch=getchar();
		a[i]=1<<(ch-'a');
		pre[i]=pre[i-1]^a[i];
	}
	ll L=1,R=0;
	for(ll i=1;i<=m;i++){
		q[i].l=rd();  q[i].r=rd();
		q[i].l--; 
		q[i].id=i;
	}
	sort(q+1,q+1+m,cmp);
	for(ll i=1;i<=m;i++){
		while(L>q[i].l) add(pre[--L]);
		while(L<q[i].l) del(pre[L++]);
		while(R<q[i].r) add(pre[++R]);
		while(R>q[i].r) del(pre[R--]);
		ans[q[i].id]=res;
	}
	for(ll i=1;i<=m;i++){
		printf("%lld\n",ans[i]);
		//out(ans[i]); putchar('\n');
	}
	return 0;
} 

感谢.JPG

2023/6/8 12:11
加载中...