样例过了,20分,大样例调不出来,所以来求助
#include<bits/stdc++.h>
using namespace std;
int n,m;
inline int read(){ //快读
register char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
register int ans = 0;
while(ch >= '0' && ch <= '9'){
ans = (ans << 3) + (ans << 1) + (ch ^ 48);
ch = getchar();
}
return ans;
}
int s;
int cnt[200010];
struct pp
{
int l,r,id;
} ask[200010];
#define blo(i) (i-1)/s+1
int ans[200010];
unsigned short int p[(1<<26)+10];
int xo[200010];
int now=0;
void add(int x)
{
now+=p[xo[x]];
p[xo[x]]++;
for(int i=0;i<26;i++) now+=p[xo[x]^(1<<i)];
}
void del(int x)
{
//cerr<<x<<endl;
p[xo[x]]--;
now-=p[xo[x]];
for(int i=0;i<26;i++) now-=p[xo[x]^(1<<i)];
}
bool cmp(pp m,pp n)
{
if(blo(m.l)!=blo(n.l)) return blo(m.l)<blo(n.l);
return m.r<n.r;
}
void solve()
{
//do something
n=read();m=read();
s=3*sqrt(n);
char t[200010];
scanf("%s",t+1);
//for(int i=1;i<=n;i++) rd(a[i]);
//assert(0);
//cerr<<"qwq"<<endl;
//cout<<t+1<<endl;
for(int i=1;i<=n;i++) xo[i]=xo[i-1]^(1<<(t[i]-'a'));//cout<<xo[i]<<endl;//cout<<xo[i]<<endl;
//cerr<<"qwq"<<endl;
for(int i=1;i<=m;i++) ask[i].l=read(),ask[i].r=read(),ask[i].id=i;
//cerr<<"qaq"<<endl;
sort(ask+1,ask+m+1,cmp);
int l=1,r=0;
//assert(0);
cerr<<"qaq"<<endl;
for(int i=1;i<=m;i++)
{
//cout<<l<<" "<<r<<endl;
//cerr<<"qwq"<<endl;
ask[i].l--;
while(l<ask[i].l) del(l++);
//cerr<<"?????"<<endl;
while(r>ask[i].r) del(r--);
while(l>ask[i].l) add(--l);
while(r<ask[i].r) add(++r);
ans[ask[i].id]=now;
//cout<<"?????";
}
for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
}
signed main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve();
}
// POWERED BY WITHERS
// THINK ONCE, CODE TWICE
/*things to check
1. int overflow or long long memory need
2. recursion/array/binary search/dp/loop bounds
3. precision
4. special cases(n=1,bounds)
5. delete debug statements
6. initialize(especially multi-tests)
7. = or == , n or m ,++ or -- , i or j , > or >= , < or <= , - or =
8. keep it simple and stupid
9. do not delete, use // instead
10. operator priority
11. is there anything extra to output?
12. if you don't know where the bug is , try to clear some parts of the code
and check each part seperately.
13. ...
*/
/* something to think about
1. greedy? dp? searching? dp with matrix/ segment tree? binary search?
2. If contains "not", why not 正难则反 or few affect?
*/