2020江西省赛 E.Color Sequence(异或前缀和)

 利用异或前缀和,如果两个前缀的异或值相同,那么中间这一段连续的序列就满足条件,用map记录一下前缀和出现的次数,具体计数方法见代码。

颜色只有20中,一个int型就可以记录所有状态。

#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <queue>
#include <vector>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
#define lson(x) node << 1, start, mid
#define rson(x) node << 1 | 1, mid + 1, end

using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const int maxm = 1e4 + 10;
const LL mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int a[maxn], sum[maxn];
int n;
map<int, int> mp;
int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        sum[i] = sum[i - 1] ^ (1 << a[i]);
    }
    mp[0] = 1;
    LL ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = ans + 1LL * mp[sum[i]];
        ++mp[sum[i]];
    }
    cout << ans;
    return 0;
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
`sltest.testsequence.addStepBefore` 函数的用法如下: ```matlab sltest.testsequence.addStepBefore(blockPath, newStep, stepPath) ``` 其中,`blockPath` 是要添加测试步骤的 Simulink 模块路径,`newStep` 是要添加的测试步骤,`stepPath` 是要添加新步骤的位置。这个函数将在 `stepPath` 指定的位置之前添加新步骤。 例如,我们可以使用以下代码在 Simulink Test Sequence 中添加一个测试步骤: ```matlab % 打开 Simulink Test Sequence testSeq = sltest.testmanager.getTestSuites('Test Sequence'); open(testSeq); % 获取 Test Sequence 中的第一个测试用例 testCase = getTestCases(testSeq); testCase = testCase{1}; % 获取测试用例中的第一个测试序列 testSeqObj = getTestSequences(testCase); testSeqObj = testSeqObj{1}; % 获取测试序列中第一个测试步骤的路径 stepPath = getTestSteps(testSeqObj); stepPath = stepPath{1}; % 在第一个测试步骤之前添加一个新的测试步骤 newStep = sltest.testsequence.TestStep('Description', '测试步骤描述'); blockPath = '模块名称/子系统名称'; sltest.testsequence.addStepBefore(blockPath, newStep, stepPath); ``` 在这个例子中,我们首先打开 Simulink Test Sequence,并获取第一个测试用例和第一个测试序列。然后,我们获取第一个测试步骤的路径,并使用 `sltest.testsequence.TestStep` 创建一个新的测试步骤。最后,我们使用 `sltest.testsequence.addStepBefore` 将新步骤添加到第一个测试步骤之前。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值