为什么RE了?求助!!!
查看原帖
为什么RE了?求助!!!
349147
凌曦月楼主2020/12/25 21:12
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=5e4+5;
int n,m,a[maxn];
int pos[maxn],cnt[maxn];
struct node{ int l,r,biao; }q[maxn];
int ans,ans1[maxn],ans2[maxn];

void read(int &x) {
	int f=1; x=0; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0' && ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x*=f;
}

bool cmp(const node &a,const node &b) { return pos[a.l]<pos[b.l] || (pos[a.l]==pos[b.l] && (pos[a.l] & 1?a.r<b.r:a.r>b.r)); }

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }

void add(int x) {
	ans+=cnt[x];
	++cnt[x];
}

void del(int x) {
	--cnt[x];
	ans-=cnt[x];
}

signed main() {
	read(n),read(m);
	for(int i=1;i<=n;i++) {
		read(a[i]);
		pos[i]=(i-1)/sqrt(n)+1;
	}
	for(int i=1;i<=m;i++) {
		read(q[i].l),read(q[i].r);
		q[i].biao=i;
	}
	
	sort(q+1,q+m+1,cmp);
	
	int ql=1,qr=1;
	cnt[a[1]]=1;ans=0;
	for(int i=1;i<=m;i++) {
		while(ql<q[i].l) del(a[ql++]);
		while(qr>q[i].r) del(a[qr--]);
		while(ql>q[i].l) add(a[--ql]);
		while(qr<q[i].r) add(a[++qr]);
		int t1=ans,t2=(q[i].r-q[i].l+1)*(q[i].r-q[i].l)/2,g=gcd(t1,t2);
        ans1[q[i].biao]=t1/g,ans2[q[i].biao]=t2/g;
	}
	
	for(int i=1;i<=m;i++) printf("%lld/%lld\n",ans1[i],ans2[i]);
	return 0;
}

只有最后一个点对了,嘤嘤嘤...

2020/12/25 21:12
加载中...