1 条题解

  • 1
    @ 2025-12-11 20:54:45

    前缀和+二分

    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    const int N=2e5+10;
    int x[N],p[N];
    signed main()
    {
    	ios::sync_with_stdio(0);
    	cin.tie(0);cout.tie(0);
    	int n;cin>>n;
    	for(int i=1;i<=n;i++)cin>>x[i];
    	for(int i=1;i<=n;i++)cin>>p[i],p[i]+=p[i-1];
    	int q;cin>>q;
    	while(q--)
    	{
    		int l,r;cin>>l>>r;
    		int a=lower_bound(x+1,x+n+1,l)-x;
    		int b=upper_bound(x+1,x+n+1,r)-x-1;
    		if(b<a)cout<<0;
    		else cout<<p[b]-p[a-1];
    		cout<<'\n';
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    7953
    时间
    2000ms
    内存
    1024MiB
    难度
    7
    标签
    递交数
    19
    已通过
    9
    上传者