正文
增加 9 行删除 9 行
41 行未改动42434445464748495051525354555657585960616263646541 行未改动ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>n>>m>>q;for(int i=1;i<=n;i++) cin>>a[i].p>>a[i].t,a[i].id=i;for(int i=1;i<=n;i++) pre2[i]+=pre2[i-1]+a[i].p; // 求前半部分sort(a+1,a+1+n,cmp); // 排序for(int i=1;i<=n;i++){if(a[i-1].t!=a[i].t) pre1[i]=a[i].p;else pre1[i]=pre1[i-1]+a[i].p; // 分段 维护段内的前缀和t[i]=a[i].t; // 方便使用二分函数id[i]=a[i].id;}while(q--){cin>>x>>l>>r;ll ans=pre2[r]-pre2[l-1]; // 答案前半部分ll L=lower_bound(t+1,t+1+n,x)-t,R=upper_bound(t+1,t+1+n,x)-t; // 二分出 x 的区间ll LL=lower_bound(id+L,id+R,l)-id,RR=upper_bound(id+L,id+R,r)-id-1; // 在 x 的区间中二分出满足 l \leq id_i \leq r 的区间if(t[LL]==t[LL-1]) ans-=(pre1[RR]-pre1[LL-1])/2; // 左端点不在序列的开头if(LL<=RR&&t[LL]!=t[LL-1]) ans-=(pre1[RR])/2; // 左端点在序列的开头cout<<ans<<'\n';}return 0;}```41 行未改动42434445464748495051525354555657585960616263646541 行未改动ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);cin>>n>>m>>q;for(int i=1;i<=n;i++) cin>>a[i].p>>a[i].t,a[i].id=i;for(int i=1;i<=n;i++) pre2[i]+=pre2[i-1]+a[i].p; // 求前半部分sort(a+1,a+1+n,cmp); // 排序for(int i=1;i<=n;i++){if(a[i-1].t!=a[i].t) pre1[i]=a[i].p;else pre1[i]=pre1[i-1]+a[i].p; // 分段 维护段内的前缀和t[i]=a[i].t; // 方便使用二分函数id[i]=a[i].id;}while(q--){cin>>x>>l>>r;ll ans=pre2[r]-pre2[l-1]; // 答案前半部分ll L=lower_bound(t+1,t+1+n,x)-t,R=upper_bound(t+1,t+1+n,x)-t; // 二分出 x 的区间ll LL=lower_bound(id+L,id+R,l)-id,RR=upper_bound(id+L,id+R,r)-id-1; // 在 x 的区间中二分出满足 l \leq id_i \leq r 的区间if(t[LL]==t[LL-1]) ans-=(pre1[RR]-pre1[LL-1])/2; // 左端点不在序列的开头if(LL<=RR&&t[LL]!=t[LL-1]) ans-=(pre1[RR])/2; // 左端点在序列的开头cout<<ans<<'\n';}return 0;}```