加载中...

数组找符合要求的n元对

abc265 Dhttps://atcoder.jp/contests/abc265/tasks/abc265_d

找到符合条件的 x y z w 使得 前缀和s
sy-1-sx-1=p
sz-1-sy-1=q
sr-1-sz-1=r

#include<bits/stdc++.h>
using namespace std;
typedef __float128 f128;
typedef __int128 i128;
typedef long long LL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
const int N=2e5+10;
LL s[N];

int main()
{

    int n;
    LL P,Q,R;
    cin>>n>>P>>Q>>R;

    set<LL>op;
    op.insert(0); //把s0插入

    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        s[i]=s[i-1]+x;
        op.insert(s[i]);
    }

    //枚举x
    for(int i=1;i<=n;i++){
        if(op.find(s[i-1]+P)!=op.end()&&op.find(s[i-1]+P+Q)!=op.end()&&op.find(s[i-1]+P+Q+R)!=op.end()){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");

    return 0;
}
posted @ 2022-08-22 14:07  liang302  阅读(16)  评论(0编辑  收藏  举报