fgfdsgfads

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long ll;
const int Mod = 836131;
const int N = 1e6 + 3;
int T_T, n, a, K, temp, Case;
ll sum[N];
bool flag;

struct Hash_Type {
    int top, info[Mod], nxt[N];
    ll num[N];
    inline void Init() {
        memset(info, 0, sizeof(info));
        top = 0;
    }
    inline void Insert(const ll &y) {
        int x = y % Mod;
        if (x < 0) x += Mod;
        for (int k = info[x]; k; k = nxt[k])
            if (num[k] == y) return ;
        nxt[++top] = info[x];
        info[x] = top;
        num[top] = y;
        return ;
    }
    inline bool Query(const ll &y) {
        int x = y % Mod;
        if (x < 0) x += Mod;
        for (int k = info[x]; k; k = nxt[k])
            if (num[k] == y)
                return true;
        return false;
    }
} cnt;

char ch;
inline int read() {
    int res = 0, sgn = 0;
    while (ch = getchar(), ch < ‘0‘ || ch > ‘9‘) if (ch == ‘-‘) sgn = 1;
    res = ch - 48;
    while (ch = getchar(), ch >= ‘0‘ && ch <= ‘9‘) res = res * 10 + ch - 48;
    return sgn ? -res : res;
}

int main() {
    freopen ("a.txt" , "r" , stdin) ;
    T_T = read();
    for (Case = 1; Case <= T_T; ++Case) {
        n = read(); K = read();
        flag = false;
        cnt.Init();
        for (int i = 1; i <= n; ++i) {
            temp = read();
            if (i & 1) sum[i] = sum[i - 1] + temp;
            else     sum[i] = sum[i - 1] - temp;
            if (temp == K) flag = true;
        }
        if (!flag) {
            for (int i = n; i >= 1; --i) {
                if (i & 1) {
                    ll cur = K + sum[i - 1];
                    if (cnt.Query(cur)) {
                        flag = true;
                        break;
                    }
                }
                else {
                    ll cur = -K + sum[i - 1];
                    if (cnt.Query(cur)) {
                        flag = true;
                        break;
                    }
                }
                cnt.Insert(sum[i]);
            }
        }
        if (flag) printf("Case #%d: Yes.\n", Case);
        else printf("Case #%d: No.\n", Case);
    }
    return 0;
}
时间: 2024-10-13 03:57:50

fgfdsgfads的相关文章