Table of Contents

ExplanationSolution

Explanation

The problem involves counting the occurrences of specific pairs of characters (ligatures) in a given text corpus based on multiple sets of suggested ligatures. The primary challenge is efficiently handling large input sizes and ensuring that the counting process respects the rule that ligatures can't overlap.

Solution

This solution to the problem uses SIMD (Single Instruction, Multiple Data) parallelism to efficiently count the occurrences of suggested ligatures within a large corpus:

Overview

  1. Preprocessing the Corpus:
    • The corpus is preprocessed to identify all pairs of consecutive characters, which are stored in a pairs vector.
  2. Setting Up Bitmasks:
    • A bitmask array active is set up where each bit represents whether a specific ligature is part of a query.

The bitmask for each query is configured such that each suggested ligature toggles a specific bit.

Time Complexity: O(Q(N+K))\mathcal{O}(Q(N+K))

C++

#pragma GCC target("avx2")
#include <immintrin.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!